@@ -8,7 +8,8 @@ import * as os from 'os';
8
8
import { Logger , ConfigAggregator , SfConfigProperties } from '@salesforce/core' ;
9
9
import { AsyncCreatable , env } from '@salesforce/kit' ;
10
10
11
- import axios from 'axios' ;
11
+ import got from 'got' ;
12
+ import { ProxyAgent } from 'proxy-agent' ;
12
13
import { AppInsights , Attributes , Properties , TelemetryOptions } from './appInsights' ;
13
14
import { TelemetryClient } from './exported' ;
14
15
@@ -82,32 +83,30 @@ export class TelemetryReporter extends AsyncCreatable<TelemetryOptions> {
82
83
const timeout = parseInt ( env . getString ( 'SFDX_TELEMETRY_TIMEOUT' , '1000' ) , 10 ) ;
83
84
this . logger . debug ( `Testing connection to ${ AppInsights . APP_INSIGHTS_SERVER } with timeout of ${ timeout } ms` ) ;
84
85
85
- // set up a CancelToken to handle connection timeouts because
86
- // the built in timeout functionality only handles response timeouts
87
- // see here: https://github.com/axios/axios/issues/647#issuecomment-322209906
88
- const cancelRequest = axios . CancelToken . source ( ) ;
89
- setTimeout ( ( ) => cancelRequest . cancel ( 'connection timeout' ) , timeout ) ;
90
-
91
- let canConnect : boolean ;
92
86
try {
93
- const options = {
94
- timeout,
95
- cancelToken : cancelRequest . token ,
96
- // We want any status less than 500 to be resolved (not rejected)
97
- validateStatus : ( status : number ) : boolean => status < 500 ,
98
- } ;
99
- await axios . get ( AppInsights . APP_INSIGHTS_SERVER , options ) ;
100
- canConnect = true ;
87
+ const resp = await got . get ( AppInsights . APP_INSIGHTS_SERVER , {
88
+ throwHttpErrors : false ,
89
+ agent : { https : new ProxyAgent ( ) } ,
90
+ retry : {
91
+ methods : [ 'GET' ] ,
92
+ errorCodes : [ 'ECONNRESET' , 'EADDRINUSE' , 'ECONNREFUSED' , 'EPIPE' ] ,
93
+ } ,
94
+ timeout : {
95
+ lookup : 100 ,
96
+ send : 10000 ,
97
+ response : 1000 ,
98
+ } ,
99
+ } ) ;
100
+ if ( resp . statusCode < 500 ) {
101
+ this . logger . debug ( `Successfully made a connection to ${ AppInsights . APP_INSIGHTS_SERVER } ` ) ;
102
+ return true ;
103
+ }
104
+ this . logger . error ( `${ AppInsights . APP_INSIGHTS_SERVER } responded with ${ resp . statusCode } ` ) ;
105
+ throw new Error ( resp . statusCode . toString ( ) ) ;
101
106
} catch ( err ) {
102
- canConnect = false ;
103
- }
104
-
105
- if ( canConnect ) {
106
- this . logger . debug ( `Successfully made a connection to ${ AppInsights . APP_INSIGHTS_SERVER } ` ) ;
107
- } else {
108
107
this . logger . warn ( `Connection to ${ AppInsights . APP_INSIGHTS_SERVER } timed out after ${ timeout } ms` ) ;
108
+ return false ;
109
109
}
110
- return canConnect ;
111
110
}
112
111
113
112
/**
0 commit comments