diff --git a/extensions/microsoft-authentication/src/common/loggerOptions.ts b/extensions/microsoft-authentication/src/common/loggerOptions.ts index d572f655f92..af5c1644a27 100644 --- a/extensions/microsoft-authentication/src/common/loggerOptions.ts +++ b/extensions/microsoft-authentication/src/common/loggerOptions.ts @@ -5,11 +5,15 @@ import { LogLevel as MsalLogLevel } from '@azure/msal-node'; import { env, LogLevel, LogOutputChannel } from 'vscode'; +import { MicrosoftAuthenticationTelemetryReporter } from './telemetryReporter'; export class MsalLoggerOptions { piiLoggingEnabled = false; - constructor(private readonly _output: LogOutputChannel) { } + constructor( + private readonly _output: LogOutputChannel, + private readonly _telemtryReporter: MicrosoftAuthenticationTelemetryReporter + ) { } get logLevel(): MsalLogLevel { return this._toMsalLogLevel(env.logLevel); @@ -27,6 +31,7 @@ export class MsalLoggerOptions { switch (level) { case MsalLogLevel.Error: this._output.error(message); + this._telemtryReporter.sendTelemetryErrorEvent(message); return; case MsalLogLevel.Warning: this._output.warn(message); diff --git a/extensions/microsoft-authentication/src/node/authProvider.ts b/extensions/microsoft-authentication/src/node/authProvider.ts index cc422957ca9..5ce9acd3e6a 100644 --- a/extensions/microsoft-authentication/src/node/authProvider.ts +++ b/extensions/microsoft-authentication/src/node/authProvider.ts @@ -86,7 +86,7 @@ export class MsalAuthProvider implements AuthenticationProvider { uriHandler: UriEventHandler, env: Environment = Environment.AzureCloud ): Promise { - const publicClientManager = await CachedPublicClientApplicationManager.create(context.secrets, logger, env.name); + const publicClientManager = await CachedPublicClientApplicationManager.create(context.secrets, logger, telemetryReporter, env.name); context.subscriptions.push(publicClientManager); const authProvider = new MsalAuthProvider(context, telemetryReporter, logger, uriHandler, publicClientManager, env); await authProvider.initialize(); diff --git a/extensions/microsoft-authentication/src/node/cachedPublicClientApplication.ts b/extensions/microsoft-authentication/src/node/cachedPublicClientApplication.ts index f0f4eb7b9bc..c1b4fbac4c1 100644 --- a/extensions/microsoft-authentication/src/node/cachedPublicClientApplication.ts +++ b/extensions/microsoft-authentication/src/node/cachedPublicClientApplication.ts @@ -11,6 +11,7 @@ import { SecretStorageCachePlugin } from '../common/cachePlugin'; import { MsalLoggerOptions } from '../common/loggerOptions'; import { ICachedPublicClientApplication } from '../common/publicClientCache'; import { IAccountAccess } from '../common/accountAccess'; +import { MicrosoftAuthenticationTelemetryReporter } from '../common/telemetryReporter'; export class CachedPublicClientApplication implements ICachedPublicClientApplication { // Core properties @@ -44,8 +45,9 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica private readonly _secretStorage: SecretStorage, private readonly _accountAccess: IAccountAccess, private readonly _logger: LogOutputChannel, + telemetryReporter: MicrosoftAuthenticationTelemetryReporter ) { - const loggerOptions = new MsalLoggerOptions(_logger); + const loggerOptions = new MsalLoggerOptions(_logger, telemetryReporter); const nativeBrokerPlugin = new NativeBrokerPlugin(); this._isBrokerAvailable = nativeBrokerPlugin.isBrokerAvailable; this._pca = new PublicClientApplication({ @@ -75,9 +77,10 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica clientId: string, secretStorage: SecretStorage, accountAccess: IAccountAccess, - logger: LogOutputChannel + logger: LogOutputChannel, + telemetryReporter: MicrosoftAuthenticationTelemetryReporter ): Promise { - const app = new CachedPublicClientApplication(clientId, secretStorage, accountAccess, logger); + const app = new CachedPublicClientApplication(clientId, secretStorage, accountAccess, logger, telemetryReporter); await app.initialize(); return app; } diff --git a/extensions/microsoft-authentication/src/node/publicClientCache.ts b/extensions/microsoft-authentication/src/node/publicClientCache.ts index 16ccb80321f..777c3c5f272 100644 --- a/extensions/microsoft-authentication/src/node/publicClientCache.ts +++ b/extensions/microsoft-authentication/src/node/publicClientCache.ts @@ -8,6 +8,7 @@ import { SecretStorage, LogOutputChannel, Disposable, EventEmitter, Memento, Eve import { ICachedPublicClientApplication, ICachedPublicClientApplicationManager } from '../common/publicClientCache'; import { CachedPublicClientApplication } from './cachedPublicClientApplication'; import { IAccountAccess, ScopedAccountAccess } from '../common/accountAccess'; +import { MicrosoftAuthenticationTelemetryReporter } from '../common/telemetryReporter'; export interface IPublicClientApplicationInfo { clientId: string; @@ -29,6 +30,7 @@ export class CachedPublicClientApplicationManager implements ICachedPublicClient private readonly _accountAccess: IAccountAccess, private readonly _secretStorage: SecretStorage, private readonly _logger: LogOutputChannel, + private readonly _telemetryReporter: MicrosoftAuthenticationTelemetryReporter, disposables: Disposable[] ) { this._disposable = Disposable.from( @@ -41,13 +43,14 @@ export class CachedPublicClientApplicationManager implements ICachedPublicClient static async create( secretStorage: SecretStorage, logger: LogOutputChannel, + telemetryReporter: MicrosoftAuthenticationTelemetryReporter, cloudName: string ): Promise { const pcasSecretStorage = await PublicClientApplicationsSecretStorage.create(secretStorage, cloudName); // TODO: Remove the migrations in a version const migrations = await pcasSecretStorage.getOldValue(); const accountAccess = await ScopedAccountAccess.create(secretStorage, cloudName, logger, migrations); - const manager = new CachedPublicClientApplicationManager(pcasSecretStorage, accountAccess, secretStorage, logger, [pcasSecretStorage, accountAccess]); + const manager = new CachedPublicClientApplicationManager(pcasSecretStorage, accountAccess, secretStorage, logger, telemetryReporter, [pcasSecretStorage, accountAccess]); await manager.initialize(); return manager; } @@ -138,7 +141,7 @@ export class CachedPublicClientApplicationManager implements ICachedPublicClient } private async _doCreatePublicClientApplication(clientId: string): Promise { - const pca = await CachedPublicClientApplication.create(clientId, this._secretStorage, this._accountAccess, this._logger); + const pca = await CachedPublicClientApplication.create(clientId, this._secretStorage, this._accountAccess, this._logger, this._telemetryReporter); this._pcas.set(clientId, pca); const disposable = Disposable.from( pca,