Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clientMethodTrace missing original properties #2650

Merged
merged 2 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
const instrumentation = this;
return (original: GrpcClientFunc) => {
instrumentation._diag.debug('patch all client methods');
return function clientMethodTrace(this: grpcJs.Client) {
function clientMethodTrace(this: grpcJs.Client) {
const name = `grpc.${original.path.replace('/', '')}`;
const args = [...arguments];
const metadata = getMetadata.call(
Expand All @@ -289,7 +289,9 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
return context.with(trace.setSpan(context.active(), span), () =>
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
);
};
}
Object.assign(clientMethodTrace, original);
return clientMethodTrace;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
const instrumentation = this;
return (original: GrpcClientFunc) => {
instrumentation._diag.debug('patch all client methods');
return function clientMethodTrace(this: grpcTypes.Client) {
function clientMethodTrace(this: grpcTypes.Client) {
const name = `grpc.${(original.path as string | undefined)?.replace(
'/',
''
Expand All @@ -304,7 +304,9 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
this
)(span)
);
};
}
Object.assign(clientMethodTrace, original);
return clientMethodTrace;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ export const runTests = (
});
};

const runClientMethodTest = (
method: typeof methodList[0]
) => {
it(`should assign original properties for grpc remote method ${method.methodName}`, async () => {
const patchedClientMethod = (client as any)[method.methodName];
const properties = Object.keys(patchedClientMethod);
assert.ok(properties.length);
});
};

describe('enable()', () => {
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
Expand Down Expand Up @@ -801,5 +811,30 @@ export const runTests = (
});
});
});

describe('Test assigning properties from original client method to patched client method', () => {
before(async () => {
plugin.disable();
plugin.setConfig({});
plugin.enable();

const packageDefinition = await protoLoader.load(PROTO_PATH, options);
const proto = grpc.loadPackageDefinition(packageDefinition).pkg_test;

client = createClient(grpc, proto);
});

after(done => {
client.close();
server.tryShutdown(() => {
plugin.disable();
done();
});
});

methodList.map(method => {
runClientMethodTest(method);
});
});
});
};