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 library instrumentation for java http client #8138

Merged
merged 4 commits into from
Apr 3, 2023

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Mar 25, 2023

Resolves #8069
The javaagent instrumentation also supports propagating context into BodyHandler implemented in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/BodyHandlerWrapper.java I think the initial idea behind it was that this allowed propagating context into callbacks. Because this didn't work for connectionErrorUnopenedPortWithCallback test later we also added wrapping completable future to take care of propagating context into callbacks. Should I also implement context propagation for BodyHandler in library instrumentation or should I just delete it? I guess it could come handy if someone builds a custom BodyHandler and wants to emit spans from there, though this doesn't feel too likely. I'd like deleting it more.

@laurit laurit requested a review from a team as a code owner March 25, 2023 12:26
import java.net.http.HttpResponse;

/** Entrypoint for instrumenting Java HTTP Client. */
public final class JavaHttpClientTelemetry {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I named the public api classes JavaHttpClient.. but some of the other classes still use JdkHttpClient.... I think we should choose how we want to call this and name all the classes in the same way.

Copy link
Member

Choose a reason for hiding this comment

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

+1 on renaming everything from Jdk* to Java*

@laurit laurit requested a review from jkwatson March 27, 2023 06:45
@mateuszrzeszutek
Copy link
Member

The javaagent instrumentation also supports propagating context into BodyHandler implemented in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpclient/BodyHandlerWrapper.java I think the initial idea behind it was that this allowed propagating context into callbacks. Because this didn't work for connectionErrorUnopenedPortWithCallback test later we also added wrapping completable future to take care of propagating context into callbacks. Should I also implement context propagation for BodyHandler in library instrumentation or should I just delete it? I guess it could come handy if someone builds a custom BodyHandler and wants to emit spans from there, though this doesn't feel too likely. I'd like deleting it more.

I think the BodyHandler context propagation is probably mildly useful; I'd be fine with adding it only when requested.

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.

Should I also implement context propagation for BodyHandler in library instrumentation or should I just delete it? I guess it could come handy if someone builds a custom BodyHandler and wants to emit spans from there, though this doesn't feel too likely. I'd like deleting it more.

it looks like we don't have any tests for custom BodyHandler? I'm fine deleting it and adding it if there's demand.

import java.net.http.HttpResponse;

/** Entrypoint for instrumenting Java HTTP Client. */
public final class JavaHttpClientTelemetry {
Copy link
Member

Choose a reason for hiding this comment

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

+1 on renaming everything from Jdk* to Java*

instrumentation/java-http-client/library/README.md Outdated Show resolved Hide resolved
public final class OpenTelemetryClient extends HttpClient {
private final HttpClient client;
private final Instrumenter<HttpRequest, HttpResponse<?>> instrumenter;
private final HttpHeadersSetter headersSetter;
Copy link
Member

Choose a reason for hiding this comment

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

maybe could delete HttpHeadersSetter, moving its one method to this class, and pass in ContextPropagators here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is better to keep it because javaagent instrumentation does not use OpenTelemetryClient, but uses HttpHeadersSetter

laurit and others added 2 commits April 3, 2023 12:32
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@trask trask merged commit 08236a7 into open-telemetry:main Apr 3, 2023
44 checks passed
@laurit laurit deleted the java-http-client-library branch July 6, 2023 17:48
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.

Provide library instrumentation for the java 11+ HttpClient
3 participants