Skip to content

Implement HTTP resend spec for OkHttp 3#7652

Merged
trask merged 4 commits into
open-telemetry:mainfrom
mateuszrzeszutek:http-retries
May 16, 2023
Merged

Implement HTTP resend spec for OkHttp 3#7652
trask merged 4 commits into
open-telemetry:mainfrom
mateuszrzeszutek:http-retries

Conversation

@mateuszrzeszutek

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

mateuszrzeszutek commented Apr 7, 2023

Copy link
Copy Markdown
Member Author

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

@breedx-splk breedx-splk left a comment

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, I didn't see anything too spicy. Interesting to see this spec start happening...

@CanIgnoreReturnValue
public OkHttpTelemetryBuilder setCapturedRequestHeaders(List<String> requestHeaders) {
httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders);
this.capturedRequestHeaders = requestHeaders;

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.

unnecessary this?

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.

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
Copy Markdown
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
Copy Markdown
Member Author

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

@trask trask left a comment

Copy link
Copy Markdown
Member

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

trask commented May 16, 2023

Copy link
Copy Markdown
Member

(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.

3 participants