Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/early-mayflies-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/node-opentelemetry': patch
---

revert: fix: setTraceAttributes cross trace attributes leakage issue

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export class MutableAsyncLocalStorageContextManager extends AbstractAsyncHooksCo
thisArg?: ThisParameterType<F>,
...args: A
): ReturnType<F> {
// Create a fresh mutableContext for each new context to prevent
// cross-contamination between concurrent requests
const mutableContext = {
const mutableContext = this._asyncLocalStorage.getStore()
?.mutableContext ?? {
traceAttributes: new Map(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ describe('MutableAsyncLocalStorageContextManager - trace attributes isolation',
contextManager.with(ROOT_CONTEXT, () => {
const ctx2 = contextManager.getMutableContext();

// Should NOT have parent's attributes (fresh Map)
expect(ctx2?.traceAttributes.get('userId')).toBeUndefined();
expect(ctx2?.traceAttributes.get('sharedKey')).toBeUndefined();
// FIXME: the ctx2 should be fresh
expect(ctx2?.traceAttributes.get('userId')).toBe('user-1');
expect(ctx2?.traceAttributes.get('sharedKey')).toBe('parent-value');

// Set new attributes in child context
ctx2?.traceAttributes.set('userId', 'user-2');
Expand All @@ -87,10 +87,10 @@ describe('MutableAsyncLocalStorageContextManager - trace attributes isolation',
expect(ctx2?.traceAttributes.get('sharedKey')).toBe('child-value');
});

// After exiting child context, parent should still have original attributes
// FIXME: After exiting child context, parent context shouldn't be overwritten
const ctx1Again = contextManager.getMutableContext();
expect(ctx1Again?.traceAttributes.get('userId')).toBe('user-1');
expect(ctx1Again?.traceAttributes.get('sharedKey')).toBe('parent-value');
expect(ctx1Again?.traceAttributes.get('userId')).toBe('user-2');
expect(ctx1Again?.traceAttributes.get('sharedKey')).toBe('child-value');
});
});

Expand Down