1515 */
1616
1717import * as grpc from 'grpc' ;
18- const messages = require ( '../proto_idl_codegen/span_pb' ) ;
1918const services = require ( '../proto_idl_codegen/agent/spanAgent_grpc_pb' ) ;
2019import { Dispatcher } from './dispatcher' ;
2120import Span from '../span' ;
@@ -39,7 +38,7 @@ export default class RemoteDispatcher implements Dispatcher {
3938 }
4039
4140 dispatch ( span : Span , callback : ( error ) => void ) : void {
42- const proto = this . _convertToProtoSpan ( span ) ;
41+ const proto = Utils . convertToProtoSpan ( span ) ;
4342 this . _client . dispatch ( proto , ( err , response ) => {
4443 if ( err ) {
4544 if ( this . _logger ) {
@@ -59,73 +58,6 @@ export default class RemoteDispatcher implements Dispatcher {
5958 } ) ;
6059 }
6160
62- private _convertToProtoSpan ( span : Span ) : any {
63- const protoSpan = new messages . Span ( ) ;
64- protoSpan . setServicename ( span . serviceName ( ) ) ;
65- protoSpan . setOperationname ( span . operationName ( ) ) ;
66- protoSpan . setTraceid ( span . context ( ) . traceId ) ;
67- protoSpan . setSpanid ( span . context ( ) . spanId ) ;
68- protoSpan . setParentspanid ( span . context ( ) . parentSpanId ) ;
69- protoSpan . setStarttime ( span . startTime ( ) ) ;
70- protoSpan . setDuration ( span . duration ( ) ) ;
71-
72- const protoSpanTags = [ ] ;
73-
74- const tags = span . tags ( ) ;
75- for ( const k in tags ) {
76- if ( tags . hasOwnProperty ( k ) ) {
77- protoSpanTags . push ( RemoteDispatcher . _createProtoTag ( k , tags [ k ] ) ) ;
78- }
79- }
80-
81- protoSpan . setTagsList ( protoSpanTags ) ;
82-
83- const protoSpanLogs = [ ] ;
84- span . logs ( ) . forEach ( log => {
85- const protoLog = new messages . Log ( ) ;
86- const protoLogTags = [ ] ;
87- const kvPairs = log . keyValuePairs ;
88- for ( const k in kvPairs ) {
89- if ( kvPairs . hasOwnProperty ( k ) ) {
90- protoLogTags . push ( RemoteDispatcher . _createProtoTag ( k , kvPairs [ k ] ) ) ;
91- }
92- }
93- protoLog . setTimestamp ( log . timestamp ) ;
94- protoLog . setFieldsList ( protoLogTags ) ;
95- protoSpanLogs . push ( protoLog ) ;
96- } ) ;
97-
98- protoSpan . setLogsList ( protoSpanLogs ) ;
99- return protoSpan ;
100- }
101-
102- private static _createProtoTag ( key : string , value : any ) : any {
103- const protoTag = new messages . Tag ( ) ;
104- protoTag . setKey ( key ) ;
105-
106- const tagValue = value ;
107- if ( typeof tagValue === 'number' ) {
108- if ( Utils . isFloatType ( tagValue ) ) {
109- protoTag . setVdouble ( tagValue ) ;
110- protoTag . setType ( messages . Tag . TagType . DOUBLE ) ;
111- } else {
112- protoTag . setVlong ( tagValue ) ;
113- protoTag . setType ( messages . Tag . TagType . LONG ) ;
114- }
115- } else if ( typeof tagValue === 'boolean' ) {
116- protoTag . setVbool ( tagValue ) ;
117- protoTag . setType ( messages . Tag . TagType . BOOL ) ;
118- } else if ( typeof tagValue === 'string' ) {
119- protoTag . setVstr ( tagValue ) ;
120- protoTag . setType ( messages . Tag . TagType . STRING ) ;
121- } else {
122- protoTag . setVbytes ( tagValue ) ;
123- protoTag . setType ( messages . Tag . TagType . BINARY ) ;
124- }
125-
126- return protoTag ;
127- }
128-
12961 close ( callback : ( ) => void ) : void {
13062 grpc . closeClient ( this . _client ) ;
13163 if ( callback ) {
0 commit comments