@@ -20,8 +20,10 @@ import { Span } from './span'
2020import { debug } from '../../internal/util'
2121import { Stackdriver } from '../../exporters/stackdriver/stackdriver'
2222import { StackdriverOptions } from '../../exporters/stackdriver/options'
23+ import { Exporter } from '../../exporters/exporter'
2324import { TraceContext , OnEndSpanEventListener } from '../types/tracetypes' ;
2425import { TracerConfig , defaultConfig } from '../tracing' ;
26+ import { Buffer } from '../../exporters/buffer'
2527
2628export type Func < T > = ( ...args : any [ ] ) => T ;
2729
@@ -30,12 +32,13 @@ export class Tracer implements OnEndSpanEventListener {
3032
3133 readonly PLUGINS = [ 'http' , 'https' , 'mongodb-core' , 'express' ] ;
3234
35+ //public buffer: Buffer;
3336 private _active : boolean ;
3437 private contextManager : cls . Namespace ;
3538 private config : TracerConfig ;
3639
3740 //TODO: simple solution - to be rewied in future
38- private eventListeners : OnEndSpanEventListener [ ] = [ ] ;
41+ private eventListeners : OnEndSpanEventListener [ ] = [ ] ;
3942 //TODO: temp solution
4043 private endedTraces : RootSpan [ ] = [ ] ;
4144
@@ -58,6 +61,10 @@ export class Tracer implements OnEndSpanEventListener {
5861 return this ;
5962 }
6063
64+ public getEventListeners ( ) : OnEndSpanEventListener [ ] {
65+ return this . eventListeners ;
66+ }
67+
6168 public stop ( ) {
6269 this . _active = false ;
6370 }
@@ -66,53 +73,61 @@ export class Tracer implements OnEndSpanEventListener {
6673 return this . _active ;
6774 }
6875
69- public startRootSpan ( context ?: TraceContext ) : RootSpan {
76+ public startRootSpan ( name ?: string , type ?: string , context ?: TraceContext ) : RootSpan {
7077 let newRootSpan = new RootSpan ( this , context ) ;
78+ if ( name ) { newRootSpan . name = name }
79+ if ( type ) { newRootSpan . type = type }
7180 this . setCurrentRootSpan ( newRootSpan ) ;
7281 newRootSpan . start ( ) ;
7382 return newRootSpan ;
7483 }
7584
7685
77- public onEndSpan ( root :RootSpan ) : void {
86+ public onEndSpan ( root : RootSpan ) : void {
7887 if ( ! this . currentRootSpan ) {
7988 return debug ( 'cannot end trace - no active trace found' )
8089 }
81- if ( this . currentRootSpan != root ) {
82- return debug ( 'currentRootSpan != root on notifyEnd. Possbile implementation bug.' )
90+ if ( this . currentRootSpan != root ) {
91+ return debug ( 'currentRootSpan != root on notifyEnd. Possbile implementation bug.' )
8392 }
8493 this . notifyEndSpan ( this . currentRootSpan ) ;
8594 //this.clearCurrentTrace();
8695 }
8796
8897 //TODO: review
8998 public runInContex < T > ( fn : Func < T > ) : T {
90- return this . contextManager . runAndReturn ( fn )
99+ return this . contextManager . runAndReturn ( fn )
91100 }
92-
93- public registerEndSpanListener ( listner : OnEndSpanEventListener ) {
94101
95- this . eventListeners . push ( listner ) ;
102+ public registerEndSpanListener ( listener : OnEndSpanEventListener ) {
103+ this . eventListeners . push ( listener ) ;
104+ //this.buffer.registerExporter(exporter)
96105 }
97106
107+ /*public registerExporter(exporter: Exporter) {
108+ //this.eventListeners.push(listner);
109+ this.buffer.registerExporter(exporter)
110+ }*/
111+
98112 private notifyEndSpan ( root : RootSpan ) {
99113 if ( this . active ) {
100- if ( this . eventListeners && this . eventListeners . length > 0 ) {
114+ //this.buffer.onEndSpan(root);
115+ if ( this . eventListeners && this . eventListeners . length > 0 ) {
101116 this . eventListeners . forEach ( ( listener ) => listener . onEndSpan ( root ) )
102117 }
103118 } else {
104- debug ( 'this tracer is inactivate cant notify endspan' )
119+ debug ( 'this tracer is inactivate cant notify endspan' )
105120 }
106121 }
107122
108123 public clearCurrentTrace ( ) {
109124 this . setCurrentRootSpan ( null ) ;
110125 }
111126
112- public startSpan ( name : string , type : string ) : Span {
127+ public startSpan ( name ? : string , type ? : string ) : Span {
113128 let newSpan : Span = null ;
114129 if ( ! this . currentRootSpan ) {
115- debug ( 'no current trace found - cannot start a new span' ) ;
130+ debug ( 'no current trace found - must start a new root span first ' ) ;
116131 } else {
117132 newSpan = this . currentRootSpan . startSpan ( name , type ) ;
118133 }
0 commit comments