@@ -3,85 +3,26 @@ import url = require('url');
3
3
import http = require( 'http' ) ;
4
4
import https = require( 'https' ) ;
5
5
6
- const instrumentationKey = 'e18a8793-c093-46f9-8c3b-433c9553eb7f' ;
7
- const preview = false ;
8
- const version = '3.5.0' ;
9
- const sdkVersion = 'replacetokens:1.0.0' ;
10
6
const application = 'replacetokens-task' ;
11
- const eventName = 'tokens.replaced' ;
12
- const telemetryUrl = 'https://westeurope-5.in.applicationinsights.azure.com/v2/track' ;
7
+ const version = '3.0.0' ;
8
+ const endpoint = 'https://insights-collector.eu01.nr-data.net/v1/accounts/4392697/events' ;
9
+ const key = 'eu01xxc28887c2d47d9719ed24a74df5FFFFNRAL' ;
13
10
const timeout = 3000 ;
14
11
15
- export default function trackEvent ( event : TelemetryEvent , proxyUrl ?: string ) : string {
12
+ export default function trackEvent ( event : TelemetryEvent , proxy ?: string ) : string | undefined {
16
13
try {
17
14
// create event payload
18
- let operationId : string = crypto . randomBytes ( 16 ) . toString ( 'hex' ) ;
19
- let body = {
20
- name : 'Microsoft.ApplicationInsights.Dev.' + instrumentationKey + '.Event' ,
21
- time : new Date ( ) . toISOString ( ) ,
22
- iKey : instrumentationKey ,
23
- tags : {
24
- 'ai.application.ver' : version ,
25
- 'ai.cloud.role' : event . serverType ,
26
- 'ai.internal.sdkVersion' : sdkVersion ,
27
- 'ai.operation.id' : operationId ,
28
- 'ai.operation.name' : application ,
29
- 'ai.operation.parentId' : '|' + operationId ,
30
- 'ai.user.accountId' : event . account ,
31
- 'ai.user.authUserId' : event . pipeline
32
- } ,
33
- data : {
34
- baseType : 'EventData' ,
35
- baseData : {
36
- ver : '2' ,
37
- name : eventName ,
38
- properties : {
39
- preview : preview ,
40
- pipelineType : event . pipelineType ,
41
- result : event . result ,
42
- tokenPrefix : event . tokenPrefix ,
43
- tokenSuffix : event . tokenSuffix ,
44
- pattern : event . pattern ,
45
- encoding : event . encoding ,
46
- keepToken : event . keepToken ,
47
- actionOnMissing : event . actionOnMissing ,
48
- writeBOM : event . writeBOM ,
49
- emptyValue : event . emptyValue ,
50
- escapeType : event . escapeType ,
51
- escapeChar : event . escapeChar ,
52
- charsToEscape : event . charsToEscape ,
53
- verbosity : event . verbosity ,
54
- variableFiles : event . variableFiles ,
55
- variableSeparator : event . variableSeparator ,
56
- rules : event . rules ,
57
- rulesWithInputWildcard : event . rulesWithInputWildcard ,
58
- rulesWithOutputPattern : event . rulesWithOutputPattern ,
59
- rulesWithNegativePattern : event . rulesWithNegativePattern ,
60
- duration : event . duration ,
61
- tokenReplaced : event . tokenReplaced ,
62
- tokenFound : event . tokenFound ,
63
- fileProcessed : event . fileProcessed ,
64
- useLegacyPattern : event . useLegacyPattern ,
65
- enableTransforms : event . enableTransforms ,
66
- transformPrefix : event . transformPrefix ,
67
- transformSuffix : event . transformSuffix ,
68
- transformPattern : event . transformPattern ,
69
- transformExecuted : event . transformExecuted ,
70
- defaultValue : event . defaultValue ,
71
- defaultValueReplaced : event . defaultValueReplaced ,
72
- actionOnNoFiles : event . actionOnNoFiles ,
73
- inlineVariables : event . inlineVariables ,
74
- enableRecursion : event . enableRecursion ,
75
- useLegacyEmptyFeature : event . useLegacyEmptyFeature ,
76
- useDefaultValue : event . useDefaultValue ,
77
- os : event . os
78
- }
79
- }
15
+ let body = [
16
+ {
17
+ ...event ,
18
+ eventType : 'TokensReplaced' ,
19
+ application : application ,
20
+ version : version
80
21
}
81
- } ;
22
+ ] ;
82
23
83
24
// send event
84
- let telemetryUrlParsed = url . parse ( telemetryUrl ) ;
25
+ let telemetryUrlParsed = url . parse ( endpoint ) ;
85
26
let options = {
86
27
method : 'POST' ,
87
28
host : telemetryUrlParsed . hostname ,
@@ -90,29 +31,30 @@ export default function trackEvent(event: TelemetryEvent, proxyUrl?: string): st
90
31
withCredentials : false ,
91
32
timeout : timeout ,
92
33
headers : < { [ key : string ] : string } > {
34
+ 'Api-Key' : key ,
93
35
'Content-Type' : 'application/json'
94
36
}
95
37
} ;
96
38
97
- proxyUrl = proxyUrl || process . env [ 'https_proxy' ] || undefined ;
98
- if ( proxyUrl ) {
99
- if ( proxyUrl . indexOf ( '//' ) === 0 ) proxyUrl = 'http:' + proxyUrl ;
39
+ proxy = proxy || process . env [ 'https_proxy' ] || undefined ;
40
+ if ( proxy ) {
41
+ if ( proxy . indexOf ( '//' ) === 0 ) proxy = 'http:' + proxy ;
100
42
101
- let proxyUrlParsed = url . parse ( proxyUrl ) ;
43
+ let proxyUrlParsed = url . parse ( proxy ) ;
102
44
if ( proxyUrlParsed . protocol === 'https:' ) {
103
- proxyUrl = undefined ;
45
+ proxy = undefined ;
104
46
} else {
105
47
options = {
106
48
...options ,
107
49
host : proxyUrlParsed . hostname ,
108
50
port : proxyUrlParsed . port || '80' ,
109
- path : telemetryUrl ,
51
+ path : endpoint ,
110
52
headers : { ...options . headers , Host : telemetryUrlParsed . hostname }
111
53
} ;
112
54
}
113
55
}
114
56
115
- let request = proxyUrl ? http . request ( options ) : https . request ( options ) ;
57
+ let request = proxy ? http . request ( options ) : https . request ( options ) ;
116
58
117
59
request . setTimeout ( timeout , ( ) => {
118
60
request . abort ( ) ;
@@ -122,20 +64,31 @@ export default function trackEvent(event: TelemetryEvent, proxyUrl?: string): st
122
64
request . write ( JSON . stringify ( body ) ) ;
123
65
request . end ( ) ;
124
66
125
- // return payload
126
- body . name = 'Microsoft.ApplicationInsights.Dev.*****.Event' ;
127
- body . iKey = '*****' ;
128
-
129
67
return JSON . stringify ( body ) ;
130
- } catch { }
68
+ } catch {
69
+ // silently continue
70
+ }
131
71
}
132
72
133
- export interface TelemetryEvent {
134
- account : string ;
135
- pipeline : string ;
136
- pipelineType : string ;
137
- serverType : string ;
73
+ export class TelemetryEvent {
74
+ private readonly account : string ;
75
+ private readonly pipeline : string ;
76
+
77
+ constructor ( account : string , pipeline : string ) {
78
+ this . account = crypto
79
+ . createHash ( 'sha256' )
80
+ . update ( account || '' )
81
+ . digest ( 'hex' ) ;
82
+ this . pipeline = crypto
83
+ . createHash ( 'sha256' )
84
+ . update ( pipeline || '' )
85
+ . digest ( 'hex' ) ;
86
+ }
87
+
88
+ host : string ;
89
+ os : string ;
138
90
result : string ;
91
+ duration : number ;
139
92
tokenPrefix : string ;
140
93
tokenSuffix : string ;
141
94
pattern : string ;
@@ -154,7 +107,6 @@ export interface TelemetryEvent {
154
107
rulesWithInputWildcard : number ;
155
108
rulesWithOutputPattern : number ;
156
109
rulesWithNegativePattern : number ;
157
- duration : number ;
158
110
tokenReplaced : number ;
159
111
tokenFound : number ;
160
112
fileProcessed : number ;
@@ -171,5 +123,4 @@ export interface TelemetryEvent {
171
123
enableRecursion : boolean ;
172
124
useLegacyEmptyFeature : boolean ;
173
125
useDefaultValue : boolean ;
174
- os : string ;
175
126
}
0 commit comments