Skip to content

Commit

Permalink
fix: Switch instrumentation code to return version stored in NODEJS_B…
Browse files Browse the repository at this point in the history
…UNYAN_DEFAULT_LIBRARY_VERSION (#672)

* fix: Switch instrumentation code to return version stored in NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION

* Fix comment for release-please annotations

* Fix comment

* Fix comment
  • Loading branch information
losalex committed Nov 7, 2022
1 parent 499bfe3 commit 2eb88d8
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
setInstrumentationStatus,
createDiagnosticEntry,
} from '@google-cloud/logging/build/src/utils/instrumentation';
import path = require('path');

// Export the express middleware as 'express'.
export {express};
Expand Down Expand Up @@ -71,13 +70,12 @@ 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
* Default library version to be used
* Using release-please annotations to update DEFAULT_INSTRUMENTATION_VERSION with latest version.
* See https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files
*/
export const NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION = '4.2.0'; // {x-release-please-version}

// The variable to hold cached library version
let libraryVersion: string;

/**
* Gets the current fully qualified trace ID when available from the
* @google-cloud/trace-agent library in the LogEntry.trace field format of:
Expand Down Expand Up @@ -477,23 +475,11 @@ export class LoggingBunyan extends Writable {
}

/**
* Method used to retrieve the current logging-bunyan library version
* Method used to retrieve the current logging-bunyan library version stored in NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION
* @returns The version of this library
*/
getNodejsLibraryVersion() {
if (libraryVersion) {
return libraryVersion;
}
try {
libraryVersion = require(path.resolve(
__dirname,
'../../',
'package.json'
)).version;
} catch (err) {
libraryVersion = NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION;
}
return libraryVersion;
return NODEJS_BUNYAN_DEFAULT_LIBRARY_VERSION;
}
}

Expand Down

0 comments on commit 2eb88d8

Please sign in to comment.