Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk-node): register context manager if no tracer options are provided #4781

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion experimental/packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
16 changes: 16 additions & 0 deletions experimental/packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down