1616
1717import { Clock } from '../../internal/clock'
1818import { debug , randomSpanId } from '../../internal/util'
19+ import { Sampler } from '../model/sampler'
1920
2021
2122export interface MapLabels { [ propName : string ] : string ; }
@@ -30,6 +31,7 @@ export interface TraceContext {
3031export interface TraceOptions {
3132 name :string ;
3233 traceContext ?:TraceContext ;
34+ sampler ?:Sampler ;
3335}
3436
3537export interface OnEndSpanEventListener {
@@ -54,6 +56,7 @@ export abstract class SpanBaseModel {
5456 //links
5557 //TODO truncated
5658 private _truncated : boolean ;
59+ private _sampler : Sampler ;
5760
5861 constructor ( ) {
5962 this . _className = this . constructor . name ;
@@ -66,6 +69,7 @@ export abstract class SpanBaseModel {
6669 this . setId ( randomSpanId ( ) ) ;
6770 }
6871
72+
6973 public get id ( ) : string {
7074 return this . _id ;
7175 }
@@ -117,15 +121,22 @@ export abstract class SpanBaseModel {
117121 }
118122
119123 public get startTime ( ) : Date {
120- return this . clock . startTime ;
124+ if ( this . clock ) {
125+ return this . clock . startTime ;
126+ }
127+
121128 }
122129
123130 public get endTime ( ) : Date {
124- return this . clock . endTime ;
131+ if ( this . clock ) {
132+ return this . clock . endTime ;
133+ }
125134 }
126135
127136 public get duration ( ) : number {
128- return this . clock . duration ;
137+ if ( this . clock ) {
138+ return this . clock . duration ;
139+ }
129140 }
130141
131142 public get traceContext ( ) : TraceContext {
@@ -146,6 +157,16 @@ export abstract class SpanBaseModel {
146157 this . annotations [ key ] = value ;
147158 }
148159
160+ public get sampler ( ) {
161+ debug ( 'tracetypes get sampler()' )
162+ return this . _sampler ;
163+ }
164+
165+ public set sampler ( sampler :Sampler ) {
166+ debug ( 'tracetypes set sempler(sampler)' )
167+ this . _sampler = sampler ;
168+ }
169+
149170 public start ( ) {
150171 if ( this . started ) {
151172 debug ( 'calling %s.start() on already started %s %o' ,
@@ -160,13 +181,16 @@ export abstract class SpanBaseModel {
160181 public end ( ) : void {
161182 if ( ! this . started ) {
162183 debug ( 'calling %s.end() on un-started %s %o' ,
163- this . _className , this . _className ,
164- { id : this . id , name : this . name , type : this . type } )
184+ this . _className , this . _className ,
185+ { id : this . id , name : this . name , type : this . type } )
186+ this . _started = false ;
187+ this . _ended = true ;
188+ // this.clock.end();
165189 return
166190 } else if ( this . ended ) {
167191 debug ( 'calling %s.end() on already ended %s %o' ,
168- this . _className , this . _className ,
169- { id : this . id , name : this . name , type : this . type } )
192+ this . _className , this . _className ,
193+ { id : this . id , name : this . name , type : this . type } )
170194 return
171195 }
172196 this . _started = false ;
0 commit comments