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

Add gRPC request metadata instrumentation #7011

Merged
merged 45 commits into from
Jan 18, 2023

Conversation

Tavh
Copy link
Contributor

@Tavh Tavh commented Oct 31, 2022

Solves. #6991

This PR implements the request portion of the new gRPC metadata instrumentation spec:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md#grpc-request-and-response-metadata

The changes include:

  • new CommonConfig entry for desired gRPC metadata values: 'otel.instrumentation.grpc.capture-metadata.request'
    (Similar to http headers)
  • setting the desired metadata values in GrpcTelemetry
  • new property in GrpcAttributesExtractor that holds a reference to the GrpcRpcAttributesGetter
  • new property in GrpcAttributesExtractor that stores the desired values so it can iterate them and extract each one from the request
  • inject the GrpcRpcAttributesGetter to GrpcAttributesExtractor (in GrpcTelemetryBuilder)
  • logic in GrpcRpcAttributesGetter to safely extract the gRPC metadata value
  • A new test in GrpcTest that makes sure that when a certain metadata key name is inserted, it also ends up in the span attributes

** Doesn't take care of the response because gRPC response is not implemented in java-instrumentation yet. (This is absolutely necessary but out of scope for this PR)
** "metadataValue" is only implemented inside GrpcRpcAttributesGetter and not in RpcAttributesGetter to avoid providing implementations for every RpcAttributesGetter in the repo as this PR only focuses on gRPC.

@Tavh Tavh requested a review from a team as a code owner October 31, 2022 15:29
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 31, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Tavh / name: Tav Herzlich (c6f544b)

@Tavh Tavh changed the title Added gRPC request instrumentation Add gRPC request instrumentation Oct 31, 2022
@Tavh Tavh changed the title Add gRPC request instrumentation Add gRPC request metadata instrumentation Oct 31, 2022
moved rpcRequestMetadata definition to GrpcSingletons
changed null to emptylist in GrpcRpcAttributesGetter
Added caching to GrpcAttributesExtractor
@mateuszrzeszutek mateuszrzeszutek linked an issue Nov 8, 2022 that may be closed by this pull request
Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

Left one more minor comment, but overall it looks good to me 👍
Thanks!

@Tavh
Copy link
Contributor Author

Tavh commented Nov 8, 2022

@mateuszrzeszutek
There seems to be a CI issue, trying to understand if it's even related to my changes, as I made a very small change and it started failing in an unrelated area

@mateuszrzeszutek
Copy link
Member

@mateuszrzeszutek There seems to be a CI issue, trying to understand if it's even related to my changes, as I made a very small change and it started failing in an unrelated area

No, it's related to our safety net mechanism (muzzle) and the latest reactor 3.5 release (which broke a few things, and removed a couple of methods). I'm currently working on a PR that fixes it.

@Override
public void onStart(
AttributesBuilder attributes, Context parentContext, GrpcRequest grpcRequest) {
// No request attributes
// Request attributes captured on request end.
Copy link
Member

Choose a reason for hiding this comment

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

is it possible to capture attributes on start so they can be used for sampling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trask Capture them only at start or at both start and end?

Copy link
Member

Choose a reason for hiding this comment

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

can they be different at those two times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trask Not sure what you mean by that

Copy link
Member

Choose a reason for hiding this comment

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

sorry, I mean, if you capture the request metadata in onStart, is there a reason to capture them in onEnd also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trask So do you think it should only be on start?

Copy link
Member

Choose a reason for hiding this comment

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

if we don't know of any reason to also be on end, then let's start with "only on start"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@trask
Status capture has to be on end because it doesn't exist at start.
I moved the metadata capture to start though

@trask
Copy link
Member

trask commented Nov 22, 2022

it's probably worth waiting to merge this for open-telemetry/opentelemetry-specification#2981

@trask
Copy link
Member

trask commented Nov 23, 2022

it's probably worth waiting to merge this for open-telemetry/opentelemetry-specification#2981

@Tavh this spec PR has been merged so you can go ahead and update the names to match 👍

@trask
Copy link
Member

trask commented Nov 28, 2022

hey @Tavh, I took a look at the latest CI failures, and it looks related to changing from onEnd to onStart.

It looks a bit tricky to capture them onStart, so I'd suggest switching back to onEnd, add we can open an issue to track this, so that it doesn't need to block your PR.

@trask trask added this to the v1.21.0 milestone Dec 8, 2022
@Tavh
Copy link
Contributor Author

Tavh commented Dec 11, 2022

@trask Took me a while to get back to this. I reverted the changes that moved the capture to requestStart

@trask
Copy link
Member

trask commented Dec 11, 2022

it's probably worth waiting to merge this for open-telemetry/opentelemetry-specification#2981

@Tavh this spec PR has been merged so you can go ahead and update the names to match 👍

@Tavh one last thing and we can merge this, thx!

@trask trask removed this from the v1.21.0 milestone Dec 12, 2022
@trask
Copy link
Member

trask commented Jan 12, 2023

ping @Tavh

@Tavh
Copy link
Contributor Author

Tavh commented Jan 13, 2023

@trask changed the naming according to the spec changes

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

thanks @Tavh 🎉

@trask trask merged commit b9c10c9 into open-telemetry:main Jan 18, 2023
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.

Implement gRPC request metadata
5 participants