Skip to content

Commit 134826b

Browse files
Start sending ClientAuthError telemetry for microsoft auth (#278643)
To better bucketize MSAL broker errors.
1 parent 3dcee1b commit 134826b

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

extensions/microsoft-authentication/package-lock.json

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/microsoft-authentication/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@
141141
},
142142
"dependencies": {
143143
"@azure/ms-rest-azure-env": "^2.0.0",
144-
"@azure/msal-node": "^3.8.0",
145-
"@azure/msal-node-extensions": "^1.5.23",
144+
"@azure/msal-node": "^3.8.3",
145+
"@azure/msal-node-extensions": "^1.5.25",
146146
"@vscode/extension-telemetry": "^0.9.8",
147147
"keytar": "file:./packageMocks/keytar",
148148
"vscode-tas-client": "^0.1.84"

extensions/microsoft-authentication/src/common/telemetryReporter.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { AuthError } from '@azure/msal-node';
6+
import { AuthError, ClientAuthError } from '@azure/msal-node';
77
import TelemetryReporter, { TelemetryEventProperties } from '@vscode/extension-telemetry';
88
import { IExperimentationTelemetry } from 'vscode-tas-client';
99

@@ -108,6 +108,40 @@ export class MicrosoftAuthenticationTelemetryReporter implements IExperimentatio
108108
});
109109
}
110110

111+
sendTelemetryClientAuthErrorEvent(error: ClientAuthError): void {
112+
const errorCode = error.errorCode;
113+
const correlationId = error.correlationId;
114+
let brokerErrorCode: string | undefined;
115+
let brokerStatusCode: string | undefined;
116+
let brokerTag: string | undefined;
117+
118+
// Extract platform broker error information if available
119+
if (error.platformBrokerError) {
120+
brokerErrorCode = error.platformBrokerError.errorCode;
121+
brokerStatusCode = `${error.platformBrokerError.statusCode}`;
122+
brokerTag = error.platformBrokerError.tag;
123+
}
124+
125+
/* __GDPR__
126+
"msalClientAuthError" : {
127+
"owner": "TylerLeonhardt",
128+
"comment": "Used to determine how often users run into client auth errors during the login flow.",
129+
"errorCode": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The client auth error code." },
130+
"correlationId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The client auth error correlation id." },
131+
"brokerErrorCode": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The broker error code." },
132+
"brokerStatusCode": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The broker error status code." },
133+
"brokerTag": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The broker error tag." }
134+
}
135+
*/
136+
this._telemetryReporter.sendTelemetryErrorEvent('msalClientAuthError', {
137+
errorCode,
138+
correlationId,
139+
brokerErrorCode,
140+
brokerStatusCode,
141+
brokerTag
142+
});
143+
}
144+
111145
/**
112146
* Sends an event for an account type available at startup.
113147
* @param scopes The scopes for the session

extensions/microsoft-authentication/src/node/authProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ export class MsalAuthProvider implements AuthenticationProvider {
522522
} catch (e) {
523523
// If we can't get a token silently, the account is probably in a bad state so we should skip it
524524
// MSAL will log this already, so we don't need to log it again
525-
this._telemetryReporter.sendTelemetryErrorEvent(e);
525+
if (e instanceof ClientAuthError) {
526+
this._telemetryReporter.sendTelemetryClientAuthErrorEvent(e);
527+
} else {
528+
this._telemetryReporter.sendTelemetryErrorEvent(e);
529+
}
526530
this._logger.info(`[getAllSessionsForPca] [${scopeData.scopeStr}] [${account.username}] failed to acquire token silently, skipping account`, JSON.stringify(e));
527531
continue;
528532
}

0 commit comments

Comments
 (0)