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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Switch instrumentation code to return version stored in NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION #764

Merged
merged 5 commits into from
Nov 7, 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
22 changes: 4 additions & 18 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {LogSeverityFunctions} from '@google-cloud/logging/build/src/utils/log-co
import mapValues = require('lodash.mapvalues');
import {Options} from '.';
import {Entry, LogEntry} from '@google-cloud/logging/build/src/entry';
import path = require('path');
import {LogSyncOptions} from '@google-cloud/logging/build/src/log-sync';

type Callback = (err: Error | null, apiResponse?: {}) => void;
Expand Down Expand Up @@ -90,13 +89,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_WINSTON_DEFAULT_LIBRARY_VERSION = '5.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 @@ -354,19 +352,7 @@ export class LoggingCommon {
}

export function getNodejsLibraryVersion() {
if (libraryVersion) {
return libraryVersion;
}
try {
libraryVersion = require(path.resolve(
__dirname,
'../../',
'package.json'
)).version;
} catch (err) {
libraryVersion = NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION;
}
return libraryVersion;
return NODEJS_WINSTON_DEFAULT_LIBRARY_VERSION;
}

type MetadataArg = {
Expand Down