Skip to content

Commit 2486c3d

Browse files
obecnymayurkale22
andauthored
chore: fixing zone from which to fork a new zone (#1209)
* chore: fixing zone from which to fork a new zone * chore: adding tests for creating zone Co-authored-by: Mayur Kale <[email protected]>
1 parent 28ad2ce commit 2486c3d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class ZoneContextManager implements ContextManager {
113113
* @param context A context (span) to be bind with Zone
114114
*/
115115
private _createZone(zoneName: string, context: unknown): Zone {
116-
return Zone.root.fork({
116+
return Zone.current.fork({
117117
name: zoneName,
118118
properties: {
119119
[ZONE_CONTEXT_KEY]: context,

packages/opentelemetry-context-zone-peer-dep/test/ZoneContextManager.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ describe('ZoneContextManager', () => {
199199
});
200200
});
201201
});
202+
203+
it('should fork new zone from active one', () => {
204+
const context = Context.ROOT_CONTEXT;
205+
const rootZone = Zone.current;
206+
contextManager.with(context, () => {
207+
const zone1 = Zone.current;
208+
assert.ok(zone1.parent === rootZone);
209+
contextManager.with(context, () => {
210+
const zone2 = Zone.current;
211+
contextManager.with(context, () => {
212+
const zone3 = Zone.current;
213+
assert.ok(zone3.parent === zone2);
214+
});
215+
assert.ok(zone2.parent === zone1);
216+
});
217+
});
218+
});
202219
});
203220

204221
describe('.bind(function)', () => {

0 commit comments

Comments
 (0)