This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020import * as CLS from 'continuation-local-storage' ;
2121import * as semver from 'semver' ;
2222
23- import * as cls_ah from './cls-ah' ;
24-
2523export type Namespace = CLS . Namespace ;
2624export type Func < T > = CLS . Func < T > ;
2725
@@ -33,7 +31,7 @@ import * as Debug from 'debug';
3331const debug = Debug ( 'opencensus' ) ;
3432debug ( '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
3937const TRACE_NAMESPACE = 'opencensus.io' ;
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments