From 0f54c79d8ce87eb57fe6ce829d07eab009faaabf Mon Sep 17 00:00:00 2001 From: Ramin Tadayon Date: Thu, 15 Aug 2024 12:37:05 -0700 Subject: [PATCH] Adds tel events for errors with cloud integrations api calls --- src/constants.ts | 17 ++++++++++++++ .../authentication/cloudIntegrationService.ts | 23 +++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 6c6153aee9aad..494cda1780a44 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1280,6 +1280,23 @@ export type TelemetryEvents = { 'integration.connected.ids': string | undefined; }; + /** Sent when getting connected providers from the api fails*/ + 'cloudIntegrations/getConnections/failed': { + code: number | undefined; + }; + + /** Sent when getting a provider token from the api fails*/ + 'cloudIntegrations/getConnection/failed': { + code: number | undefined; + 'integration.id': string | undefined; + }; + + /** Sent when refreshing a provider token from the api fails*/ + 'cloudIntegrations/refreshConnection/failed': { + code: number | undefined; + 'integration.id': string | undefined; + }; + /** Sent when a cloud-based hosting provider is connected */ 'cloudIntegrations/hosting/connected': { 'hostingProvider.provider': IntegrationId; diff --git a/src/plus/integrations/authentication/cloudIntegrationService.ts b/src/plus/integrations/authentication/cloudIntegrationService.ts index 25a650c3b43ba..ab18d4bdf2765 100644 --- a/src/plus/integrations/authentication/cloudIntegrationService.ts +++ b/src/plus/integrations/authentication/cloudIntegrationService.ts @@ -19,8 +19,15 @@ export class CloudIntegrationService { ); if (!providersRsp.ok) { const error = (await providersRsp.json())?.error; + const errorMessage = + typeof error === 'string' ? error : (error?.message as string) ?? providersRsp.statusText; if (error != null) { - Logger.error(`Failed to get connected providers from cloud: ${error.message}`); + Logger.error(`Failed to get connected providers from cloud: ${errorMessage}`); + } + if (this.container.telemetry.enabled) { + this.container.telemetry.sendEvent('cloudIntegrations/getConnections/failed', { + code: providersRsp.status, + }); } return undefined; } @@ -54,8 +61,20 @@ export class CloudIntegrationService { ); if (!tokenRsp.ok) { const error = (await tokenRsp.json())?.error; + const errorMessage = typeof error === 'string' ? error : (error?.message as string) ?? tokenRsp.statusText; if (error != null) { - Logger.error(`Failed to ${refresh ? 'refresh' : 'get'} ${id} token from cloud: ${error.message}`); + Logger.error(`Failed to ${refresh ? 'refresh' : 'get'} ${id} token from cloud: ${errorMessage}`); + } + if (this.container.telemetry.enabled) { + this.container.telemetry.sendEvent( + refreshToken + ? 'cloudIntegrations/refreshConnection/failed' + : 'cloudIntegrations/getConnection/failed', + { + code: tokenRsp.status, + 'integration.id': id, + }, + ); } return undefined; }