Skip to content
This repository was archived by the owner on Aug 8, 2026. It is now read-only.

Add x-client-trace-id Header to All Requests - #59

Merged
herinckc merged 2 commits into
mainfrom
herinckc/xClientTraceIdExample
Jun 26, 2024
Merged

herinckc merged 2 commits into
mainfrom
herinckc/xClientTraceIdExample

Conversation

@herinckc

Copy link
Copy Markdown
Contributor

This PR adds the x-client-trace-id header to all outbound requests. This should generate a unique value per RPC request even if the same gRPC stub is used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removing the x-client-trace-id from this class as it's now being populated elsewhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

based on what I saw in the official interceptor docs as well as this Java sample

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

based on what I saw in the official interceptor docs as well as this Java sample

super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener<>(responseListener) {
@Override
public void onClose(Status status, Metadata trailers) {
logger.info("request completed for xClientTraceId {} with status {}", xClientTraceId, status);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This differs slightly from the Java example (linked above), but the intention here is to basically just log the x-client-trace-id that was passed any time a request completes. This log line should be hit whether the request completes successfully or with an error. I'll include some sample output below

example log for a successful call:

request completed for xClientTraceId 8895e3a5-65d9-4428-bc1e-6e991838f164 with status Status{code=OK, description=null, cause=null}

example log for a failed call:

request completed for xClientTraceId eb62166d-5126-4b52-857b-ed73c2d3018e with status Status{code=UNAVAILABLE, description=RST_STREAM closed stream. HTTP/2 error code: NO_ERROR, cause=null}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice find. Curious, how did you generate the RST_STREAM error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used the Subscribe example to open a subscription then killed the backend server that was serving the subscription

@herinckc
herinckc merged commit 65c91a2 into main Jun 26, 2024
@herinckc
herinckc deleted the herinckc/xClientTraceIdExample branch June 26, 2024 15:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants