@@ -39,9 +39,6 @@ export class CoreTracer implements types.Tracer {
3939 private config : configTypes . TracerConfig ;
4040 /** A list of end span event listeners */
4141 private eventListenersLocal : types . SpanEventListener [ ] = [ ] ;
42- /** A list of ended root spans */
43- // @ts -ignore
44- private endedTraces : types . RootSpan [ ] = [ ] ;
4542 /** Bit to represent whether trace is sampled or not. */
4643 private readonly IS_SAMPLED = 0x1 ;
4744 /** A sampler used to make sample decisions */
@@ -162,34 +159,31 @@ export class CoreTracer implements types.Tracer {
162159 } ) ;
163160 }
164161
162+ /** Notifies listeners of the span start. */
165163 onStartSpan ( root : types . RootSpan ) : void {
166- if ( this . active ) {
167- if ( ! root ) {
168- return this . logger . debug ( 'cannot start trace - no active trace found' ) ;
169- }
170- if ( this . currentRootSpan !== root ) {
171- this . logger . debug (
172- 'currentRootSpan != root on notifyStart. Need more investigation.' ) ;
173- }
174- this . notifyStartSpan ( root ) ;
164+ if ( ! this . active ) return ;
165+ if ( ! root ) {
166+ return this . logger . debug ( 'cannot start trace - no active trace found' ) ;
167+ }
168+ if ( this . currentRootSpan !== root ) {
169+ this . logger . debug (
170+ 'currentRootSpan != root on notifyStart. Need more investigation.' ) ;
175171 }
172+ this . notifyStartSpan ( root ) ;
176173 }
177174
178- /**
179- * Is called when a span is ended.
180- * @param root The ended span.
181- */
175+ /** Notifies listeners of the span end. */
182176 onEndSpan ( root : types . RootSpan ) : void {
183- if ( this . active ) {
184- if ( ! root ) {
185- return this . logger . debug ( 'cannot end trace - no active trace found' ) ;
186- }
187- if ( this . currentRootSpan !== root ) {
188- this . logger . debug (
189- 'currentRootSpan != root on notifyEnd. Need more investigation.' ) ;
190- }
191- this . notifyEndSpan ( root ) ;
177+ if ( ! this . active ) return ;
178+ if ( ! root ) {
179+ this . logger . debug ( 'cannot end trace - no active trace found' ) ;
180+ return ;
181+ }
182+ if ( this . currentRootSpan !== root ) {
183+ this . logger . debug (
184+ 'currentRootSpan != root on notifyEnd. Need more investigation.' ) ;
192185 }
186+ this . notifyEndSpan ( root ) ;
193187 }
194188
195189 /**
@@ -221,15 +215,11 @@ export class CoreTracer implements types.Tracer {
221215 }
222216
223217 private notifyEndSpan ( root : types . RootSpan ) {
224- if ( this . active ) {
225- this . logger . debug ( 'starting to notify listeners the end of rootspans' ) ;
226- if ( this . eventListenersLocal && this . eventListenersLocal . length > 0 ) {
227- for ( const listener of this . eventListenersLocal ) {
228- listener . onEndSpan ( root ) ;
229- }
218+ this . logger . debug ( 'starting to notify listeners the end of rootspans' ) ;
219+ if ( this . eventListenersLocal && this . eventListenersLocal . length > 0 ) {
220+ for ( const listener of this . eventListenersLocal ) {
221+ listener . onEndSpan ( root ) ;
230222 }
231- } else {
232- this . logger . debug ( 'this tracer is inactivate cant notify endspan' ) ;
233223 }
234224 }
235225
@@ -240,9 +230,8 @@ export class CoreTracer implements types.Tracer {
240230
241231 /**
242232 * Starts a span.
243- * @param name The span name.
244- * @param kind optional The span kind.
245- * @param parentSpanId The parent span ID.
233+ * @param nameOrOptions Span name string or SpanOptions object.
234+ * @param kind Span kind if not using SpanOptions object.
246235 */
247236 startChildSpan (
248237 nameOrOptions ?: string | types . SpanOptions ,
@@ -277,7 +266,7 @@ export class CoreTracer implements types.Tracer {
277266 * This is necessary in order to create child spans correctly in event
278267 * handlers.
279268 * @param emitter An event emitter whose handlers should have
280- * the trace context binded to them.
269+ * the trace context binded to them.
281270 */
282271 wrapEmitter ( emitter : NodeJS . EventEmitter ) : void {
283272 if ( ! this . active ) {
0 commit comments