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

Conversation

bgpo
Copy link
Contributor

@bgpo bgpo commented Dec 6, 2021

Which problem is this PR solving?

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #2580 by assigning the properties from original back to clientMethodTrace.

/**
* Parse initial client call properties and start a span to trace its execution
*/
private _getPatchedClientMethods(
grpcClient: typeof grpcJs
): (original: GrpcClientFunc) => () => EventEmitter {
const instrumentation = this;
return (original: GrpcClientFunc) => {
instrumentation._diag.debug('patch all client methods');
return function clientMethodTrace(this: grpcJs.Client) {
const name = `grpc.${original.path.replace('/', '')}`;
const args = [...arguments];
const metadata = getMetadata.call(
instrumentation,
grpcClient,
original,
args
);
const span = instrumentation.tracer.startSpan(name, {
kind: SpanKind.CLIENT,
});
return context.with(trace.setSpan(context.active(), span), () =>
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
);
};
};
}

The original is a function and an object. For more details see below:

https://github.com/grpc/grpc-node/blob/1ddd8ae4e7e507f75b1bb56e3f91bd9261004d31/packages/grpc-js/src/make-client.ts#L133-L171

The returned function clientMethodTrace is without those extra object entries.

Short description of the changes

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test assigning properties from original client method to patched client method

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@bgpo bgpo requested a review from a team as a code owner December 6, 2021 05:48
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 6, 2021

CLA Signed

The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Dec 6, 2021

Codecov Report

Merging #2650 (f87e6b2) into main (09d3f68) will increase coverage by 0.00%.
The diff coverage is n/a.

❗ Current head f87e6b2 differs from pull request most recent head 20d5396. Consider uploading reports for the commit 20d5396 to get more accurate results

@@           Coverage Diff           @@
##             main    #2650   +/-   ##
=======================================
  Coverage   93.09%   93.10%           
=======================================
  Files         123      123           
  Lines        4753     4757    +4     
  Branches     1059     1059           
=======================================
+ Hits         4425     4429    +4     
  Misses        328      328           
Impacted Files Coverage Δ
...entelemetry-instrumentation-grpc/src/grpc/index.ts 93.10% <0.00%> (+0.12%) ⬆️
...elemetry-instrumentation-grpc/src/grpc-js/index.ts 90.90% <0.00%> (+0.18%) ⬆️

@dyladan
Copy link
Member

dyladan commented Dec 6, 2021

Can you please copy the explanation from the issue onto this and provide a test?

Thanks for debugging this

@dyladan dyladan added the bug Something isn't working label Dec 6, 2021
@dyladan dyladan merged commit f51f853 into open-telemetry:main Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-grpc + nestjs grpc collision
4 participants