Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/microsoft-authentication/src/common/telemetryReporter.ts
3320 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { AuthError } from '@azure/msal-node';
7
import TelemetryReporter, { TelemetryEventProperties } from '@vscode/extension-telemetry';
8
import { IExperimentationTelemetry } from 'vscode-tas-client';
9
10
export const enum MicrosoftAccountType {
11
AAD = 'aad',
12
MSA = 'msa',
13
Unknown = 'unknown'
14
}
15
16
export class MicrosoftAuthenticationTelemetryReporter implements IExperimentationTelemetry {
17
private sharedProperties: Record<string, string> = {};
18
protected _telemetryReporter: TelemetryReporter;
19
constructor(aiKey: string) {
20
this._telemetryReporter = new TelemetryReporter(aiKey);
21
}
22
23
get telemetryReporter(): TelemetryReporter {
24
return this._telemetryReporter;
25
}
26
27
setSharedProperty(name: string, value: string): void {
28
this.sharedProperties[name] = value;
29
}
30
31
postEvent(eventName: string, props: Map<string, string>): void {
32
const eventProperties: TelemetryEventProperties = { ...this.sharedProperties, ...Object.fromEntries(props) };
33
this._telemetryReporter.sendTelemetryEvent(
34
eventName,
35
eventProperties
36
);
37
}
38
39
sendActivatedWithMsalNoBrokerEvent(): void {
40
/* __GDPR__
41
"activatingMsalNoBroker" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often users use the msal-no-broker login flow. This only fires if the user explictly opts in to this." }
42
*/
43
this._telemetryReporter.sendTelemetryEvent('activatingmsalnobroker');
44
}
45
46
sendActivatedWithClassicImplementationEvent(reason: 'setting' | 'web'): void {
47
/* __GDPR__
48
"activatingClassic" : {
49
"owner": "TylerLeonhardt",
50
"comment": "Used to determine how often users use the classic login flow.",
51
"reason": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Why classic was used" }
52
}
53
*/
54
this._telemetryReporter.sendTelemetryEvent('activatingClassic', { reason });
55
}
56
57
sendLoginEvent(scopes: readonly string[]): void {
58
/* __GDPR__
59
"login" : {
60
"owner": "TylerLeonhardt",
61
"comment": "Used to determine the usage of the Microsoft Auth Provider.",
62
"scopes": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight", "comment": "Used to determine what scope combinations are being requested." }
63
}
64
*/
65
this._telemetryReporter.sendTelemetryEvent('login', {
66
// Get rid of guids from telemetry.
67
scopes: JSON.stringify(this._scrubGuids(scopes)),
68
});
69
}
70
sendLoginFailedEvent(): void {
71
/* __GDPR__
72
"loginFailed" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often users run into issues with the login flow." }
73
*/
74
this._telemetryReporter.sendTelemetryEvent('loginFailed');
75
}
76
sendLogoutEvent(): void {
77
/* __GDPR__
78
"logout" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often users log out." }
79
*/
80
this._telemetryReporter.sendTelemetryEvent('logout');
81
}
82
sendLogoutFailedEvent(): void {
83
/* __GDPR__
84
"logoutFailed" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often fail to log out." }
85
*/
86
this._telemetryReporter.sendTelemetryEvent('logoutFailed');
87
}
88
89
sendTelemetryErrorEvent(error: unknown): void {
90
let errorMessage: string | undefined;
91
let errorName: string | undefined;
92
let errorCode: string | undefined;
93
let errorCorrelationId: string | undefined;
94
if (typeof error === 'string') {
95
errorMessage = error;
96
} else {
97
const authError: AuthError = error as any;
98
// don't set error message or stack because it contains PII
99
errorCode = authError.errorCode;
100
errorCorrelationId = authError.correlationId;
101
errorName = authError.name;
102
}
103
104
/* __GDPR__
105
"msalError" : {
106
"owner": "TylerLeonhardt",
107
"comment": "Used to determine how often users run into issues with the login flow.",
108
"errorMessage": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The error message." },
109
"errorName": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The name of the error." },
110
"errorCode": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The error code." },
111
"errorCorrelationId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The error correlation id." }
112
}
113
*/
114
this._telemetryReporter.sendTelemetryErrorEvent('msalError', {
115
errorMessage,
116
errorName,
117
errorCode,
118
errorCorrelationId,
119
});
120
}
121
122
/**
123
* Sends an event for an account type available at startup.
124
* @param scopes The scopes for the session
125
* @param accountType The account type for the session
126
* @todo Remove the scopes since we really don't care about them.
127
*/
128
sendAccountEvent(scopes: string[], accountType: MicrosoftAccountType): void {
129
/* __GDPR__
130
"account" : {
131
"owner": "TylerLeonhardt",
132
"comment": "Used to determine the usage of the Microsoft Auth Provider.",
133
"scopes": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight", "comment": "Used to determine what scope combinations are being requested." },
134
"accountType": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight", "comment": "Used to determine what account types are being used." }
135
}
136
*/
137
this._telemetryReporter.sendTelemetryEvent('account', {
138
// Get rid of guids from telemetry.
139
scopes: JSON.stringify(this._scrubGuids(scopes)),
140
accountType
141
});
142
}
143
144
protected _scrubGuids(scopes: readonly string[]): string[] {
145
return scopes.map(s => s.replace(/[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/i, '{guid}'));
146
}
147
}
148
149
export class MicrosoftSovereignCloudAuthenticationTelemetryReporter extends MicrosoftAuthenticationTelemetryReporter {
150
override sendLoginEvent(scopes: string[]): void {
151
/* __GDPR__
152
"loginMicrosoftSovereignCloud" : {
153
"owner": "TylerLeonhardt",
154
"comment": "Used to determine the usage of the Microsoft Auth Provider.",
155
"scopes": { "classification": "PublicNonPersonalData", "purpose": "FeatureInsight", "comment": "Used to determine what scope combinations are being requested." }
156
}
157
*/
158
this._telemetryReporter.sendTelemetryEvent('loginMicrosoftSovereignCloud', {
159
// Get rid of guids from telemetry.
160
scopes: JSON.stringify(this._scrubGuids(scopes)),
161
});
162
}
163
override sendLoginFailedEvent(): void {
164
/* __GDPR__
165
"loginMicrosoftSovereignCloudFailed" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often users run into issues with the login flow." }
166
*/
167
this._telemetryReporter.sendTelemetryEvent('loginMicrosoftSovereignCloudFailed');
168
}
169
override sendLogoutEvent(): void {
170
/* __GDPR__
171
"logoutMicrosoftSovereignCloud" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often users log out." }
172
*/
173
this._telemetryReporter.sendTelemetryEvent('logoutMicrosoftSovereignCloud');
174
}
175
override sendLogoutFailedEvent(): void {
176
/* __GDPR__
177
"logoutMicrosoftSovereignCloudFailed" : { "owner": "TylerLeonhardt", "comment": "Used to determine how often fail to log out." }
178
*/
179
this._telemetryReporter.sendTelemetryEvent('logoutMicrosoftSovereignCloudFailed');
180
}
181
}
182
183