File tree 3 files changed +43
-4
lines changed
experimental/packages/opentelemetry-instrumentation-grpc
3 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -274,7 +274,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
274
274
const instrumentation = this ;
275
275
return ( original : GrpcClientFunc ) => {
276
276
instrumentation . _diag . debug ( 'patch all client methods' ) ;
277
- return function clientMethodTrace ( this : grpcJs . Client ) {
277
+ function clientMethodTrace ( this : grpcJs . Client ) {
278
278
const name = `grpc.${ original . path . replace ( '/' , '' ) } ` ;
279
279
const args = [ ...arguments ] ;
280
280
const metadata = getMetadata . call (
@@ -289,7 +289,9 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
289
289
return context . with ( trace . setSpan ( context . active ( ) , span ) , ( ) =>
290
290
makeGrpcClientRemoteCall ( original , args , metadata , this ) ( span )
291
291
) ;
292
- } ;
292
+ }
293
+ Object . assign ( clientMethodTrace , original ) ;
294
+ return clientMethodTrace ;
293
295
} ;
294
296
}
295
297
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
285
285
const instrumentation = this ;
286
286
return ( original : GrpcClientFunc ) => {
287
287
instrumentation . _diag . debug ( 'patch all client methods' ) ;
288
- return function clientMethodTrace ( this : grpcTypes . Client ) {
288
+ function clientMethodTrace ( this : grpcTypes . Client ) {
289
289
const name = `grpc.${ ( original . path as string | undefined ) ?. replace (
290
290
'/' ,
291
291
''
@@ -304,7 +304,9 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
304
304
this
305
305
) ( span )
306
306
) ;
307
- } ;
307
+ }
308
+ Object . assign ( clientMethodTrace , original ) ;
309
+ return clientMethodTrace ;
308
310
} ;
309
311
}
310
312
}
Original file line number Diff line number Diff line change @@ -646,6 +646,16 @@ export const runTests = (
646
646
} ) ;
647
647
} ;
648
648
649
+ const runClientMethodTest = (
650
+ method : typeof methodList [ 0 ]
651
+ ) => {
652
+ it ( `should assign original properties for grpc remote method ${ method . methodName } ` , async ( ) => {
653
+ const patchedClientMethod = ( client as any ) [ method . methodName ] ;
654
+ const properties = Object . keys ( patchedClientMethod ) ;
655
+ assert . ok ( properties . length ) ;
656
+ } ) ;
657
+ } ;
658
+
649
659
describe ( 'enable()' , ( ) => {
650
660
const provider = new NodeTracerProvider ( ) ;
651
661
provider . addSpanProcessor ( new SimpleSpanProcessor ( memoryExporter ) ) ;
@@ -801,5 +811,30 @@ export const runTests = (
801
811
} ) ;
802
812
} ) ;
803
813
} ) ;
814
+
815
+ describe ( 'Test assigning properties from original client method to patched client method' , ( ) => {
816
+ before ( async ( ) => {
817
+ plugin . disable ( ) ;
818
+ plugin . setConfig ( { } ) ;
819
+ plugin . enable ( ) ;
820
+
821
+ const packageDefinition = await protoLoader . load ( PROTO_PATH , options ) ;
822
+ const proto = grpc . loadPackageDefinition ( packageDefinition ) . pkg_test ;
823
+
824
+ client = createClient ( grpc , proto ) ;
825
+ } ) ;
826
+
827
+ after ( done => {
828
+ client . close ( ) ;
829
+ server . tryShutdown ( ( ) => {
830
+ plugin . disable ( ) ;
831
+ done ( ) ;
832
+ } ) ;
833
+ } ) ;
834
+
835
+ methodList . map ( method => {
836
+ runClientMethodTest ( method ) ;
837
+ } ) ;
838
+ } ) ;
804
839
} ) ;
805
840
} ;
You can’t perform that action at this time.
0 commit comments