Skip to content

Commit

Permalink
Fix context manager for older node versions (#53)
Browse files Browse the repository at this point in the history
Async hooks context manager needs to be activated by calling `.enable()`
before it can be used as a context manager. This is important for older
versions of node that don't use support local storage context manager.
  • Loading branch information
owais authored Mar 29, 2021
1 parent dfa0a76 commit cd1fdda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### Changed

- Context management should not work properly on older versions of NodeJS (<14.8).
([#53](https://github.com/signalfx/splunk-otel-js/pull/53))


## 0.5.0 (03-24-2021)

- Replaced `SPLUNK_TRACE_EXPORTER_URL` with `OTEL_EXPORTER_JAEGER_ENDPOINT`.
Expand Down
4 changes: 3 additions & 1 deletion src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export function startTracing(opts: Partial<Options> = {}): void {
const ContextManager = gte(process.version, '14.8.0')
? AsyncLocalStorageContextManager
: AsyncHooksContextManager;
context.setGlobalContextManager(new ContextManager());
const contextManager = new ContextManager();
contextManager.enable();
context.setGlobalContextManager(contextManager);

// tracer provider
const provider = new NodeTracerProvider(options.tracerConfig);
Expand Down

0 comments on commit cd1fdda

Please sign in to comment.