@@ -31,7 +31,6 @@ const OC_HEADER = {
3131
3232google . options ( { headers : OC_HEADER } ) ;
3333const monitoring = google . monitoring ( 'v3' ) ;
34- const GOOGLEAPIS_SCOPE = 'https://www.googleapis.com/auth/cloud-platform' ;
3534
3635/** Format and sends Stats to Stackdriver */
3736export class StackdriverStatsExporter implements StatsEventListener {
@@ -187,13 +186,21 @@ export class StackdriverStatsExporter implements StatsEventListener {
187186 } ;
188187
189188 return new Promise ( ( resolve , reject ) => {
190- monitoring . projects . metricDescriptors . create (
191- request , { headers : OC_HEADER , userAgentDirectives : [ OC_USER_AGENT ] } ,
192- ( err : Error | null ) => {
193- this . logger . debug ( 'sent metric descriptor' , request . resource ) ;
194- err ? reject ( err ) : resolve ( ) ;
195- } ) ;
196- } ) ;
189+ monitoring . projects . metricDescriptors . create (
190+ request ,
191+ { headers : OC_HEADER , userAgentDirectives : [ OC_USER_AGENT ] } ,
192+ ( err : Error | null ) => {
193+ this . logger . debug (
194+ 'sent metric descriptor' , request . resource ) ;
195+ err ? reject ( err ) : resolve ( ) ;
196+ } ) ;
197+ } )
198+ . catch ( ( err ) => {
199+ this . logger . error (
200+ `StackdriverStatsExporter: Failed to write data: ${
201+ err . message } `) ;
202+ this . stop ( ) ;
203+ } ) ;
197204 } ) ;
198205 }
199206
@@ -209,21 +216,10 @@ export class StackdriverStatsExporter implements StatsEventListener {
209216 * Gets the Google Application Credentials from the environment variables
210217 * and authenticates the client.
211218 */
212- private authorize ( ) : Promise < JWT > {
213- return auth . getApplicationDefault ( )
214- . then ( ( client ) => {
215- let authClient = client . credential as JWT ;
216- if ( authClient . createScopedRequired &&
217- authClient . createScopedRequired ( ) ) {
218- const scopes = [ GOOGLEAPIS_SCOPE ] ;
219- authClient = authClient . createScoped ( scopes ) ;
220- }
221- return authClient ;
222- } )
223- . catch ( ( err ) => {
224- err . message = `authorize error: ${ err . message } ` ;
225- throw ( err ) ;
226- } ) ;
219+ private async authorize ( ) : Promise < JWT > {
220+ const client = await auth . getClient (
221+ { scopes : [ 'https://www.googleapis.com/auth/cloud-platform' ] } ) ;
222+ return client as JWT ;
227223 }
228224
229225 // TODO(mayurkale): Deprecate onRegisterView and onRecord apis after
0 commit comments