@@ -62,6 +62,7 @@ import { getLogScope, setLogScopeExit } from '../../system/logger.scope';
6262import { flatten } from '../../system/object' ;
6363import { pauseOnCancelOrTimeout } from '../../system/promise' ;
6464import { pluralize } from '../../system/string' ;
65+ import { createDisposable } from '../../system/unifiedDisposable' ;
6566import { satisfies } from '../../system/version' ;
6667import { LoginUriPathPrefix } from './authenticationConnection' ;
6768import { authenticationProviderScopes } from './authenticationProvider' ;
@@ -871,9 +872,22 @@ export class SubscriptionService implements Disposable {
871872
872873 if ( ! ( await ensurePlusFeaturesEnabled ( ) ) ) return ;
873874
874- if ( this . container . telemetry . enabled ) {
875- this . container . telemetry . sendEvent ( 'subscription/action' , { action : 'upgrade' } , source ) ;
876- }
875+ let aborted = false ;
876+ using telemetry = this . container . telemetry . enabled
877+ ? createDisposable (
878+ ( ) => {
879+ this . container . telemetry . sendEvent (
880+ 'subscription/action' ,
881+ {
882+ action : 'upgrade' ,
883+ aborted : aborted ,
884+ } ,
885+ source ,
886+ ) ;
887+ } ,
888+ { once : true } ,
889+ )
890+ : undefined ;
877891
878892 if ( this . _subscription . account != null ) {
879893 // Do a pre-check-in to see if we've already upgraded to a paid plan.
@@ -910,27 +924,34 @@ export class SubscriptionService implements Disposable {
910924
911925 try {
912926 if ( hasAccount ) {
913- const token = await this . container . accountAuthentication . getExchangeToken (
914- SubscriptionUpdatedUriPathPrefix ,
915- ) ;
916- query . set ( 'token' , token ) ;
917- } else {
927+ try {
928+ const token = await this . container . accountAuthentication . getExchangeToken (
929+ SubscriptionUpdatedUriPathPrefix ,
930+ ) ;
931+ query . set ( 'token' , token ) ;
932+ } catch ( ex ) {
933+ Logger . error ( ex , scope ) ;
934+ }
935+ }
936+
937+ if ( ! query . has ( 'token' ) ) {
918938 const successUri = await env . asExternalUri (
919939 Uri . parse ( `${ env . uriScheme } ://${ this . container . context . extension . id } /${ LoginUriPathPrefix } ` ) ,
920940 ) ;
921941 query . set ( 'success_uri' , successUri . toString ( true ) ) ;
922942 }
923-
924- if ( ! ( await openUrl ( this . container . getGkDevUri ( 'purchase/checkout' , query . toString ( ) ) . toString ( true ) ) ) ) {
925- return ;
926- }
927943 } catch ( ex ) {
928944 Logger . error ( ex , scope ) ;
929- if ( ! ( await openUrl ( this . container . getGkDevUri ( 'purchase/checkout' , query . toString ( ) ) . toString ( true ) ) ) ) {
930- return ;
931- }
932945 }
933946
947+ aborted = ! ( await openUrl ( this . container . getGkDevUri ( 'purchase/checkout' , query . toString ( ) ) . toString ( true ) ) ) ;
948+
949+ if ( aborted ) {
950+ return ;
951+ }
952+
953+ telemetry ?. dispose ( ) ;
954+
934955 const completionPromises = [ new Promise < boolean > ( resolve => setTimeout ( ( ) => resolve ( false ) , 5 * 60 * 1000 ) ) ] ;
935956
936957 if ( hasAccount ) {
0 commit comments