diff --git a/package.json b/package.json index bc44b086..7458b112 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "precompile": "gts clean" }, "dependencies": { - "@google-cloud/logging": "^10.1.11", + "@google-cloud/logging": "^10.2.2", "google-auth-library": "^8.0.2", "lodash.mapvalues": "^4.6.0", "winston-transport": "^4.3.0" diff --git a/src/common.ts b/src/common.ts index 577bce84..8fa1a6b9 100644 --- a/src/common.ts +++ b/src/common.ts @@ -89,6 +89,11 @@ export const LOGGING_SPAN_KEY = 'logging.googleapis.com/spanId'; */ export const LOGGING_SAMPLED_KEY = 'logging.googleapis.com/trace_sampled'; +/** + * Default library version to be used if version retrieval fails + */ +export const NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION = 'unknown'; + // The variable to hold cached library version let libraryVersion: string; @@ -352,11 +357,15 @@ export function getNodejsLibraryVersion() { if (libraryVersion) { return libraryVersion; } - libraryVersion = require(path.resolve( - __dirname, - '../../', - 'package.json' - )).version; + try { + libraryVersion = require(path.resolve( + __dirname, + '../../', + 'package.json' + )).version; + } catch (err) { + libraryVersion = NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION; + } return libraryVersion; } diff --git a/system-test/logging-winston.ts b/system-test/logging-winston.ts index 6f4f8d72..02907904 100644 --- a/system-test/logging-winston.ts +++ b/system-test/logging-winston.ts @@ -185,8 +185,8 @@ describe('LoggingWinston', function () { entry.data[instrumentation.DIAGNOSTIC_INFO_KEY][ instrumentation.INSTRUMENTATION_SOURCE_KEY ]; - assert.equal(info[0].name, 'nodejs'); - assert.equal(info[1].name, 'nodejs-winston'); + assert.equal(info[0].name, 'nodejs-winston'); + assert.equal(info[1].name, 'nodejs'); } else { const data = entry.data as {message: string}; assert.strictEqual(data.message, ` ${MESSAGE}`);