Skip to content

Commit ae592a6

Browse files
committed
fix: fix path to package.json after upgrade to OTel JS SDK 2.0.0
1 parent 804c2c2 commit ae592a6

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

src/1.x/init.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ const debugOutput = hasOptedIn('DASH0_DEBUG');
3333
let packageJson;
3434
let version: string;
3535
try {
36-
// In the published package, the transpiled JS files are in dist/src/init.js, therefore the relative path to
37-
// package.json is two levels above the directory of init.js.
36+
// In the published package, the transpiled JS files are in dist/src/(1.x|2.x)/init.js, therefore the relative path to
37+
// package.json is three levels above the directory of init.js.
3838
// eslint-disable-next-line @typescript-eslint/no-require-imports
39-
packageJson = require('../../package.json');
39+
packageJson = require('../../../package.json');
4040
} catch (e1) {
4141
try {
42-
// In development, the directory is just src, therefore the relative path to package.json is only one level above.
42+
// In development, the directory is just src/(1.x|2.x)/, therefore the relative path to package.json is only two
43+
// levels above.
4344
// eslint-disable-next-line @typescript-eslint/no-require-imports
44-
packageJson = require('../package.json');
45+
packageJson = require('../../package.json');
4546
} catch (e2) {
4647
printDebugStderr(
4748
'Unable to find our own package.json file, will not transmit telemetry.distro.version. This warning can be safely ignored.',
@@ -50,14 +51,17 @@ try {
5051
);
5152
}
5253
}
53-
// Since we read the package.json from two possible relative paths, we are extra-careful to make sure we actually are
54-
// reading from our own package.json file, hence the name check.
55-
if (packageJson && packageJson.name === '@dash0hq/opentelemetry') {
56-
version = packageJson.version;
57-
} else {
58-
printDebugStderr(
59-
`Unexpected package name in our own package.json: ${packageJson.name}, will not transmit telemetry.distro.version. This warning can be safely ignored.`,
60-
);
54+
55+
if (packageJson) {
56+
// Since we read the package.json from two possible relative paths, we are extra-careful to make sure we actually are
57+
// reading from our own package.json file, hence the name check.
58+
if (packageJson.name === '@dash0hq/opentelemetry') {
59+
version = packageJson.version;
60+
} else {
61+
printDebugStderr(
62+
`Unexpected package name in our own package.json: ${packageJson.name}, will not transmit telemetry.distro.version. This warning can be safely ignored.`,
63+
);
64+
}
6165
}
6266

6367
printDebugStdout('Starting NodeSDK.');

src/2.x/init.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ const debugOutput = hasOptedIn('DASH0_DEBUG');
3333
let packageJson;
3434
let version: string;
3535
try {
36-
// In the published package, the transpiled JS files are in dist/src/init.js, therefore the relative path to
37-
// package.json is two levels above the directory of init.js.
36+
// In the published package, the transpiled JS files are in dist/src/(1.x|2.x)/init.js, therefore the relative path to
37+
// package.json is three levels above the directory of init.js.
3838
// eslint-disable-next-line @typescript-eslint/no-require-imports
39-
packageJson = require('../../package.json');
39+
packageJson = require('../../../package.json');
4040
} catch (e1) {
4141
try {
42-
// In development, the directory is just src, therefore the relative path to package.json is only one level above.
42+
// In development, the directory is just src/(1.x|2.x)/, therefore the relative path to package.json is only two
43+
// levels above.
4344
// eslint-disable-next-line @typescript-eslint/no-require-imports
44-
packageJson = require('../package.json');
45+
packageJson = require('../../package.json');
4546
} catch (e2) {
4647
printDebugStderr(
4748
'Unable to find our own package.json file, will not transmit telemetry.distro.version. This warning can be safely ignored.',
@@ -50,14 +51,17 @@ try {
5051
);
5152
}
5253
}
53-
// Since we read the package.json from two possible relative paths, we are extra-careful to make sure we actually are
54-
// reading from our own package.json file, hence the name check.
55-
if (packageJson && packageJson.name === '@dash0hq/opentelemetry') {
56-
version = packageJson.version;
57-
} else {
58-
printDebugStderr(
59-
`Unexpected package name in our own package.json: ${packageJson.name}, will not transmit telemetry.distro.version. This warning can be safely ignored.`,
60-
);
54+
55+
if (packageJson) {
56+
// Since we read the package.json from two possible relative paths, we are extra-careful to make sure we actually are
57+
// reading from our own package.json file, hence the name check.
58+
if (packageJson.name === '@dash0hq/opentelemetry') {
59+
version = packageJson.version;
60+
} else {
61+
printDebugStderr(
62+
`Unexpected package name in our own package.json: ${packageJson.name}, will not transmit telemetry.distro.version. This warning can be safely ignored.`,
63+
);
64+
}
6165
}
6266

6367
printDebugStdout('Starting NodeSDK.');

test/integration/ChildProcessWrapper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export function defaultAppConfiguration(appPort: number): ChildProcessWrapperOpt
215215
OTEL_METRIC_EXPORT_TIMEOUT: '90',
216216

217217
DASH0_OTEL_COLLECTOR_BASE_URL: 'http://localhost:4318',
218+
DASH0_DEBUG: 'true',
218219

219220
// helpful options for troubleshooting integration tests:
220221
// DASH0_DEBUG_PRINT_SPANS: 'true',

0 commit comments

Comments
 (0)