1515 */
1616
1717import * as cls from '../../internal/cls'
18- import { Trace } from './trace'
19- import { Span } from './span'
20- import { debug } from '../../internal/util'
21- import { Stackdriver } from '../../exporters/stackdriver/stackdriver'
22- import { StackdriverOptions } from '../../exporters/stackdriver/options'
18+ import { Trace } from './trace'
19+ import { Span } from './span'
20+ import { debug } from '../../internal/util'
21+ import { Stackdriver } from '../../exporters/stackdriver/stackdriver'
22+ import { StackdriverOptions } from '../../exporters/stackdriver/options'
2323import { Exporter } from '../../exporters/exporter'
2424
2525export type Func < T > = ( ...args : any [ ] ) => T ;
2626
2727export class Tracer {
2828
2929 readonly PLUGINS = [ 'http' , 'https' , 'mongodb-core' , 'express' ] ;
30-
30+
3131 private _active : boolean ;
3232 private contextManager : cls . Namespace ;
3333 private exporter : Exporter ;
@@ -40,15 +40,15 @@ export class Tracer {
4040 this . contextManager = cls . createNamespace ( ) ;
4141 }
4242
43- public get currentTrace ( ) : Trace {
44- return this . contextManager . get ( 'trace' ) ;
43+ public get currentTrace ( ) : Trace {
44+ return this . contextManager . get ( 'trace' ) ;
4545 }
4646
47- private setCurrentTrace ( trace :Trace ) {
48- this . contextManager . set ( 'trace' , trace ) ;
47+ private setCurrentTrace ( trace : Trace ) {
48+ this . contextManager . set ( 'trace' , trace ) ;
4949 }
5050
51- public start ( config ?:Object ) : Tracer {
51+ public start ( config ?: Object ) : Tracer {
5252 this . _active = true ;
5353 return this ;
5454 }
@@ -65,22 +65,22 @@ export class Tracer {
6565 }
6666
6767 public endTrace ( ) : void {
68- if ( ! this . currentTrace ) {
68+ if ( ! this . currentTrace ) {
6969 return debug ( 'cannot end trace - no active trace found' )
7070 }
7171 this . currentTrace . end ( ) ;
7272 this . addEndedTrace ( this . currentTrace ) ;
7373 //this.clearCurrentTrace();
7474 }
75-
75+
7676 public clearCurrentTrace ( ) {
7777 this . setCurrentTrace ( null ) ;
7878 }
7979
80- public startSpan ( name :string , type : string ) : Span {
80+ public startSpan ( name : string , type : string ) : Span {
8181 let newSpan : Span = null ;
82- if ( ! this . currentTrace ) {
83- debug ( 'no current trace found - cannot start a new span' ) ;
82+ if ( ! this . currentTrace ) {
83+ debug ( 'no current trace found - cannot start a new span' ) ;
8484 } else {
8585 newSpan = this . currentTrace . startSpan ( name , type ) ;
8686 }
@@ -97,35 +97,35 @@ export class Tracer {
9797 if ( this . active ) {
9898 //TODO: temp solution
9999 //this.endedTraces.push(trace);
100- this . exporter . emit ( this . currentTrace ) ;
100+ this . exporter . writeTrace ( this . currentTrace ) ;
101101 }
102102 }
103103
104104 public wrap < T > ( fn : Func < T > ) : Func < T > {
105105 if ( ! this . active ) {
106- return fn ;
107- }
108-
106+ return fn ;
107+ }
108+
109109 // This is safe because isActive checks the value of this.namespace.
110110 const namespace = this . contextManager as cls . Namespace ;
111111 return namespace . bind < T > ( fn ) ;
112112 }
113-
113+
114114 public wrapEmitter ( emitter : NodeJS . EventEmitter ) : void {
115- if ( ! this . active ) {
116- return ;
117- }
115+ if ( ! this . active ) {
116+ return ;
117+ }
118118
119119 // This is safe because isActive checks the value of this.namespace.
120120 const namespace = this . contextManager as cls . Namespace ;
121121 namespace . bindEmitter ( emitter ) ;
122122 }
123123
124- public registerExporter ( exporter :Exporter ) {
124+ public registerExporter ( exporter : Exporter ) {
125125 this . exporter = exporter ;
126126 }
127127
128- }
128+ }
129129
130130
131131
0 commit comments