Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit 4e12496

Browse files
authored
fix: Prevent instrumentation crash and fix the system test (#666)
* fix: Prevent instrumentation crash and fix the system test * Update base package to 10.2.2.
1 parent 303320e commit 4e12496

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"precompile": "gts clean"
5252
},
5353
"dependencies": {
54-
"@google-cloud/logging": "^10.1.11",
54+
"@google-cloud/logging": "^10.2.2",
5555
"google-auth-library": "^8.0.2"
5656
},
5757
"devDependencies": {

src/index.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export const LOGGING_SPAN_KEY = 'logging.googleapis.com/spanId';
7070
*/
7171
export const LOGGING_SAMPLED_KEY = 'logging.googleapis.com/trace_sampled';
7272

73+
/**
74+
* Default library version to be used if version retrieval fails
75+
*/
76+
export const NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION = 'unknown';
77+
7378
// The variable to hold cached library version
7479
let libraryVersion: string;
7580

@@ -479,11 +484,15 @@ export class LoggingBunyan extends Writable {
479484
if (libraryVersion) {
480485
return libraryVersion;
481486
}
482-
libraryVersion = require(path.resolve(
483-
__dirname,
484-
'../../',
485-
'package.json'
486-
)).version;
487+
try {
488+
libraryVersion = require(path.resolve(
489+
__dirname,
490+
'../../',
491+
'package.json'
492+
)).version;
493+
} catch (err) {
494+
libraryVersion = NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION;
495+
}
487496
return libraryVersion;
488497
}
489498
}

system-test/logging-bunyan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ describe('LoggingBunyan', function () {
9191
const info = (entry.data as any)[instrumentation.DIAGNOSTIC_INFO_KEY][
9292
instrumentation.INSTRUMENTATION_SOURCE_KEY
9393
];
94-
assert.equal(info[0].name, 'nodejs');
94+
assert.equal(info[0].name, 'nodejs-bunyan');
9595
assert.ok(info[0].version.includes('.'));
96-
assert.equal(info[1].name, 'nodejs-bunyan');
96+
assert.equal(info[1].name, 'nodejs');
9797
assert.ok(info[1].version.includes('.'));
9898
isDiagnosticPresent = true;
9999
} else {

0 commit comments

Comments
 (0)