Skip to content

Commit 4b90c33

Browse files
committed
fix: clientMethodTrace missing original properties
1 parent 6724a1b commit 4b90c33

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

experimental/packages/opentelemetry-instrumentation-grpc/src/grpc-js/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
274274
const instrumentation = this;
275275
return (original: GrpcClientFunc) => {
276276
instrumentation._diag.debug('patch all client methods');
277-
return function clientMethodTrace(this: grpcJs.Client) {
277+
function clientMethodTrace(this: grpcJs.Client) {
278278
const name = `grpc.${original.path.replace('/', '')}`;
279279
const args = [...arguments];
280280
const metadata = getMetadata.call(
@@ -289,7 +289,9 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
289289
return context.with(trace.setSpan(context.active(), span), () =>
290290
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
291291
);
292-
};
292+
}
293+
Object.assign(clientMethodTrace, original);
294+
return clientMethodTrace;
293295
};
294296
}
295297

experimental/packages/opentelemetry-instrumentation-grpc/src/grpc/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
285285
const instrumentation = this;
286286
return (original: GrpcClientFunc) => {
287287
instrumentation._diag.debug('patch all client methods');
288-
return function clientMethodTrace(this: grpcTypes.Client) {
288+
function clientMethodTrace(this: grpcTypes.Client) {
289289
const name = `grpc.${(original.path as string | undefined)?.replace(
290290
'/',
291291
''
@@ -304,7 +304,9 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
304304
this
305305
)(span)
306306
);
307-
};
307+
}
308+
Object.assign(clientMethodTrace, original);
309+
return clientMethodTrace;
308310
};
309311
}
310312
}

experimental/packages/opentelemetry-instrumentation-grpc/test/helper.ts

+35
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,16 @@ export const runTests = (
646646
});
647647
};
648648

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+
649659
describe('enable()', () => {
650660
const provider = new NodeTracerProvider();
651661
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
@@ -801,5 +811,30 @@ export const runTests = (
801811
});
802812
});
803813
});
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+
});
804839
});
805840
};

0 commit comments

Comments
 (0)