This repository was archived by the owner on Oct 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
packages/opencensus-core/src/trace Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,18 +76,12 @@ export class RootSpan extends SpanBaseModel implements OnEndSpanEventListener {
7676 }
7777
7878 public startSpan ( name : string , type : string ) {
79- if ( ! this . sampler == null || this . sampler . continue ( this . _traceId ) ) {
80- let newSpan = new Span ( this ) ;
81- newSpan . name = name
82- newSpan . type = type
83- newSpan . start ( ) ;
84- this . _spans . push ( newSpan ) ;
85- return newSpan ;
86- } else {
87- //TODO
88- debug ( "ELDREY -> RootSpan return startSpan null" )
89- return
90- }
79+ let newSpan = new Span ( this ) ;
80+ newSpan . name = name
81+ newSpan . type = type
82+ newSpan . start ( ) ;
83+ this . _spans . push ( newSpan ) ;
84+ return newSpan ;
9185 }
9286
9387}
Original file line number Diff line number Diff line change @@ -61,19 +61,20 @@ export class Span extends SpanBaseModel {
6161 }
6262
6363 public end ( ) : void {
64- super . end ( ) ;
65- this . notifyEnd ( ) ;
66- debug ( 'ending span %o' ,
67- {
68- spanId : this . id ,
69- traceId : this . traceId ,
70- name : this . name ,
71- startTime : this . startTime ,
72- endTime : this . endTime ,
73- duration : this . duration
74- }
75- )
76-
64+ // if(this.sampler.continue(this.traceId)) {
65+
66+ super . end ( ) ;
67+ this . notifyEnd ( ) ;
68+ debug ( 'ending span %o' ,
69+ {
70+ spanId : this . id ,
71+ traceId : this . traceId ,
72+ name : this . name ,
73+ startTime : this . startTime ,
74+ endTime : this . endTime ,
75+ duration : this . duration
76+ } ) ;
77+ // }
7778 }
7879
7980
Original file line number Diff line number Diff line change @@ -77,12 +77,16 @@ export class Tracer implements OnEndSpanEventListener {
7777 return this . contextManager . runAndReturn ( ( root ) => {
7878 let newRoot = new RootSpan ( this , options ) ;
7979 this . setCurrentRootSpan ( newRoot ) ;
80- if ( sampler == null ) {
81- sampler = new Sampler ( newTrace . traceId ) ;
82- sampler . always ( ) ;
80+ debug ( 'ELDREY -> START ROOT SPAN OPTIONS: ' , options ) ;
81+ if ( options . sampler == null ) {
82+ options . sampler = new Sampler ( newRoot . traceId ) ;
83+ options . sampler . always ( ) ;
84+ }
85+ newRoot . sampler = options . sampler ;
86+ if ( newRoot . sampler . continue ( newRoot . traceId ) ) {
87+ debug ( 'ELDREY -> START ROOT SPAN .START()' ) ;
88+ newRoot . start ( ) ;
8389 }
84- newRoot . sampler = sampler ;
85- newRoot . start ( ) ;
8690 return fn ( newRoot ) ;
8791 } ) ;
8892 }
@@ -124,7 +128,7 @@ export class Tracer implements OnEndSpanEventListener {
124128 let newSpan : Span = null ;
125129 if ( ! this . currentRootSpan ) {
126130 debug ( 'no current trace found - cannot start a new span' ) ;
127- } else {
131+ } else {
128132 newSpan = this . currentRootSpan . startSpan ( name , type ) ;
129133 }
130134 return newSpan ;
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import { debug, randomSpanId } from '../../internal/util'
1818
1919
2020const minNumber = 1e-4 ;
21- const maxNumber = 1 ;
21+ const maxNumber = 0xffffffffffffffff ;
2222
2323export class Sampler {
2424 traceId : string ;
@@ -69,13 +69,15 @@ export class Sampler{
6969
7070 public continue ( traceId :string ) :boolean {
7171 debug ( 'Samplre continue' )
72- let lower_bytes = traceId . substring ( traceId . length - 4 )
72+ let lower_bytes = traceId . substring ( 16 )
7373 let j ;
7474 let lower_long : number
75- for ( j = 0 ; j < lower_bytes . length ; j ++ ) {
76- lower_long = lower_bytes . charCodeAt ( j ) ;
77- }
75+ debug ( 'ELDREY -> SAMPLER CONTINUE lower_bytes :' , lower_bytes )
76+
77+ lower_long = parseInt ( lower_bytes , 16 ) ;
7878
79+ debug ( 'ELDREY -> SAMPLER CONTINUE lower_long :' , lower_long )
80+ debug ( 'ELDREY -> SAMPLER CONTINUE this.idUpperBound :' , this . idUpperBound )
7981 if ( lower_long <= this . idUpperBound ) {
8082 return true
8183 } else {
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export interface TraceContext {
3131export interface TraceOptions {
3232 name :string ;
3333 traceContext ?:TraceContext ;
34+ sampler ?:Sampler ;
3435}
3536
3637export interface OnEndSpanEventListener {
You can’t perform that action at this time.
0 commit comments