From b2da7f190ad3a7664b047d4a190a235da0ac554b Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 18 Dec 2023 14:09:36 +0100 Subject: [PATCH 1/3] fix(instrumentation): do not export Node.js types for Browser users --- .../packages/opentelemetry-instrumentation/src/index.ts | 5 ++--- .../opentelemetry-instrumentation/src/platform/index.ts | 6 +++++- .../src/platform/node/index.ts | 2 ++ .../node}/instrumentationNodeModuleDefinition.ts | 2 +- .../{ => platform/node}/instrumentationNodeModuleFile.ts | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) rename experimental/packages/opentelemetry-instrumentation/src/{ => platform/node}/instrumentationNodeModuleDefinition.ts (98%) rename experimental/packages/opentelemetry-instrumentation/src/{ => platform/node}/instrumentationNodeModuleFile.ts (94%) diff --git a/experimental/packages/opentelemetry-instrumentation/src/index.ts b/experimental/packages/opentelemetry-instrumentation/src/index.ts index 0185bfc79d8..321de80dc31 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/index.ts @@ -15,9 +15,8 @@ */ export * from './autoLoader'; -export { InstrumentationBase } from './platform/index'; -export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition'; -export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile'; +// Exports for Node.js and Browser are different, therefore exporting * +export * from './platform/index'; export * from './types'; export * from './types_internal'; export * from './utils'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts index 81d30962522..da34ecd10fb 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts @@ -14,4 +14,8 @@ * limitations under the License. */ -export { InstrumentationBase } from './node'; +export { + InstrumentationNodeModuleFile, + InstrumentationNodeModuleDefinition, + InstrumentationBase, +} from './node'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts index 1e81931b2a0..cfff43c58c0 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts @@ -14,3 +14,5 @@ * limitations under the License. */ export { InstrumentationBase } from './instrumentation'; +export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile'; +export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleDefinition.ts similarity index 98% rename from experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts rename to experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleDefinition.ts index e45a943a7fc..6fd1afb300d 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleDefinition.ts @@ -17,7 +17,7 @@ import { InstrumentationModuleDefinition, InstrumentationModuleFile, -} from './types'; +} from '../../types'; export class InstrumentationNodeModuleDefinition implements InstrumentationModuleDefinition diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts similarity index 94% rename from experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts rename to experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts index 574f17257e8..e5d642e7d48 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { InstrumentationModuleFile } from './types'; +import { InstrumentationModuleFile } from '../../types'; import { normalize } from 'path'; export class InstrumentationNodeModuleFile From d0d2c0725c38113e75e75cb920c0f0b004c84766 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 18 Dec 2023 14:22:56 +0100 Subject: [PATCH 2/3] fix(changelog): add changelog entry --- experimental/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 2b4a27e9681..fca78260065 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -10,6 +10,9 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) +* fix(instrumentation): do not export Node.js-specific types for Browser users [#4378](https://github.com/open-telemetry/opentelemetry-js/pull/4378) @pichlermarc + * Fixes a bug where `InstrumentationNodeModuleFile` and `InstrumentationNodeModuleDefinition` were exported even if using the package in a browser context + ### :books: (Refine Doc) ### :house: (Internal) From 83ab4db0fde8c8dd6070cd710e0964713d0c3136 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 18 Dec 2023 14:41:50 +0100 Subject: [PATCH 3/3] fix(instrumentation): undo import change to test file --- .../test/node/EsmInstrumentation.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs b/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs index f09097cd796..715dbdbff22 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs +++ b/experimental/packages/opentelemetry-instrumentation/test/node/EsmInstrumentation.test.mjs @@ -18,7 +18,7 @@ import * as assert from 'assert'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, -} from '../../build/src/index.js'; +} from '../../build/src/platform/index.js'; import * as exported from 'test-esm-module'; class TestInstrumentationWrapFn extends InstrumentationBase {