File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed
handwritten/nodejs-logging-winston Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 5050 "precompile" : " gts clean"
5151 },
5252 "dependencies" : {
53- "@google-cloud/logging" : " ^10.1.11 " ,
53+ "@google-cloud/logging" : " ^10.2.2 " ,
5454 "google-auth-library" : " ^8.0.2" ,
5555 "lodash.mapvalues" : " ^4.6.0" ,
5656 "winston-transport" : " ^4.3.0"
Original file line number Diff line number Diff line change @@ -89,6 +89,11 @@ export const LOGGING_SPAN_KEY = 'logging.googleapis.com/spanId';
8989 */
9090export const LOGGING_SAMPLED_KEY = 'logging.googleapis.com/trace_sampled' ;
9191
92+ /**
93+ * Default library version to be used if version retrieval fails
94+ */
95+ export const NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION = 'unknown' ;
96+
9297// The variable to hold cached library version
9398let libraryVersion : string ;
9499
@@ -352,11 +357,15 @@ export function getNodejsLibraryVersion() {
352357 if ( libraryVersion ) {
353358 return libraryVersion ;
354359 }
355- libraryVersion = require ( path . resolve (
356- __dirname ,
357- '../../' ,
358- 'package.json'
359- ) ) . version ;
360+ try {
361+ libraryVersion = require ( path . resolve (
362+ __dirname ,
363+ '../../' ,
364+ 'package.json'
365+ ) ) . version ;
366+ } catch ( err ) {
367+ libraryVersion = NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION ;
368+ }
360369 return libraryVersion ;
361370}
362371
Original file line number Diff line number Diff line change @@ -185,8 +185,8 @@ describe('LoggingWinston', function () {
185185 entry . data [ instrumentation . DIAGNOSTIC_INFO_KEY ] [
186186 instrumentation . INSTRUMENTATION_SOURCE_KEY
187187 ] ;
188- assert . equal ( info [ 0 ] . name , 'nodejs' ) ;
189- assert . equal ( info [ 1 ] . name , 'nodejs-winston ' ) ;
188+ assert . equal ( info [ 0 ] . name , 'nodejs-winston ' ) ;
189+ assert . equal ( info [ 1 ] . name , 'nodejs' ) ;
190190 } else {
191191 const data = entry . data as { message : string } ;
192192 assert . strictEqual ( data . message , ` ${ MESSAGE } ` ) ;
You can’t perform that action at this time.
0 commit comments