-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtelemetry.ts
More file actions
103 lines (97 loc) · 2.56 KB
/
telemetry.ts
File metadata and controls
103 lines (97 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Mode } from '@codeque/core'
import TelemetryReporter from '@vscode/extension-telemetry'
import { CaseType } from './types'
import { SearchFileType } from './StateManager'
const applicationInsightsInstrumentationKey =
'8f838c47-7173-4f6c-851a-b012d45d9ad8'
export const activateReporter = (): {
nativeReporter: TelemetryReporter | null
telemetryModule: TelemetryModule
} => {
if (process.env.NODE_ENV !== 'production') {
return {
nativeReporter: null,
telemetryModule: {
reportSearch: () => undefined,
reportSearchError: () => undefined,
},
}
}
const nativeReporter = new TelemetryReporter(
applicationInsightsInstrumentationKey,
)
return {
nativeReporter,
telemetryModule: telemetryModuleFactory(nativeReporter),
}
}
export type TelemetryModule = {
reportSearch: (data: {
mode: Mode
caseType: CaseType
fileType: SearchFileType
isWorkspace: 'true' | 'false'
queryLength: number
searchTime: number
resultsCount: number
errorsCount: number
searchedFilesCount: number
mainExt: string
}) => void
reportSearchError: (data: {
mode: Mode
caseType: CaseType
fileType: SearchFileType
isWorkspace: 'true' | 'false'
queryLength: number
searchTime: number
}) => void
}
export const telemetryModuleFactory = (
reporter: TelemetryReporter,
): TelemetryModule => {
return {
reportSearch: async (data) => {
try {
reporter.sendTelemetryEvent(
'vscode:search_results',
{
mode: data.mode,
caseType: data.caseType,
fileType: data.fileType,
isWorkspace: data.isWorkspace,
mainExt: data.mainExt,
},
{
queryLength: data.queryLength,
searchTime: data.searchTime,
resultsCount: data.resultsCount,
errorsCount: data.errorsCount,
searchedFilesCount: data.searchedFilesCount,
},
)
} catch (e) {
console.error('Send telemetry event error', e)
}
},
reportSearchError: (data) => {
try {
reporter.sendTelemetryErrorEvent(
'vscode:search_error',
{
mode: data.mode,
caseType: data.caseType,
fileType: data.fileType,
isWorkspace: data.isWorkspace,
},
{
queryLength: data.queryLength,
searchTime: data.searchTime,
},
)
} catch (e) {
console.error('Telemetry error event reporting error', e)
}
},
}
}