Skip to content

Commit 3552a79

Browse files
authored
Revert "fix: setTraceAttributes cross trace attributes leakage issue #200)" (#205)
This reverts commit 7038775 due to the regression
1 parent f3ccd9b commit 3552a79

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperdx/node-opentelemetry': patch
3+
---
4+
5+
revert: fix: setTraceAttributes cross trace attributes leakage issue
6+

packages/node-opentelemetry/src/MutableAsyncLocalStorageContextManager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ export class MutableAsyncLocalStorageContextManager extends AbstractAsyncHooksCo
4444
thisArg?: ThisParameterType<F>,
4545
...args: A
4646
): ReturnType<F> {
47-
// Create a fresh mutableContext for each new context to prevent
48-
// cross-contamination between concurrent requests
49-
const mutableContext = {
47+
const mutableContext = this._asyncLocalStorage.getStore()
48+
?.mutableContext ?? {
5049
traceAttributes: new Map(),
5150
};
5251

packages/node-opentelemetry/src/__tests__/setTraceAttributes.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ describe('MutableAsyncLocalStorageContextManager - trace attributes isolation',
7575
contextManager.with(ROOT_CONTEXT, () => {
7676
const ctx2 = contextManager.getMutableContext();
7777

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

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

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

0 commit comments

Comments
 (0)