Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit edd8845

Browse files
fabiogomessilvakjin
authored andcommitted
fix: nodejs 6 async_hook issue (#9)
PR-URL: #9
1 parent cbce142 commit edd8845

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

packages/opencensus-core/src/internal/cls.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import * as CLS from 'continuation-local-storage';
2121
import * as semver from 'semver';
2222

23-
import * as cls_ah from './cls-ah';
24-
2523
export type Namespace = CLS.Namespace;
2624
export type Func<T> = CLS.Func<T>;
2725

@@ -33,7 +31,7 @@ import * as Debug from 'debug';
3331
const debug = Debug('opencensus');
3432
debug('useAsyncHooks = %s', useAsyncHooks);
3533

36-
const cls: typeof CLS = useAsyncHooks ? cls_ah : CLS;
34+
const cls: typeof CLS = useAsyncHooks ? require('./cls-ah') : CLS;
3735

3836

3937
const TRACE_NAMESPACE = 'opencensus.io';

packages/opencensus-core/src/trace/model/tracer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class Tracer implements types.Tracer {
5252
constructor() {
5353
this.activeLocal = false;
5454
this.contextManager = cls.createNamespace();
55-
this.clearCurrentTrace();
5655
}
5756

5857
/** Gets the current root span. */
@@ -170,6 +169,7 @@ export class Tracer implements types.Tracer {
170169
}
171170
}
172171

172+
// TODO: reveiw clearCurrentTrace when using continuation-local-storage
173173
/** Clears the current root span. */
174174
clearCurrentTrace() {
175175
this.currentRootSpan = null;

packages/opencensus-core/test/test-tracer.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ describe('Tracer', () => {
5252

5353
/** Should get/set the current RootSpan from tracer instance */
5454
describe('get/set currentRootSpan()', () => {
55-
let tracer, rootSpan;
56-
before(() => {
57-
tracer = new Tracer();
58-
rootSpan = new RootSpan(tracer);
59-
tracer.currentRootSpan = rootSpan;
60-
});
55+
const tracer = new Tracer().start(defaultConfig);
6156
it('should get the current RootSpan from tracer instance', () => {
62-
assert.ok(tracer.currentRootSpan instanceof RootSpan);
63-
});
64-
it('should set the current RootSpan from tracer instance', () => {
65-
assert.strictEqual(tracer.currentRootSpan, rootSpan);
57+
tracer.startRootSpan(options, (root) => {
58+
assert.ok(root);
59+
assert.ok(tracer.currentRootSpan instanceof RootSpan);
60+
assert.strictEqual(tracer.currentRootSpan, root);
61+
});
6662
});
6763
});
6864

0 commit comments

Comments
 (0)