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

Implement HTTP resend spec for OkHttp 3 #7652

Merged
merged 4 commits into from
May 16, 2023

Conversation

mateuszrzeszutek
Copy link
Member

Part of #5722

It's a draft because it unfortunately breaks the "connection error" scenarios. Establishing the connection in OkHttp happens before sending the HTTP request (duh), and the instrumentation reflects that - there's no HTTP client span around opening a connection.
Perhaps we should spec the "informal" CONNECT spans that we have in some of our instrumentations? This issue is bound to surface in other HTTP client instrumentations as well, and the telemetry around opening a connection is super useful in failure scenarios.

And, we have to rewrite all the resend/retry tests, but I've left that for another PR.

laurit pushed a commit that referenced this pull request Mar 7, 2023
Extracted from #7652 - I figured this'll be useful on its own in some of
the POCs/prototypes that we'll make
Comment on lines 80 to 84
if (emitEncompassingSpan) {
builder.interceptors().add(1, new EncompassingSpanInterceptor());
} else if (createSpanForConnectionErrors) {
builder.interceptors().add(1, new ConnectionErrorSpanInterceptor(instrumenter));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@trask @lmolkova I added two different ways of handling the connection stuff to this PR:

  • the first one is the wrapper span
  • the second one is a minor hack that only creates an HTTP span when there was an error thrown and no attempt to send an HTTP request was made - this way of handling things might not need any new spec (?)

Copy link
Member Author

Choose a reason for hiding this comment

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

There are some example traces for both of these in the OkHttp3Test class

@mateuszrzeszutek
Copy link
Member Author

mateuszrzeszutek commented Apr 7, 2023

This PR is now ready for review.
In case of connection-level errors, the OkHttp instrumentation will create a "fake" top-level span wrapping the whole operation. In any other case, it behaves according to the "low-level HTTP client instrumentation" description, and properly implements the resend spec.

Outstanding TODO items left for future PRs:

  • remove the retry tests in AbstractHttpClientTest and replace them by scenarios that are correct wrt the resend spec
  • add a test scenario that utilizes the tested HTTP client's authentication feature (if there's any; OkHttp has the Authenticator API) and performs HTTP basic auth exchange

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Nice, I didn't see anything too spicy. Interesting to see this spec start happening...

@@ -56,7 +47,7 @@ public OkHttpTelemetryBuilder addAttributesExtractor(
*/
@CanIgnoreReturnValue
public OkHttpTelemetryBuilder setCapturedRequestHeaders(List<String> requestHeaders) {
httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders);
this.capturedRequestHeaders = requestHeaders;
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary this?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: reassigning the reference allows the caller to later manipulate the list. It's silly/pedantic for a builder, I know, but prefer making the field final and just adding the to list. Could even rename to addCapturedRequestHeaders() if that's nicer (and avoids a clear/add race).

Same applies to response headers.

Copy link
Member Author

Choose a reason for hiding this comment

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

reassigning the reference allows the caller to later manipulate the list.

Great point! Will fix that, thanks

but prefer making the field final and just adding the to list. Could even rename to addCapturedRequestHeaders() if that's nicer (and avoids a clear/add race).

I think at some point we've decided to have a setter method (not an "adder") in all HTTP instrumentations, as it resulted in simpler API. We can revisit that discussion, but we'd have to do it for all HTTP instrumentations.

@mateuszrzeszutek
Copy link
Member Author

FYI @open-telemetry/java-instrumentation-approvers I'm planning to merge this PR this week

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.

🎉

@trask trask merged commit c21ec3f into open-telemetry:main May 16, 2023
@trask
Copy link
Member

trask commented May 16, 2023

(cc @lmolkova)

@mateuszrzeszutek mateuszrzeszutek deleted the http-retries branch May 16, 2023 06:02
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.

None yet

3 participants