1515 */
1616
1717import arrify = require( 'arrify' ) ;
18- import path = require( 'path' ) ;
1918import { Entry } from '../entry' ;
2019
2120// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -29,15 +28,17 @@ global.instrumentationAdded = false;
2928// The global variable to avoid records inspection once instrumentation already written to prevent perf impact
3029global . shouldSkipInstrumentationCheck = false ;
3130
32- // The variable to hold cached library version
33- let libraryVersion : string ;
34-
3531// Max length for instrumentation library name and version values
3632const maxDiagnosticValueLen = 14 ;
3733
3834export const DIAGNOSTIC_INFO_KEY = 'logging.googleapis.com/diagnostic' ;
3935export const INSTRUMENTATION_SOURCE_KEY = 'instrumentation_source' ;
4036export const NODEJS_LIBRARY_NAME_PREFIX = 'nodejs' ;
37+ /**
38+ * Default library version to be used
39+ * Using release-please annotations to update DEFAULT_INSTRUMENTATION_VERSION with latest version.
40+ * See https://github.com/googleapis/release-please/blob/main/docs/customizing.md#updating-arbitrary-files
41+ */
4142export const NODEJS_DEFAULT_LIBRARY_VERSION = '10.3.0' ; // {x-release-please-version}
4243export const MAX_INSTRUMENTATION_COUNT = 3 ;
4344export type InstrumentationInfo = { name : string ; version : string } ;
@@ -184,24 +185,11 @@ function truncateValue(value: object | string, maxLen: number) {
184185}
185186
186187/**
187- * The helper function to retrieve current library version from 'package.json' file. Note that
188- * since we use {path.resolve}, the search for 'package.json' could be impacted by current working directory.
188+ * The helper function to retrieve current library version from annotated NODEJS_DEFAULT_LIBRARY_VERSION
189189 * @returns {string } A current library version.
190190 */
191191export function getNodejsLibraryVersion ( ) {
192- if ( libraryVersion ) {
193- return libraryVersion ;
194- }
195- try {
196- libraryVersion = require ( path . resolve (
197- __dirname ,
198- '../../../' ,
199- 'package.json'
200- ) ) . version ;
201- } catch ( err ) {
202- libraryVersion = NODEJS_DEFAULT_LIBRARY_VERSION ;
203- }
204- return libraryVersion ;
192+ return NODEJS_DEFAULT_LIBRARY_VERSION ;
205193}
206194
207195/**
0 commit comments