From 01b870659c4afdaf77876b6616e7d8b9f6faf881 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 10 Jun 2024 12:56:31 +0200 Subject: [PATCH 1/2] fix(sdk-node): register context manager if no tracer options are provided --- .../packages/opentelemetry-sdk-node/src/sdk.ts | 5 ++++- .../opentelemetry-sdk-node/test/sdk.test.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts index d26ffea4efb..7cb02a2120f 100644 --- a/experimental/packages/opentelemetry-sdk-node/src/sdk.ts +++ b/experimental/packages/opentelemetry-sdk-node/src/sdk.ts @@ -247,7 +247,10 @@ export class NodeSDK { } tracerProvider.register({ - contextManager: this._tracerProviderConfig?.contextManager, + contextManager: + this._tracerProviderConfig?.contextManager ?? + // _tracerProviderConfig may be undefined if trace-specific settings are not provided - fall back to raw config + this._configuration?.contextManager, propagator: this._tracerProviderConfig?.textMapPropagator, }); diff --git a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts index 22e1794ccc6..12cf964f203 100644 --- a/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts +++ b/experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts @@ -325,6 +325,22 @@ describe('Node SDK', () => { await sdk.shutdown(); delete env.OTEL_TRACES_EXPORTER; }); + + it('should register a context manager if only a context manager is provided', async () => { + // arrange + const expectedContextManager = new AsyncHooksContextManager(); + const sdk = new NodeSDK({ + contextManager: expectedContextManager, + }); + + // act + sdk.start(); + + // assert + const actualContextManager = context['_getContextManager'](); + assert.equal(actualContextManager, expectedContextManager); + await sdk.shutdown(); + }); }); async function waitForNumberOfMetrics( From ec9d506c4b19429a35112b32f1de943977c1d851 Mon Sep 17 00:00:00 2001 From: Marc Pichler Date: Mon, 10 Jun 2024 13:01:13 +0200 Subject: [PATCH 2/2] chore: add changelog entry --- experimental/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index a4071de14f1..4a2abad3844 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) +* fix(sdk-node): register context manager if no tracer options are provided [#4781](https://github.com/open-telemetry/opentelemetry-js/pull/4781) @pichlermarc + ### :books: (Refine Doc) ### :house: (Internal)