[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Runtime package.json check causes breakage when bundled #1364

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/utils/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const maxDiagnosticValueLen = 14;
export const DIAGNOSTIC_INFO_KEY = 'logging.googleapis.com/diagnostic';
export const INSTRUMENTATION_SOURCE_KEY = 'instrumentation_source';
export const NODEJS_LIBRARY_NAME_PREFIX = 'nodejs';
export const NODEJS_DEFAULT_LIBRARY_VERSION = 'unknown';
export const MAX_INSTRUMENTATION_COUNT = 3;
export type InstrumentationInfo = {name: string; version: string};

Expand Down Expand Up @@ -174,7 +175,7 @@ function truncateValue(value: object | string, maxLen: number) {
}
// Return 'unknown' if version cannot be retrieved
if (typeof value !== 'string') {
return 'unknown';
return NODEJS_DEFAULT_LIBRARY_VERSION;
}
if (value && value.length > maxLen) {
return value.substring(0, maxLen).concat('*');
Expand All @@ -191,11 +192,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_DEFAULT_LIBRARY_VERSION;
}
return libraryVersion;
}

Expand Down