15
15
*/
16
16
17
17
import arrify = require( 'arrify' ) ;
18
- import path = require( 'path' ) ;
19
18
import { Entry } from '../entry' ;
20
19
21
20
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -29,15 +28,17 @@ global.instrumentationAdded = false;
29
28
// The global variable to avoid records inspection once instrumentation already written to prevent perf impact
30
29
global . shouldSkipInstrumentationCheck = false ;
31
30
32
- // The variable to hold cached library version
33
- let libraryVersion : string ;
34
-
35
31
// Max length for instrumentation library name and version values
36
32
const maxDiagnosticValueLen = 14 ;
37
33
38
34
export const DIAGNOSTIC_INFO_KEY = 'logging.googleapis.com/diagnostic' ;
39
35
export const INSTRUMENTATION_SOURCE_KEY = 'instrumentation_source' ;
40
36
export 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
+ */
41
42
export const NODEJS_DEFAULT_LIBRARY_VERSION = '10.3.0' ; // {x-release-please-version}
42
43
export const MAX_INSTRUMENTATION_COUNT = 3 ;
43
44
export type InstrumentationInfo = { name : string ; version : string } ;
@@ -184,24 +185,11 @@ function truncateValue(value: object | string, maxLen: number) {
184
185
}
185
186
186
187
/**
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
189
189
* @returns {string } A current library version.
190
190
*/
191
191
export 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 ;
205
193
}
206
194
207
195
/**
0 commit comments