diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetry.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetry.java new file mode 100644 index 000000000000..e7c609d79520 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetry.java @@ -0,0 +1,55 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryHttpClient; +import ratpack.http.client.HttpClient; +import ratpack.http.client.HttpResponse; +import ratpack.http.client.RequestSpec; + +/** + * Entrypoint for instrumenting Ratpack http client. + * + *

To apply OpenTelemetry instrumentation to a http client, wrap the {@link HttpClient} using + * {@link #instrument(HttpClient)}. + * + *

{@code
+ * RatpackClientTelemetry telemetry = RatpackClientTelemetry.create(OpenTelemetrySdk.builder()
+ *   ...
+ *   .build());
+ * HttpClient instrumentedHttpClient = telemetry.instrument(httpClient);
+ * }
+ */ +public final class RatpackClientTelemetry { + + /** + * Returns a new {@link RatpackClientTelemetry} configured with the given {@link OpenTelemetry}. + */ + public static RatpackClientTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + /** + * Returns a new {@link RatpackClientTelemetryBuilder} configured with the given {@link + * OpenTelemetry}. + */ + public static RatpackClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new RatpackClientTelemetryBuilder(openTelemetry); + } + + private final OpenTelemetryHttpClient httpClientInstrumenter; + + RatpackClientTelemetry(Instrumenter clientInstrumenter) { + httpClientInstrumenter = new OpenTelemetryHttpClient(clientInstrumenter); + } + + /** Returns instrumented instance of {@link HttpClient} with OpenTelemetry. */ + public HttpClient instrument(HttpClient httpClient) throws Exception { + return httpClientInstrumenter.instrument(httpClient); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetryBuilder.java new file mode 100644 index 000000000000..f2f077b76fa0 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetryBuilder.java @@ -0,0 +1,101 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +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.ratpack.v1_7.internal.Experimental; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.RatpackClientInstrumenterBuilderFactory; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import ratpack.http.client.HttpResponse; +import ratpack.http.client.RequestSpec; + +/** A builder for {@link RatpackClientTelemetry}. */ +public final class RatpackClientTelemetryBuilder { + + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7"; + + private final DefaultHttpClientInstrumenterBuilder builder; + + static { + Experimental.setSetEmitExperimentalClientTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + } + + RatpackClientTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = RatpackClientInstrumenterBuilderFactory.create(INSTRUMENTATION_NAME, openTelemetry); + } + + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder addAttributesExtractor( + AttributesExtractor attributesExtractor) { + builder.addAttributesExtractor(attributesExtractor); + return this; + } + + /** + * Configures the HTTP client request headers that will be captured as span attributes. + * + * @param requestHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { + builder.setCapturedRequestHeaders(requestHeaders); + return this; + } + + /** + * Configures the HTTP client response headers that will be captured as span attributes. + * + * @param responseHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { + builder.setCapturedResponseHeaders(responseHeaders); + return this; + } + + /** + * Configures the instrumentation to recognize an alternative set of HTTP request methods. + * + *

By default, this instrumentation defines "known" methods as the ones listed in RFC9110 and the PATCH + * method defined in RFC5789. + * + *

Note: calling this method overrides the default known method sets completely; it does + * not supplement it. + * + * @param knownMethods A set of recognized HTTP request methods. + * @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set) + */ + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom client {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + clientSpanNameExtractor) { + builder.setSpanNameExtractor(clientSpanNameExtractor); + return this; + } + + /** Returns a new {@link RatpackClientTelemetry} with the configuration of this builder. */ + public RatpackClientTelemetry build() { + return new RatpackClientTelemetry(builder.build()); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetry.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetry.java new file mode 100644 index 000000000000..b4d56aa1b1ed --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetry.java @@ -0,0 +1,81 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryExecInitializer; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryExecInterceptor; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryServerHandler; +import ratpack.exec.ExecInitializer; +import ratpack.exec.ExecInterceptor; +import ratpack.handling.Handler; +import ratpack.handling.HandlerDecorator; +import ratpack.http.Request; +import ratpack.http.Response; +import ratpack.registry.RegistrySpec; + +/** + * Entrypoint for instrumenting Ratpack server. + * + *

To apply OpenTelemetry instrumentation to a server, configure the {@link RegistrySpec} using + * {@link #configureRegistry(RegistrySpec)}. + * + *

{@code
+ * RatpackServerTelemetry telemetry = RatpackServerTelemetry.create(OpenTelemetrySdk.builder()
+ *   ...
+ *   .build());
+ * RatpackServer.start(server -> {
+ *   server.registryOf(telemetry::configureRegistry);
+ *   server.handlers(chain -> ...);
+ * });
+ * }
+ */ +public final class RatpackServerTelemetry { + + /** + * Returns a new {@link RatpackServerTelemetry} configured with the given {@link OpenTelemetry}. + */ + public static RatpackServerTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + /** + * Returns a new {@link RatpackServerTelemetryBuilder} configured with the given {@link + * OpenTelemetry}. + */ + public static RatpackServerTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new RatpackServerTelemetryBuilder(openTelemetry); + } + + private final OpenTelemetryServerHandler serverHandler; + + RatpackServerTelemetry(Instrumenter serverInstrumenter) { + serverHandler = new OpenTelemetryServerHandler(serverInstrumenter); + } + + /** Returns a {@link Handler} to support Ratpack Registry binding. */ + public Handler getHandler() { + return serverHandler; + } + + /** Returns instance of {@link ExecInterceptor} to support Ratpack Registry binding. */ + public ExecInterceptor getExecInterceptor() { + return OpenTelemetryExecInterceptor.INSTANCE; + } + + /** Returns instance of {@link ExecInitializer} to support Ratpack Registry binding. */ + public ExecInitializer getExecInitializer() { + return OpenTelemetryExecInitializer.INSTANCE; + } + + /** Configures the {@link RegistrySpec} with OpenTelemetry. */ + public void configureRegistry(RegistrySpec registry) { + registry.add(HandlerDecorator.prepend(serverHandler)); + registry.add(OpenTelemetryExecInterceptor.INSTANCE); + registry.add(OpenTelemetryExecInitializer.INSTANCE); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetryBuilder.java new file mode 100644 index 000000000000..20cc6201af0b --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetryBuilder.java @@ -0,0 +1,103 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.Experimental; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.RatpackServerInstrumenterBuilderFactory; +import java.util.List; +import java.util.Set; +import java.util.function.Function; +import ratpack.http.Request; +import ratpack.http.Response; + +/** A builder for {@link RatpackServerTelemetry}. */ +public final class RatpackServerTelemetryBuilder { + + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7"; + + private final DefaultHttpServerInstrumenterBuilder builder; + + static { + Experimental.setSetEmitExperimentalServerTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); + } + + RatpackServerTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = RatpackServerInstrumenterBuilderFactory.create(INSTRUMENTATION_NAME, 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 RatpackServerTelemetryBuilder addAttributesExtractor( + AttributesExtractor attributesExtractor) { + builder.addAttributesExtractor(attributesExtractor); + return this; + } + + /** + * Configures the HTTP server request headers that will be captured as span attributes. + * + * @param requestHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public RatpackServerTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { + builder.setCapturedRequestHeaders(requestHeaders); + return this; + } + + /** + * Configures the HTTP server response headers that will be captured as span attributes. + * + * @param responseHeaders A list of HTTP header names. + */ + @CanIgnoreReturnValue + public RatpackServerTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { + builder.setCapturedResponseHeaders(responseHeaders); + return this; + } + + /** + * Configures the instrumentation to recognize an alternative set of HTTP request methods. + * + *

By default, this instrumentation defines "known" methods as the ones listed in RFC9110 and the PATCH + * method defined in RFC5789. + * + *

Note: calling this method overrides the default known method sets completely; it does + * not supplement it. + * + * @param knownMethods A set of recognized HTTP request methods. + * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Set) + */ + @CanIgnoreReturnValue + public RatpackServerTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom server {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public RatpackServerTelemetryBuilder setSpanNameExtractor( + Function, ? extends SpanNameExtractor> + serverSpanNameExtractor) { + builder.setSpanNameExtractor(serverSpanNameExtractor); + return this; + } + + /** Returns a new {@link RatpackServerTelemetry} with the configuration of this builder. */ + public RatpackServerTelemetry build() { + return new RatpackServerTelemetry(builder.build()); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetry.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetry.java index 95ea733c4fe7..f3ff0a4d82c0 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetry.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetry.java @@ -46,17 +46,30 @@ * .build()); * HttpClient instrumentedHttpClient = telemetry.instrumentHttpClient(httpClient); * } + * + * @deprecated Use {@link RatpackClientTelemetry} and {@link RatpackServerTelemetry} instead. */ +@Deprecated public final class RatpackTelemetry { - /** Returns a new {@link RatpackTelemetry} configured with the given {@link OpenTelemetry}. */ + /** + * Returns a new {@link RatpackTelemetry} configured with the given {@link OpenTelemetry}. + * + * @deprecated Use {@link RatpackClientTelemetry#create(OpenTelemetry)} and {@link + * RatpackServerTelemetry#create(OpenTelemetry)} instead. + */ + @Deprecated public static RatpackTelemetry create(OpenTelemetry openTelemetry) { return builder(openTelemetry).build(); } /** * Returns a new {@link RatpackTelemetryBuilder} configured with the given {@link OpenTelemetry}. + * + * @deprecated Use {@link RatpackClientTelemetry#builder(OpenTelemetry)} and {@link + * RatpackServerTelemetry#builder(OpenTelemetry)} instead. */ + @Deprecated public static RatpackTelemetryBuilder builder(OpenTelemetry openTelemetry) { return new RatpackTelemetryBuilder(openTelemetry); } @@ -71,29 +84,54 @@ public static RatpackTelemetryBuilder builder(OpenTelemetry openTelemetry) { httpClientInstrumenter = new OpenTelemetryHttpClient(clientInstrumenter); } - /** Returns instance of {@link OpenTelemetryServerHandler} to support Ratpack Registry binding. */ + /** + * Returns instance of {@link OpenTelemetryServerHandler} to support Ratpack Registry binding. + * + * @deprecated Use {@link RatpackServerTelemetry#getHandler()} instead. + */ + @Deprecated public OpenTelemetryServerHandler getOpenTelemetryServerHandler() { return serverHandler; } - /** Returns instance of {@link ExecInterceptor} to support Ratpack Registry binding. */ + /** + * Returns instance of {@link ExecInterceptor} to support Ratpack Registry binding. + * + * @deprecated Use {@link RatpackServerTelemetry#getExecInterceptor()} instead. + */ + @Deprecated public ExecInterceptor getOpenTelemetryExecInterceptor() { return OpenTelemetryExecInterceptor.INSTANCE; } - /** Returns instance of {@link ExecInitializer} to support Ratpack Registry binding. */ + /** + * Returns instance of {@link ExecInitializer} to support Ratpack Registry binding. + * + * @deprecated Use {@link RatpackServerTelemetry#getExecInitializer()} instead. + */ + @Deprecated public ExecInitializer getOpenTelemetryExecInitializer() { return OpenTelemetryExecInitializer.INSTANCE; } - /** Configures the {@link RegistrySpec} with OpenTelemetry. */ + /** + * Configures the {@link RegistrySpec} with OpenTelemetry. + * + * @deprecated Use {@link RatpackServerTelemetry#configureRegistry(RegistrySpec)} instead. + */ + @Deprecated public void configureServerRegistry(RegistrySpec registry) { registry.add(HandlerDecorator.prepend(serverHandler)); registry.add(OpenTelemetryExecInterceptor.INSTANCE); registry.add(OpenTelemetryExecInitializer.INSTANCE); } - /** Returns instrumented instance of {@link HttpClient} with OpenTelemetry. */ + /** + * Returns instrumented instance of {@link HttpClient} with OpenTelemetry. + * + * @deprecated Use {@link RatpackClientTelemetry#instrument(HttpClient)} instead. + */ + @Deprecated public HttpClient instrumentHttpClient(HttpClient httpClient) throws Exception { return httpClientInstrumenter.instrument(httpClient); } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 304bb943a31d..47f8aa063643 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.ratpack.v1_7.internal.Experimental; import io.opentelemetry.instrumentation.ratpack.v1_7.internal.RatpackClientInstrumenterBuilderFactory; import io.opentelemetry.instrumentation.ratpack.v1_7.internal.RatpackServerInstrumenterBuilderFactory; import java.util.List; @@ -23,7 +24,13 @@ import ratpack.http.client.HttpResponse; import ratpack.http.client.RequestSpec; -/** A builder for {@link RatpackTelemetry}. */ +/** + * A builder for {@link RatpackTelemetry}. + * + * @deprecated Use {@link RatpackClientTelemetryBuilder} and {@link RatpackServerTelemetryBuilder} + * instead. + */ +@Deprecated public final class RatpackTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7"; @@ -41,7 +48,11 @@ public final class RatpackTelemetryBuilder { /** * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented * items. The {@link AttributesExtractor} will be executed after all default extractors. + * + * @deprecated Use {@link + * RatpackServerTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -49,6 +60,11 @@ public RatpackTelemetryBuilder addAttributeExtractor( return this; } + /** + * @deprecated Use {@link + * RatpackClientTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} instead. + */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder addClientAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -60,7 +76,9 @@ public RatpackTelemetryBuilder addClientAttributeExtractor( * Configures the HTTP server request headers that will be captured as span attributes. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link RatpackServerTelemetryBuilder#setCapturedRequestHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedServerRequestHeaders(List requestHeaders) { serverBuilder.setCapturedRequestHeaders(requestHeaders); @@ -71,7 +89,9 @@ public RatpackTelemetryBuilder setCapturedServerRequestHeaders(List requ * Configures the HTTP server response headers that will be captured as span attributes. * * @param responseHeaders A list of HTTP header names. + * @deprecated Use {@link RatpackServerTelemetryBuilder#setCapturedResponseHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedServerResponseHeaders(List responseHeaders) { serverBuilder.setCapturedResponseHeaders(responseHeaders); @@ -82,7 +102,9 @@ public RatpackTelemetryBuilder setCapturedServerResponseHeaders(List res * Configures the HTTP client request headers that will be captured as span attributes. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link RatpackClientTelemetryBuilder#setCapturedRequestHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedClientRequestHeaders(List requestHeaders) { clientBuilder.setCapturedRequestHeaders(requestHeaders); @@ -93,7 +115,9 @@ public RatpackTelemetryBuilder setCapturedClientRequestHeaders(List requ * Configures the HTTP client response headers that will be captured as span attributes. * * @param responseHeaders A list of HTTP header names. + * @deprecated Use {@link RatpackClientTelemetryBuilder#setCapturedResponseHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedClientResponseHeaders(List responseHeaders) { clientBuilder.setCapturedResponseHeaders(responseHeaders); @@ -113,7 +137,10 @@ public RatpackTelemetryBuilder setCapturedClientResponseHeaders(List res * @param knownMethods A set of recognized HTTP request methods. * @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set) * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Set) + * @deprecated Use {@link RatpackServerTelemetryBuilder#setKnownMethods(Set)} and {@link + * RatpackClientTelemetryBuilder#setKnownMethods(Set)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setKnownMethods(Set knownMethods) { clientBuilder.setKnownMethods(knownMethods); @@ -126,7 +153,10 @@ public RatpackTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(RatpackClientTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { @@ -139,7 +169,10 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(RatpackServerTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { @@ -147,7 +180,12 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( return this; } - /** Sets custom client {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom client {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link RatpackClientTelemetryBuilder#setSpanNameExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setClientSpanNameExtractor( Function< @@ -158,7 +196,12 @@ public RatpackTelemetryBuilder setClientSpanNameExtractor( return this; } - /** Sets custom server {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom server {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link RatpackServerTelemetryBuilder#setSpanNameExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setServerSpanNameExtractor( Function, ? extends SpanNameExtractor> @@ -167,7 +210,13 @@ public RatpackTelemetryBuilder setServerSpanNameExtractor( return this; } - /** Returns a new {@link RatpackTelemetry} with the configuration of this builder. */ + /** + * Returns a new {@link RatpackTelemetry} with the configuration of this builder. + * + * @deprecated Use {@link RatpackClientTelemetryBuilder#build()} and {@link + * RatpackServerTelemetryBuilder#build()} instead. + */ + @Deprecated public RatpackTelemetry build() { return new RatpackTelemetry(serverBuilder.build(), clientBuilder.build()); } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/Experimental.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/Experimental.java new file mode 100644 index 000000000000..acddd6cd710c --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/Experimental.java @@ -0,0 +1,53 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7.internal; + +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackClientTelemetryBuilder; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetryBuilder; +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 + setEmitExperimentalClientTelemetry; + + @Nullable + private static volatile BiConsumer + setEmitExperimentalServerTelemetry; + + public static void setEmitExperimentalTelemetry( + RatpackClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + if (setEmitExperimentalClientTelemetry != null) { + setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); + } + } + + public static void setEmitExperimentalTelemetry( + RatpackServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + if (setEmitExperimentalServerTelemetry != null) { + setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); + } + } + + public static void setSetEmitExperimentalClientTelemetry( + BiConsumer setEmitExperimentalClientTelemetry) { + Experimental.setEmitExperimentalClientTelemetry = setEmitExperimentalClientTelemetry; + } + + public static void setSetEmitExperimentalServerTelemetry( + BiConsumer setEmitExperimentalServerTelemetry) { + Experimental.setEmitExperimentalServerTelemetry = setEmitExperimentalServerTelemetry; + } + + private Experimental() {} +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy index 7a6de6f3d980..bd4f7c1a57d4 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/client/InstrumentedHttpClientTest.groovy @@ -11,7 +11,8 @@ import io.opentelemetry.api.trace.Tracer import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator import io.opentelemetry.context.Context import io.opentelemetry.context.propagation.ContextPropagators -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackClientTelemetry +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry import io.opentelemetry.sdk.OpenTelemetrySdk import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter import io.opentelemetry.sdk.trace.SdkTracerProvider @@ -34,22 +35,21 @@ import java.util.concurrent.TimeUnit import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD -import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE -import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE +import static io.opentelemetry.semconv.HttpAttributes.* class InstrumentedHttpClientTest extends Specification { def spanExporter = InMemorySpanExporter.create() def tracerProvider = SdkTracerProvider.builder() - .addSpanProcessor(SimpleSpanProcessor.create(spanExporter)) - .build() + .addSpanProcessor(SimpleSpanProcessor.create(spanExporter)) + .build() def openTelemetry = OpenTelemetrySdk.builder() - .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) - .setTracerProvider(tracerProvider).build() + .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) + .setTracerProvider(tracerProvider).build() - RatpackTelemetry telemetry = RatpackTelemetry.create(openTelemetry) + RatpackClientTelemetry telemetry = RatpackClientTelemetry.create(openTelemetry) + RatpackServerTelemetry serverTelemetry = RatpackServerTelemetry.create(openTelemetry) def cleanup() { spanExporter.reset() @@ -59,9 +59,9 @@ class InstrumentedHttpClientTest extends Specification { expect: def otherApp = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - } + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + } ) spec.handlers { it.get("bar") { ctx -> ctx.render("foo") } @@ -70,17 +70,17 @@ class InstrumentedHttpClientTest extends Specification { def app = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient(HttpClient.of(Action.noop()))) - } + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) + } ) spec.handlers { chain -> chain.get("foo") { ctx -> HttpClient instrumentedHttpClient = ctx.get(HttpClient) instrumentedHttpClient.get(new URI("${otherApp.address}bar")) - .then { ctx.render("bar") } + .then { ctx.render("bar") } } } } @@ -131,10 +131,10 @@ class InstrumentedHttpClientTest extends Specification { def app = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient(HttpClient.of(Action.noop()))) - } + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) + } ) spec.handlers { chain -> @@ -189,27 +189,27 @@ class InstrumentedHttpClientTest extends Specification { spec.handlers { it.get("foo") { ctx -> Promise.value("bar").defer(Duration.ofSeconds(1L)) - .then { ctx.render("bar") } + .then { ctx.render("bar") } } } } def app = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient( - HttpClient.of { s -> s.readTimeout(Duration.ofMillis(10)) }) - ) - } + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument( + HttpClient.of { s -> s.readTimeout(Duration.ofMillis(10)) }) + ) + } ) spec.handlers { chain -> chain.get("path-name") { ctx -> def instrumentedHttpClient = ctx.get(HttpClient) instrumentedHttpClient.get(new URI("${otherApp.address}foo")) - .onError { ctx.render("error") } - .then { ctx.render("hello") } + .onError { ctx.render("error") } + .then { ctx.render("hello") } } } } @@ -253,11 +253,11 @@ class InstrumentedHttpClientTest extends Specification { def app = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient(HttpClient.of(Action.noop()))) - bindings.bindInstance(new BarService(latch, "${otherApp.address}foo", openTelemetry)) - }, + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) + bindings.bindInstance(new BarService(latch, "${otherApp.address}foo", openTelemetry)) + }, ) spec.handlers { chain -> chain.get("foo") { ctx -> ctx.render("bar") } @@ -286,11 +286,11 @@ class InstrumentedHttpClientTest extends Specification { def app = EmbeddedApp.of { spec -> spec.registry( - Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient(HttpClient.of(Action.noop()))) - bindings.bindInstance(new BarForkService(latch, "${otherApp.address}foo", openTelemetry)) - }, + Guice.registry { bindings -> + serverTelemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) + bindings.bindInstance(new BarForkService(latch, "${otherApp.address}foo", openTelemetry)) + }, ) spec.handlers { chain -> chain.get("foo") { ctx -> ctx.render("bar") } @@ -324,24 +324,23 @@ class BarService implements Service { void onStart(StartEvent event) { def parentContext = Context.current() def span = tracer.spanBuilder("a-span") - .setParent(parentContext) - .startSpan() + .setParent(parentContext) + .startSpan() Context otelContext = parentContext.with(span) otelContext.makeCurrent().withCloseable { Execution.current().add(Context, otelContext) def httpClient = event.registry.get(HttpClient) httpClient.get(new URI(url)) - .flatMap { httpClient.get(new URI(url)) } - .then { - span.end() - latch.countDown() - } + .flatMap { httpClient.get(new URI(url)) } + .then { + span.end() + latch.countDown() + } } } } - class BarForkService implements Service { private final String url private final CountDownLatch latch @@ -359,19 +358,19 @@ class BarForkService implements Service { Execution.fork().start { def parentContext = Context.current() def span = tracer.spanBuilder("a-span") - .setParent(parentContext) - .startSpan() + .setParent(parentContext) + .startSpan() Context otelContext = parentContext.with(span) otelContext.makeCurrent().withCloseable { Execution.current().add(Context, otelContext) def httpClient = event.registry.get(HttpClient) httpClient.get(new URI(url)) - .flatMap { httpClient.get(new URI(url)) } - .then { - span.end() - latch.countDown() - } + .flatMap { httpClient.get(new URI(url)) } + .then { + span.end() + latch.countDown() + } } } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy index 3e0ed088f401..d2ca21755a9c 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.groovy @@ -10,9 +10,9 @@ import com.google.inject.Provides import groovy.transform.CompileStatic import io.opentelemetry.api.OpenTelemetry import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryServerHandler +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackClientTelemetry import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackFunctionalTest -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry import io.opentelemetry.sdk.OpenTelemetrySdk import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter import io.opentelemetry.sdk.trace.SdkTracerProvider @@ -21,6 +21,7 @@ import io.opentelemetry.sdk.trace.export.SpanExporter import ratpack.exec.ExecInitializer import ratpack.exec.ExecInterceptor import ratpack.guice.Guice +import ratpack.handling.Handler import ratpack.http.client.HttpClient import ratpack.server.RatpackServer import spock.lang.Specification @@ -28,9 +29,7 @@ import spock.util.concurrent.PollingConditions import javax.inject.Singleton -import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD -import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE -import static io.opentelemetry.semconv.HttpAttributes.HTTP_ROUTE +import static io.opentelemetry.semconv.HttpAttributes.* import static io.opentelemetry.semconv.UrlAttributes.URL_PATH class RatpackServerApplicationTest extends Specification { @@ -104,20 +103,26 @@ class OpenTelemetryModule extends AbstractModule { @Singleton @Provides - RatpackTelemetry ratpackTracing(OpenTelemetry openTelemetry) { - return RatpackTelemetry.create(openTelemetry) + RatpackClientTelemetry ratpackClientTelemetry(OpenTelemetry openTelemetry) { + return RatpackClientTelemetry.create(openTelemetry) } @Singleton @Provides - OpenTelemetryServerHandler ratpackServerHandler(RatpackTelemetry ratpackTracing) { - return ratpackTracing.getOpenTelemetryServerHandler() + RatpackServerTelemetry ratpackServerTelemetry(OpenTelemetry openTelemetry) { + return RatpackServerTelemetry.create(openTelemetry) } @Singleton @Provides - ExecInterceptor ratpackExecInterceptor(RatpackTelemetry ratpackTracing) { - return ratpackTracing.getOpenTelemetryExecInterceptor() + Handler ratpackServerHandler(RatpackServerTelemetry ratpackTracing) { + return ratpackTracing.getHandler() + } + + @Singleton + @Provides + ExecInterceptor ratpackExecInterceptor(RatpackServerTelemetry ratpackTracing) { + return ratpackTracing.getExecInterceptor() } @Provides @@ -131,14 +136,14 @@ class OpenTelemetryModule extends AbstractModule { @Singleton @Provides - HttpClient instrumentedHttpClient(RatpackTelemetry ratpackTracing) { - return ratpackTracing.instrumentHttpClient(HttpClient.of {}) + HttpClient instrumentedHttpClient(RatpackClientTelemetry ratpackTracing) { + return ratpackTracing.instrument(HttpClient.of {}) } @Singleton @Provides - ExecInitializer ratpackExecInitializer(RatpackTelemetry ratpackTracing) { - return ratpackTracing.getOpenTelemetryExecInitializer() + ExecInitializer ratpackExecInitializer(RatpackServerTelemetry ratpackTracing) { + return ratpackTracing.getExecInitializer() } } @@ -152,7 +157,7 @@ class RatpackApp { .handlers { chain -> chain .get("ignore") { ctx -> ctx.render("ignored") } - .all(OpenTelemetryServerHandler) + .all(Handler) .get("foo") { ctx -> ctx.render("hi-foo") } .get("bar") { ctx -> ctx.get(HttpClient).get(ctx.get(URI)) diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy index f04d97f458ee..19cb6d22e5ac 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.groovy @@ -8,7 +8,7 @@ package io.opentelemetry.instrumentation.ratpack.v1_7.server import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator import io.opentelemetry.context.propagation.ContextPropagators -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry import io.opentelemetry.sdk.OpenTelemetrySdk import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter import io.opentelemetry.sdk.trace.SdkTracerProvider @@ -32,7 +32,7 @@ class RatpackServerTest extends Specification { .setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance())) .setTracerProvider(tracerProvider).build() - def telemetry = RatpackTelemetry.create(openTelemetry) + def telemetry = RatpackServerTelemetry.create(openTelemetry) def cleanup() { spanExporter.reset() @@ -41,7 +41,7 @@ class RatpackServerTest extends Specification { def "add span on handlers"() { given: def app = EmbeddedApp.of { spec -> - spec.registry { Registry.of { telemetry.configureServerRegistry(it) } } + spec.registry { Registry.of { telemetry.configureRegistry(it) } } spec.handlers { chain -> chain.get("foo") { ctx -> ctx.render("hi-foo") } } @@ -67,7 +67,7 @@ class RatpackServerTest extends Specification { def "propagate trace with instrumented async operations"() { expect: def app = EmbeddedApp.of { spec -> - spec.registry { Registry.of { telemetry.configureServerRegistry(it) } } + spec.registry { Registry.of { telemetry.configureRegistry(it) } } spec.handlers { chain -> chain.get("foo") { ctx -> ctx.render("hi-foo") @@ -106,7 +106,7 @@ class RatpackServerTest extends Specification { def "propagate trace with instrumented async concurrent operations"() { expect: def app = EmbeddedApp.of { spec -> - spec.registry { Registry.of { telemetry.configureServerRegistry(it) } } + spec.registry { Registry.of { telemetry.configureRegistry(it) } } spec.handlers { chain -> chain.get("bar") { ctx -> ctx.render("hi-bar") diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java new file mode 100644 index 000000000000..dff44ee98fb8 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java @@ -0,0 +1,39 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import java.util.Collections; +import org.junit.jupiter.api.extension.RegisterExtension; +import ratpack.func.Action; +import ratpack.http.client.HttpClient; +import ratpack.http.client.HttpClientSpec; + +@SuppressWarnings("deprecation") // testing deprecated API +class RatpackHttpClientOldTest extends AbstractRatpackHttpClientTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary(); + + @Override + protected HttpClient buildHttpClient() throws Exception { + return RatpackTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedClientRequestHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) + .setCapturedClientResponseHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) + .build() + .instrumentHttpClient(HttpClient.of(Action.noop())); + } + + @Override + protected HttpClient buildHttpClient(Action action) throws Exception { + return RatpackClientTelemetry.create(testing.getOpenTelemetry()) + .instrument(HttpClient.of(action)); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientTest.java index 49ceb3e976e2..b993de02489b 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientTest.java @@ -21,18 +21,18 @@ class RatpackHttpClientTest extends AbstractRatpackHttpClientTest { @Override protected HttpClient buildHttpClient() throws Exception { - return RatpackTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedClientRequestHeaders( + return RatpackClientTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) - .setCapturedClientResponseHeaders( + .setCapturedResponseHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) .build() - .instrumentHttpClient(HttpClient.of(Action.noop())); + .instrument(HttpClient.of(Action.noop())); } @Override protected HttpClient buildHttpClient(Action action) throws Exception { - return RatpackTelemetry.create(testing.getOpenTelemetry()) - .instrumentHttpClient(HttpClient.of(action)); + return RatpackClientTelemetry.create(testing.getOpenTelemetry()) + .instrument(HttpClient.of(action)); } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.java index ae496f03b4e1..3a9e38b2c56a 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.java @@ -8,7 +8,7 @@ import static java.util.Collections.singletonList; import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackAsyncHttpServerTest; -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -24,14 +24,12 @@ class RatpackAsyncHttpServerTest extends AbstractRatpackAsyncHttpServerTest { @Override protected void configure(RatpackServerSpec serverSpec) throws Exception { - RatpackTelemetry telemetry = - RatpackTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedServerRequestHeaders( - singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedServerResponseHeaders( - singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + RatpackServerTelemetry telemetry = + RatpackServerTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build(); - serverSpec.registryOf(telemetry::configureServerRegistry); + serverSpec.registryOf(telemetry::configureRegistry); } @Override diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.java index 0c18d081cd07..5165dd3e4af0 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.java @@ -8,7 +8,7 @@ import static java.util.Collections.singletonList; import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackForkedHttpServerTest; -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -24,14 +24,12 @@ class RatpackForkedHttpServerTest extends AbstractRatpackForkedHttpServerTest { @Override protected void configure(RatpackServerSpec serverSpec) throws Exception { - RatpackTelemetry telemetry = - RatpackTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedServerRequestHeaders( - singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedServerResponseHeaders( - singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + RatpackServerTelemetry telemetry = + RatpackServerTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build(); - serverSpec.registryOf(telemetry::configureServerRegistry); + serverSpec.registryOf(telemetry::configureRegistry); } @Override diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java new file mode 100644 index 000000000000..3fda1eaa1efb --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7.server; + +import static java.util.Collections.singletonList; + +import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import org.junit.jupiter.api.extension.RegisterExtension; +import ratpack.server.RatpackServerSpec; + +@SuppressWarnings("deprecation") // testing deprecated API +class RatpackHttpServerOldTest extends AbstractRatpackHttpServerTest { + + @RegisterExtension + public static final InstrumentationExtension testing = + HttpServerInstrumentationExtension.forLibrary(); + + @Override + protected void configure(RatpackServerSpec serverSpec) throws Exception { + io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry telemetry = + io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry.builder( + testing.getOpenTelemetry()) + .setCapturedServerRequestHeaders( + singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedServerResponseHeaders( + singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + .build(); + serverSpec.registryOf(telemetry::configureServerRegistry); + } + + @Override + protected void configure(HttpServerTestOptions options) { + super.configure(options); + + options.setHasHandlerSpan(endpoint -> false); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.java index 1a00d239d28f..ddc615054a51 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.java @@ -8,7 +8,7 @@ import static java.util.Collections.singletonList; import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackHttpServerTest; -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; @@ -24,14 +24,12 @@ class RatpackHttpServerTest extends AbstractRatpackHttpServerTest { @Override protected void configure(RatpackServerSpec serverSpec) throws Exception { - RatpackTelemetry telemetry = - RatpackTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedServerRequestHeaders( - singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedServerResponseHeaders( - singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + RatpackServerTelemetry telemetry = + RatpackServerTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build(); - serverSpec.registryOf(telemetry::configureServerRegistry); + serverSpec.registryOf(telemetry::configureRegistry); } @Override diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.java index 8a1edc9993e8..742a2693a048 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.java @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.ratpack.v1_7.server; import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackRoutesTest; -import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetry; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; import org.junit.jupiter.api.extension.RegisterExtension; @@ -24,8 +24,8 @@ protected InstrumentationExtension testing() { @Override protected void configure(RatpackServerSpec serverSpec) throws Exception { - RatpackTelemetry telemetry = RatpackTelemetry.create(testing.getOpenTelemetry()); - serverSpec.registryOf(telemetry::configureServerRegistry); + RatpackServerTelemetry telemetry = RatpackServerTelemetry.create(testing.getOpenTelemetry()); + serverSpec.registryOf(telemetry::configureRegistry); } @Override