-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Better qualify Java HttpClient instrumentation package name #13296
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44c6b64
Better qualify Java HttpClient package
trask 2e29209
spotless
trask 3e09baa
Add javadoc
trask 6a88add
Merge remote-tracking branch 'upstream/main' into javahttpclient
trask d449cd3
add migration note
trask 0bf8035
Merge remote-tracking branch 'upstream/main' into javahttpclient
trask de1cd18
Merge branch 'main' into javahttpclient
laurit 54ad46a
Merge remote-tracking branch 'upstream/main' into javahttpclient
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...rc/main/java/io/opentelemetry/instrumentation/javahttpclient/JavaHttpClientTelemetry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.javahttpclient; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
| import io.opentelemetry.instrumentation.javahttpclient.internal.HttpHeadersSetter; | ||
| import io.opentelemetry.instrumentation.javahttpclient.internal.OpenTelemetryHttpClient; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
|
|
||
| /** Entrypoint for instrumenting Java HTTP Client. */ | ||
| public final class JavaHttpClientTelemetry { | ||
|
|
||
| /** | ||
| * Returns a new {@link JavaHttpClientTelemetry} configured with the given {@link OpenTelemetry}. | ||
| */ | ||
| public static JavaHttpClientTelemetry create(OpenTelemetry openTelemetry) { | ||
| return builder(openTelemetry).build(); | ||
| } | ||
|
|
||
| public static JavaHttpClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { | ||
| return new JavaHttpClientTelemetryBuilder(openTelemetry); | ||
| } | ||
|
|
||
| private final Instrumenter<HttpRequest, HttpResponse<?>> instrumenter; | ||
| private final HttpHeadersSetter headersSetter; | ||
|
|
||
| JavaHttpClientTelemetry( | ||
| Instrumenter<HttpRequest, HttpResponse<?>> instrumenter, HttpHeadersSetter headersSetter) { | ||
| this.instrumenter = instrumenter; | ||
| this.headersSetter = headersSetter; | ||
| } | ||
|
|
||
| /** | ||
| * Construct a new OpenTelemetry tracing-enabled {@link HttpClient} using the provided {@link | ||
| * HttpClient} instance. | ||
| * | ||
| * @param client An instance of HttpClient configured as desired. | ||
| * @return a tracing-enabled {@link HttpClient}. | ||
| */ | ||
| public HttpClient newHttpClient(HttpClient client) { | ||
| return new OpenTelemetryHttpClient(client, instrumenter, headersSetter); | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
.../java/io/opentelemetry/instrumentation/javahttpclient/JavaHttpClientTelemetryBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.javahttpclient; | ||
|
|
||
| import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
| import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; | ||
| import io.opentelemetry.instrumentation.javahttpclient.internal.Experimental; | ||
| import io.opentelemetry.instrumentation.javahttpclient.internal.HttpHeadersSetter; | ||
| import io.opentelemetry.instrumentation.javahttpclient.internal.JavaHttpClientInstrumenterBuilderFactory; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
| import java.util.Collection; | ||
| import java.util.function.Function; | ||
|
|
||
| public final class JavaHttpClientTelemetryBuilder { | ||
|
|
||
| private final DefaultHttpClientInstrumenterBuilder<HttpRequest, HttpResponse<?>> builder; | ||
| private final OpenTelemetry openTelemetry; | ||
|
|
||
| static { | ||
| Experimental.internalSetEmitExperimentalTelemetry( | ||
| (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); | ||
| } | ||
|
|
||
| JavaHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { | ||
| builder = JavaHttpClientInstrumenterBuilderFactory.create(openTelemetry); | ||
| this.openTelemetry = openTelemetry; | ||
| } | ||
|
|
||
| /** | ||
| * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented | ||
| * items. The {@link AttributesExtractor} will be executed after all default extractors. | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JavaHttpClientTelemetryBuilder addAttributesExtractor( | ||
| AttributesExtractor<? super HttpRequest, ? super HttpResponse<?>> attributesExtractor) { | ||
| builder.addAttributesExtractor(attributesExtractor); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures the HTTP request headers that will be captured as span attributes. | ||
| * | ||
| * @param requestHeaders A list of HTTP header names. | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JavaHttpClientTelemetryBuilder setCapturedRequestHeaders( | ||
| Collection<String> requestHeaders) { | ||
| builder.setCapturedRequestHeaders(requestHeaders); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures the HTTP response headers that will be captured as span attributes. | ||
| * | ||
| * @param responseHeaders A list of HTTP header names. | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JavaHttpClientTelemetryBuilder setCapturedResponseHeaders( | ||
| Collection<String> responseHeaders) { | ||
| builder.setCapturedResponseHeaders(responseHeaders); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Configures the instrumentation to recognize an alternative set of HTTP request methods. | ||
| * | ||
| * <p>By default, this instrumentation defines "known" methods as the ones listed in <a | ||
| * href="https://www.rfc-editor.org/rfc/rfc9110.html#name-methods">RFC9110</a> and the PATCH | ||
| * method defined in <a href="https://www.rfc-editor.org/rfc/rfc5789.html">RFC5789</a>. | ||
| * | ||
| * <p>Note: calling this method <b>overrides</b> the default known method sets completely; it does | ||
| * not supplement it. | ||
| * | ||
| * @param knownMethods A set of recognized HTTP request methods. | ||
| * @see HttpClientAttributesExtractorBuilder#setKnownMethods(Collection) | ||
| */ | ||
| @CanIgnoreReturnValue | ||
| public JavaHttpClientTelemetryBuilder setKnownMethods(Collection<String> knownMethods) { | ||
| builder.setKnownMethods(knownMethods); | ||
| return this; | ||
| } | ||
|
|
||
| /** Sets custom {@link SpanNameExtractor} via transform function. */ | ||
| @CanIgnoreReturnValue | ||
| public JavaHttpClientTelemetryBuilder setSpanNameExtractor( | ||
| Function< | ||
| SpanNameExtractor<? super HttpRequest>, | ||
| ? extends SpanNameExtractor<? super HttpRequest>> | ||
| spanNameExtractorTransformer) { | ||
| builder.setSpanNameExtractor(spanNameExtractorTransformer); | ||
| return this; | ||
| } | ||
|
|
||
| public JavaHttpClientTelemetry build() { | ||
| return new JavaHttpClientTelemetry( | ||
| builder.build(), new HttpHeadersSetter(openTelemetry.getPropagators())); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../src/main/java/io/opentelemetry/instrumentation/javahttpclient/internal/Experimental.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.instrumentation.javahttpclient.internal; | ||
|
|
||
| import io.opentelemetry.instrumentation.javahttpclient.JavaHttpClientTelemetryBuilder; | ||
| import java.util.function.BiConsumer; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * This class is internal and experimental. Its APIs are unstable and can change at any time. Its | ||
| * APIs (or a version of them) may be promoted to the public stable API in the future, but no | ||
| * guarantees are made. | ||
| */ | ||
| public final class Experimental { | ||
|
|
||
| @Nullable | ||
| private static volatile BiConsumer<JavaHttpClientTelemetryBuilder, Boolean> | ||
| setEmitExperimentalTelemetry; | ||
|
|
||
| public static void setEmitExperimentalTelemetry( | ||
| JavaHttpClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { | ||
| if (setEmitExperimentalTelemetry != null) { | ||
| setEmitExperimentalTelemetry.accept(builder, emitExperimentalTelemetry); | ||
| } | ||
| } | ||
|
|
||
| public static void internalSetEmitExperimentalTelemetry( | ||
| BiConsumer<JavaHttpClientTelemetryBuilder, Boolean> setEmitExperimentalTelemetry) { | ||
| Experimental.setEmitExperimentalTelemetry = setEmitExperimentalTelemetry; | ||
| } | ||
|
|
||
| private Experimental() {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.