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(instrumentation-grpc): instrument @grpc/grpc-js Client methods #3804

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented May 15, 2023

Which problem is this PR solving?

Traces when using the @openfeature/flagd-provider are not connected as the @grpc/grpc-js Client methods used by @protobuf-ts/grpc-transport are not instrumented, (see instance creation, makeUnaryRequest, makeServerStreamRequest, makeClientStreamRequest, makeBidiStreamRequest) .

This was presumably not added initially as the Client class is only used via its prototype in clients generated by makeGenericClientConstructor()/makeClientConstructor(), which means that patching the methods on the Client class would not cause the patched method ever to be used.

Because clients generated by makeGenericClientConstructor()/makeClientConstructor() do not use the patched methods, it is possible to add instrumentation to those methods and not affect telemetry generated by the existing instrumentation code. This PR patches these un-instrumented client methods to provide context propagation and telemetry generation when the Client is used directly.

Fixes #3775

Short description of the changes

Adds instrumentation for the client methods

  • makeUnaryRequest
  • makeClientStreamRequest
  • makeServerStreamRequest
  • makeBidiStreamRequest

Type of change

I'm unsure whether to categorize this as a bugfix or a new feature. The Client class in @grpc/grpc-js is public, therefore I think it is entirely possible that people would use the class directly, as is the case in @protobuf-ts/grpc-transport

  • Bug fix (non-breaking change which fixes an issue)
  • New feature? (non-breaking change which adds functionality)

How Has This Been Tested?

  • Added test cases based on the existing client tests for @grpc/grpc-js
  • Manual testing using the @openfeature/flagd-provider

Checklist:

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

@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Merging #3804 (0753de5) into main (1a7488e) will increase coverage by 0.03%.
The diff coverage is 92.72%.

❗ Current head 0753de5 differs from pull request most recent head 6ae9ec9. Consider uploading reports for the commit 6ae9ec9 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3804      +/-   ##
==========================================
+ Coverage   92.31%   92.35%   +0.03%     
==========================================
  Files         321      321              
  Lines        9189     9249      +60     
  Branches     1953     1962       +9     
==========================================
+ Hits         8483     8542      +59     
- Misses        706      707       +1     
Files Changed Coverage Δ
...elemetry-instrumentation-grpc/src/grpc-js/index.ts 92.04% <91.52%> (-0.64%) ⬇️
...ry-instrumentation-grpc/src/grpc-js/clientUtils.ts 96.70% <94.11%> (+3.84%) ⬆️

... and 1 file with indirect coverage changes

@pichlermarc pichlermarc marked this pull request as ready for review May 24, 2023 15:43
@pichlermarc pichlermarc requested a review from a team May 24, 2023 15:43
@darren-west
Copy link

Anything blocking getting this merged? Ive run into this issue also

@pichlermarc
Copy link
Member Author

Anything blocking getting this merged? Ive run into this issue also

Currently, this is just missing reviews from @open-telemetry/javascript-approvers - we'll need to get at least one green check to merge, though I'd like to have at least two as this is quite a significant change. I don't know if the original authors of this instrumentation are still around, which further complicates the process.

Copy link
Member

@Flarna Flarna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments but as I'm not an grpc expert may review doesn't cover all these inner grpc details.

@pichlermarc
Copy link
Member Author

Sorry for the force-push - I must've messed up my history somewhere and there were too many commits to figure out where it went wrong. 😞

Copy link
Member Author

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Flarna, thank you for the review; it has been extremely helpful as I'm not as familiar with writing instrumentations as I'd like to be - I made some quite substantial changes since the last review based on your suggestions. 🙂

I added a few questions to your comments - mostly regarding modifying the pre-existing code that I moved to helper functions.

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really large change and I'm also not a grpc expert but it looks ok to me

@beeme1mr
Copy link

Hey @pichlermarc, would it be possible to merge this soon?

@pichlermarc
Copy link
Member Author

Hey @pichlermarc, would it be possible to merge this soon?

Yes, sorry @beeme1mr, I was out for a while and did not notice we already have enough approvals now. Failing EOL tests are unrelated (see #4030)

@pichlermarc
Copy link
Member Author

pichlermarc commented Jul 31, 2023

/easycla

Edit: looks like easycla is broken right now. communitybridge/easycla#4071, we'll have to wait until it's back.

@pichlermarc pichlermarc merged commit 87fff2e into open-telemetry:main Aug 1, 2023
14 checks passed
@pichlermarc pichlermarc deleted the fix/instrument-grpc-client branch August 1, 2023 14:12
@mydea
Copy link
Contributor

mydea commented Aug 10, 2023

I think this lead to #4053 (but not sure, just digging around a bit)!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disconnected traces when using @opentelemetry/instrumentation-grpc with @openfeature/flagd-provider
7 participants