From 67308724d51744ca781547cb1fc8d0b2dba07fe0 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 17 Dec 2019 16:11:52 -0800 Subject: [PATCH] fix: review comments and build --- .../opentelemetry-plugin-grpc/src/grpc.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/opentelemetry-plugin-grpc/src/grpc.ts b/packages/opentelemetry-plugin-grpc/src/grpc.ts index ecf234f0d7..2fba28743e 100644 --- a/packages/opentelemetry-plugin-grpc/src/grpc.ts +++ b/packages/opentelemetry-plugin-grpc/src/grpc.ts @@ -328,18 +328,9 @@ export class GrpcPlugin extends BasePlugin { ) { // tslint:disable-next-line:no-any const client = original.apply(this, arguments as any); - const methodsToWrap = [ - ...Object.keys(methods), - ...(Object.keys(methods) - .map(methodName => methods[methodName].originalName) - .filter( - originalName => - !!originalName && client.prototype.hasOwnProperty(originalName) - ) as string[]), - ]; shimmer.massWrap( client.prototype as never, - methodsToWrap as never[], + plugin._getMethodsToWrap(client, methods) as never[], // tslint:disable-next-line:no-any plugin._getPatchedClientMethods() as any ); @@ -348,6 +339,22 @@ export class GrpcPlugin extends BasePlugin { }; } + private _getMethodsToWrap( + client: typeof grpcTypes.Client, + methods: { [key: string]: { originalName?: string } } + ): string[] { + const methodsToWrap = [ + ...Object.keys(methods), + ...(Object.keys(methods) + .map(methodName => methods[methodName].originalName) + .filter( + originalName => + !!originalName && client.prototype.hasOwnProperty(originalName) + ) as string[]), + ]; + return methodsToWrap; + } + private _getPatchedClientMethods() { const plugin = this; return (original: GrpcClientFunc) => { @@ -361,9 +368,12 @@ export class GrpcPlugin extends BasePlugin { parent: plugin._tracer.getCurrentSpan(), }) .setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component); - return plugin._makeGrpcClientRemoteCall(original, args, this, plugin)( - span - ); + return plugin._makeGrpcClientRemoteCall( + original, + args, + this, + plugin + )(span); }; }; }