@@ -90,9 +90,10 @@ export class TraceWriter extends common.Service {
9090
9191 if ( onUncaughtExceptionValues . indexOf ( config . onUncaughtException ) === - 1 ) {
9292 logger . error (
93- 'The value of onUncaughtException ' + config . onUncaughtException +
94- ' should be one of ' ,
95- onUncaughtExceptionValues ) ;
93+ `TraceWriter#constructor: The value of config.onUncaughtException [${
94+ config . onUncaughtException } ] should be one of [${
95+ onUncaughtExceptionValues . join ( ', ' ) } ].`,
96+ ) ;
9697 // TODO(kjin): Either log an error or throw one, but not both
9798 throw new Error ( 'Invalid value for onUncaughtException configuration.' ) ;
9899 }
@@ -123,9 +124,10 @@ export class TraceWriter extends common.Service {
123124 this . getProjectId ( ( err : Error | null , project ?: string ) => {
124125 if ( err ) {
125126 this . logger . error (
126- 'Unable to acquire the project number from metadata ' +
127- 'service. Please provide a valid project number as an env. ' +
128- 'variable, or through config.projectId passed to start(). ' + err ) ;
127+ 'TraceWriter#initialize: Unable to acquire the project number' ,
128+ 'automatically from the GCP metadata service. Please provide a' ,
129+ 'valid project ID as environmental variable GCLOUD_PROJECT, or as' ,
130+ `config.projectId passed to start. Original error: ${ err } ` ) ;
129131 cb ( err ) ;
130132 } else {
131133 this . config . projectId = project ;
@@ -182,7 +184,9 @@ export class TraceWriter extends common.Service {
182184 . catch ( ( err : AxiosError ) => {
183185 if ( err . code !== 'ENOTFOUND' ) {
184186 // We are running on GCP.
185- this . logger . warn ( 'Unable to retrieve GCE hostname.' , err ) ;
187+ this . logger . warn (
188+ 'TraceWriter#getHostname: Unable to retrieve GCE hostname' ,
189+ `from the GCP metadata service. Original error: ${ err } ` ) ;
186190 }
187191 cb ( os . hostname ( ) ) ;
188192 } ) ;
@@ -196,7 +200,9 @@ export class TraceWriter extends common.Service {
196200 . catch ( ( err : AxiosError ) => {
197201 if ( err . code !== 'ENOTFOUND' ) {
198202 // We are running on GCP.
199- this . logger . warn ( 'Unable to retrieve GCE instance id.' , err ) ;
203+ this . logger . warn (
204+ 'TraceWriter#getInstanceId: Unable to retrieve GCE instance ID' ,
205+ `from the GCP metadata service. Original error: ${ err } ` ) ;
200206 }
201207 cb ( ) ;
202208 } ) ;
@@ -256,18 +262,21 @@ export class TraceWriter extends common.Service {
256262 queueTrace ( trace : Trace ) {
257263 this . getProjectId ( ( err , projectId ?) => {
258264 if ( err || ! projectId ) {
259- this . logger . info ( 'No project number, dropping trace.' ) ;
265+ this . logger . info (
266+ 'TraceWriter#queueTrace: No project ID, dropping trace.' ) ;
260267 return ; // if we even reach this point, disabling traces is already
261268 // imminent.
262269 }
263270
264271 trace . projectId = projectId ;
265272 this . buffer . push ( JSON . stringify ( trace ) ) ;
266- this . logger . debug ( 'queued trace. new size:' , this . buffer . length ) ;
273+ this . logger . info (
274+ `TraceWriter#queueTrace: buffer.size = ${ this . buffer . length } ` ) ;
267275
268276 // Publish soon if the buffer is getting big
269277 if ( this . buffer . length >= this . config . bufferSize ) {
270- this . logger . info ( 'Flushing: trace buffer full' ) ;
278+ this . logger . info (
279+ 'TraceWriter#queueTrace: Trace buffer full, flushing.' ) ;
271280 setImmediate ( ( ) => this . flushBuffer ( ) ) ;
272281 }
273282 } ) ;
@@ -280,7 +289,7 @@ export class TraceWriter extends common.Service {
280289 * @private
281290 */
282291 scheduleFlush ( ) {
283- this . logger . info ( 'Flushing: performing periodic flush' ) ;
292+ this . logger . info ( 'TraceWriter#scheduleFlush: Performing periodic flush. ' ) ;
284293 this . flushBuffer ( ) ;
285294
286295 // Do it again after delay
@@ -308,7 +317,7 @@ export class TraceWriter extends common.Service {
308317 // Privatize and clear the buffer.
309318 const buffer = this . buffer ;
310319 this . buffer = [ ] ;
311- this . logger . debug ( 'Flushing traces' , buffer ) ;
320+ this . logger . debug ( 'TraceWriter#flushBufffer: Flushing traces' , buffer ) ;
312321 this . publish ( `{"traces":[${ buffer . join ( ) } ]}` ) ;
313322 }
314323
@@ -320,17 +329,16 @@ export class TraceWriter extends common.Service {
320329 publish ( json : string ) {
321330 const uri = `https://cloudtrace.googleapis.com/v1/projects/${
322331 this . config . projectId } /traces`;
323-
324332 const options = { method : 'PATCH' , uri, body : json , headers} ;
325- this . logger . debug ( 'TraceWriter: publishing to ' + uri ) ;
333+ this . logger . debug ( 'TraceWriter#publish: Publishing to ' + uri ) ;
326334 this . request ( options , ( err , body ?, response ?) => {
335+ const statusCode = ( response && response . statusCode ) || 'unknown' ;
327336 if ( err ) {
328- this . logger . error (
329- 'TraceWriter: error: ' ,
330- ( ( response && response . statusCode ) || '' ) + '\n' + err . stack ) ;
337+ this . logger . error ( `TraceWriter#publish: Received error status code ${
338+ statusCode } . Original error: ${ err } `) ;
331339 } else {
332340 this . logger . info (
333- ' TraceWriter: published. statusCode: ' + response . statusCode ) ;
341+ ` TraceWriter#publish: Published w/ status code: ${ statusCode } ` ) ;
334342 }
335343 } ) ;
336344 }
0 commit comments