File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,6 @@ import Span from '../span';
1818
1919export interface Dispatcher {
2020 name ( ) : string ;
21- dispatch ( span : Span ) : void ;
21+ dispatch ( span : Span , callback : ( error ) => void ) : void ;
2222 close ( callback : ( ) => void ) : void ;
2323}
Original file line number Diff line number Diff line change @@ -32,9 +32,12 @@ export default class FileDispatcher implements Dispatcher {
3232 return 'FileDispatcher' ;
3333 }
3434
35- dispatch ( span : Span ) : void {
35+ dispatch ( span : Span , callback : ( error ) => void ) : void {
3636 this . _spanFileStream . write ( span . toString ( ) ) ;
3737 this . _spanFileStream . write ( '\n' ) ;
38+ if ( callback ) {
39+ callback ( null ) ;
40+ }
3841 }
3942
4043 close ( callback : ( ) => void ) : void {
Original file line number Diff line number Diff line change @@ -28,8 +28,11 @@ export default class InMemoryDispatcher implements Dispatcher {
2828 return 'InMemoryDispatcher' ;
2929 }
3030
31- dispatch ( span : Span ) : void {
31+ dispatch ( span : Span , callback : ( error ) => void ) : void {
3232 this . _spans . push ( span ) ;
33+ if ( callback ) {
34+ callback ( null ) ;
35+ }
3336 }
3437
3538 close ( callback : ( ) => void ) : void {
Original file line number Diff line number Diff line change @@ -24,7 +24,11 @@ export default class NoopDispatcher implements Dispatcher {
2424 return 'NoopDispatcher' ;
2525 }
2626
27- dispatch ( span : Span ) : void { }
27+ dispatch ( span : Span , callback : ( error ) => void ) : void {
28+ if ( callback ) {
29+ callback ( null ) ;
30+ }
31+ }
2832
2933 close ( callback : ( ) => void ) : void {
3034 if ( callback ) {
Original file line number Diff line number Diff line change @@ -36,14 +36,20 @@ export default class RemoteDispatcher implements Dispatcher {
3636 return 'RemoteDispatcher' ;
3737 }
3838
39- dispatch ( span : Span ) : void {
39+ dispatch ( span : Span , callback : ( error ) => void ) : void {
4040 const proto = this . _convertToProtoSpan ( span ) ;
4141 this . _client . dispatch ( proto , ( err , response ) => {
4242 if ( this . _logger ) {
4343 if ( err ) {
4444 this . _logger . error ( `Fail to dispatch span to haystack-agent ${ err . toString ( ) } ` ) ;
45+ if ( callback ) {
46+ callback ( new Error ( err ) ) ;
47+ }
4548 } else {
4649 this . _logger . debug ( `grpc response code from haystack-agent - ${ response . getCode ( ) } ` ) ;
50+ if ( callback ) {
51+ callback ( null ) ;
52+ }
4753 }
4854 }
4955 } ) ;
Original file line number Diff line number Diff line change @@ -127,14 +127,14 @@ export default class Span {
127127 } ) ;
128128 }
129129
130- finish ( finishTime ?: number ) : void {
130+ finish ( finishTime ?: number , callback ?: ( error ) => void ) : void {
131131 if ( this . _isFinished ) {
132132 const spanInfo = `operation=${ this . operationName } ,context=${ this . context ( ) . toString ( ) } ` ;
133133 throw new Error ( `cant finish the same span twice - ${ spanInfo } ` ) ;
134134 }
135135 const endTime = finishTime || Utils . now ( ) ;
136136 this . _duration = endTime - this . _startTime ;
137- this . _tracer . dispatcher ( ) . dispatch ( this ) ;
137+ this . _tracer . dispatcher ( ) . dispatch ( this , callback ) ;
138138 this . _isFinished = true ;
139139 }
140140
You can’t perform that action at this time.
0 commit comments