From e03e83c190826c0ad257b884041808a1fca98d6b Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 8 Dec 2024 12:46:52 -0800 Subject: [PATCH] Split ratpack into client and server --- .../ratpack/v1_7/RatpackClientTelemetry.java | 62 ++++++++++ .../v1_7/RatpackClientTelemetryBuilder.java | 105 +++++++++++++++++ .../ratpack/v1_7/RatpackServerTelemetry.java | 80 +++++++++++++ .../v1_7/RatpackServerTelemetryBuilder.java | 107 ++++++++++++++++++ .../ratpack/v1_7/RatpackTelemetry.java | 50 +++++++- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 59 +++++++++- .../ratpack/v1_7/internal/Experimental.java | 86 ++++++++++++++ .../client/InstrumentedHttpClientTest.groovy | 39 ++++--- .../server/RatpackAsyncHttpServerTest.groovy | 10 +- .../server/RatpackForkedHttpServerTest.groovy | 10 +- .../v1_7/server/RatpackHttpServerTest.groovy | 10 +- .../v1_7/server/RatpackRoutesTest.groovy | 6 +- .../RatpackServerApplicationTest.groovy | 37 +++--- .../v1_7/server/RatpackServerTest.groovy | 10 +- .../ratpack/v1_7/RatpackHttpClientTest.java | 12 +- 15 files changed, 611 insertions(+), 72 deletions(-) create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetry.java create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetryBuilder.java create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetry.java create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetryBuilder.java create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/Experimental.java 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..e8300fdd4cd7 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetry.java @@ -0,0 +1,62 @@ +/* + * 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.OpenTelemetryHttpClient; +import ratpack.http.client.HttpClient; +import ratpack.http.client.HttpResponse; +import ratpack.http.client.RequestSpec; +import ratpack.registry.RegistrySpec; + +/** + * 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); + } + + /** Configures the {@link RegistrySpec} with OpenTelemetry. */ + public void configureRegistry(RegistrySpec registry) { + registry.add(OpenTelemetryExecInitializer.INSTANCE); + } +} 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..e3c96535154d --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackClientTelemetryBuilder.java @@ -0,0 +1,105 @@ +/* + * 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 clientBuilder; + + RatpackClientTelemetryBuilder(OpenTelemetry openTelemetry) { + clientBuilder = + RatpackClientInstrumenterBuilderFactory.create(INSTRUMENTATION_NAME, openTelemetry); + } + + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder addAttributeExtractor( + AttributesExtractor attributesExtractor) { + clientBuilder.addAttributeExtractor(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) { + clientBuilder.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) { + clientBuilder.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) { + clientBuilder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom client {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public RatpackClientTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + clientSpanNameExtractor) { + clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); + return this; + } + + /** + * Can be used via the unstable method {@link + * Experimental#setEmitExperimentalHttpClientMetrics(RatpackClientTelemetryBuilder, boolean)}. + */ + void setEmitExperimentalHttpClientMetrics(boolean emitExperimentalHttpClientMetrics) { + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + } + + /** Returns a new {@link RatpackClientTelemetry} with the configuration of this builder. */ + public RatpackClientTelemetry build() { + return new RatpackClientTelemetry(clientBuilder.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..988d3b140c4e --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetry.java @@ -0,0 +1,80 @@ +/* + * 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); + } +} 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..10532fba926e --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackServerTelemetryBuilder.java @@ -0,0 +1,107 @@ +/* + * 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 serverBuilder; + + RatpackServerTelemetryBuilder(OpenTelemetry openTelemetry) { + serverBuilder = + 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 addAttributeExtractor( + AttributesExtractor attributesExtractor) { + serverBuilder.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) { + serverBuilder.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) { + serverBuilder.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) { + serverBuilder.setKnownMethods(knownMethods); + return this; + } + + /** Sets custom server {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public RatpackServerTelemetryBuilder setSpanNameExtractor( + Function, ? extends SpanNameExtractor> + serverSpanNameExtractor) { + serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); + return this; + } + + /** + * Can be used via the unstable method {@link + * Experimental#setEmitExperimentalHttpServerMetrics(RatpackServerTelemetryBuilder, boolean)}. + */ + void setEmitExperimentalHttpServerMetrics(boolean emitExperimentalHttpServerMetrics) { + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + } + + /** Returns a new {@link RatpackServerTelemetry} with the configuration of this builder. */ + public RatpackServerTelemetry build() { + return new RatpackServerTelemetry(serverBuilder.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 1192a8d8d936..055efc794582 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#addAttributeExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -49,6 +60,11 @@ public RatpackTelemetryBuilder addAttributeExtractor( return this; } + /** + * @deprecated Use {@link + * RatpackClientTelemetryBuilder#addAttributeExtractor(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,11 @@ public RatpackTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalHttpClientMetrics(RatpackClientTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { @@ -139,7 +170,11 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalHttpServerMetrics(RatpackServerTelemetryBuilder, boolean)} + * instead. */ + @Deprecated @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { @@ -147,7 +182,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 +198,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 +212,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..b5900a6a0962 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/internal/Experimental.java @@ -0,0 +1,86 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7.internal; + +import static java.util.logging.Level.FINE; + +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackClientTelemetryBuilder; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackServerTelemetryBuilder; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +// TODO (trask) update the above javadoc similar to +// https://github.com/open-telemetry/opentelemetry-java/pull/6886 +public class Experimental { + + private static final Logger logger = Logger.getLogger(Experimental.class.getName()); + + @Nullable + private static final Method emitExperimentalHttpClientMetricsMethod = + getEmitExperimentalHttpClientMetricsMethod(); + + @Nullable + private static final Method emitExperimentalHttpServerMetricsMethod = + getEmitExperimentalHttpServerMetricsMethod(); + + public void setEmitExperimentalHttpClientMetrics( + RatpackClientTelemetryBuilder builder, boolean emitExperimentalHttpClientMetrics) { + + if (emitExperimentalHttpClientMetricsMethod != null) { + try { + emitExperimentalHttpClientMetricsMethod.invoke(builder, emitExperimentalHttpClientMetrics); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + public void setEmitExperimentalHttpServerMetrics( + RatpackServerTelemetryBuilder builder, boolean emitExperimentalHttpServerMetrics) { + + if (emitExperimentalHttpServerMetricsMethod != null) { + try { + emitExperimentalHttpServerMetricsMethod.invoke(builder, emitExperimentalHttpServerMetrics); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + + @Nullable + private static Method getEmitExperimentalHttpClientMetricsMethod() { + try { + Method method = + RatpackClientTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpClientMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } + + @Nullable + private static Method getEmitExperimentalHttpServerMetricsMethod() { + try { + Method method = + RatpackServerTelemetryBuilder.class.getDeclaredMethod( + "setEmitExperimentalHttpServerMetrics", boolean.class); + method.setAccessible(true); + return method; + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } +} 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..943ddd84adec 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,9 +35,7 @@ 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 { @@ -49,7 +48,8 @@ class InstrumentedHttpClientTest extends Specification { .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() @@ -60,7 +60,8 @@ class InstrumentedHttpClientTest extends Specification { def otherApp = EmbeddedApp.of { spec -> spec.registry( Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) } ) spec.handlers { @@ -71,8 +72,9 @@ 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()))) + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) } ) @@ -132,8 +134,9 @@ 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()))) + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) } ) @@ -197,8 +200,9 @@ class InstrumentedHttpClientTest extends Specification { def app = EmbeddedApp.of { spec -> spec.registry( Guice.registry { bindings -> - telemetry.configureServerRegistry(bindings) - bindings.bindInstance(HttpClient, telemetry.instrumentHttpClient( + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument( HttpClient.of { s -> s.readTimeout(Duration.ofMillis(10)) }) ) } @@ -254,8 +258,9 @@ 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()))) + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) bindings.bindInstance(new BarService(latch, "${otherApp.address}foo", openTelemetry)) }, ) @@ -287,8 +292,9 @@ 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()))) + serverTelemetry.configureRegistry(bindings) + telemetry.configureRegistry(bindings) + bindings.bindInstance(HttpClient, telemetry.instrument(HttpClient.of(Action.noop()))) bindings.bindInstance(new BarForkService(latch, "${otherApp.address}foo", openTelemetry)) }, ) @@ -341,7 +347,6 @@ class BarService implements Service { } } - class BarForkService implements Service { private final String url private final CountDownLatch latch diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.groovy index c391c85a5ec3..cc18bc735592 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackAsyncHttpServerTest.groovy @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.ratpack.v1_7.server 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.test.LibraryTestTrait import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint @@ -15,12 +15,12 @@ import ratpack.server.RatpackServerSpec class RatpackAsyncHttpServerTest extends AbstractRatpackAsyncHttpServerTest implements LibraryTestTrait { @Override void configure(RatpackServerSpec serverSpec) { - RatpackTelemetry telemetry = RatpackTelemetry.builder(openTelemetry) - .setCapturedServerRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) - .setCapturedServerResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) + RatpackServerTelemetry telemetry = RatpackServerTelemetry.builder(openTelemetry) + .setCapturedRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) + .setCapturedResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) .build() serverSpec.registryOf { - telemetry.configureServerRegistry(it) + telemetry.configureRegistry(it) } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.groovy index a5e5657074d3..1cf178ecec20 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackForkedHttpServerTest.groovy @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.ratpack.v1_7.server 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.test.LibraryTestTrait import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint @@ -15,12 +15,12 @@ import ratpack.server.RatpackServerSpec class RatpackForkedHttpServerTest extends AbstractRatpackForkedHttpServerTest implements LibraryTestTrait { @Override void configure(RatpackServerSpec serverSpec) { - RatpackTelemetry telemetry = RatpackTelemetry.builder(openTelemetry) - .setCapturedServerRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) - .setCapturedServerResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) + RatpackServerTelemetry telemetry = RatpackServerTelemetry.builder(openTelemetry) + .setCapturedRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) + .setCapturedResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) .build() serverSpec.registryOf { - telemetry.configureServerRegistry(it) + telemetry.configureRegistry(it) } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.groovy index 72f1a0f43189..7e07e86c9a8a 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerTest.groovy @@ -6,7 +6,7 @@ package io.opentelemetry.instrumentation.ratpack.v1_7.server 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.test.LibraryTestTrait import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint @@ -15,12 +15,12 @@ import ratpack.server.RatpackServerSpec class RatpackHttpServerTest extends AbstractRatpackHttpServerTest implements LibraryTestTrait { @Override void configure(RatpackServerSpec serverSpec) { - RatpackTelemetry telemetry = RatpackTelemetry.builder(openTelemetry) - .setCapturedServerRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) - .setCapturedServerResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) + RatpackServerTelemetry telemetry = RatpackServerTelemetry.builder(openTelemetry) + .setCapturedRequestHeaders([AbstractHttpServerTest.TEST_REQUEST_HEADER]) + .setCapturedResponseHeaders([AbstractHttpServerTest.TEST_RESPONSE_HEADER]) .build() serverSpec.registryOf { - telemetry.configureServerRegistry(it) + telemetry.configureRegistry(it) } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.groovy index 0d5004b71050..d4c3677f499a 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackRoutesTest.groovy @@ -6,16 +6,16 @@ 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.test.LibraryTestTrait import ratpack.server.RatpackServerSpec class RatpackRoutesTest extends AbstractRatpackRoutesTest implements LibraryTestTrait { @Override void configure(RatpackServerSpec serverSpec) { - RatpackTelemetry telemetry = RatpackTelemetry.create(openTelemetry) + RatpackServerTelemetry telemetry = RatpackServerTelemetry.create(openTelemetry) serverSpec.registryOf { - telemetry.configureServerRegistry(it) + telemetry.configureRegistry(it) } } 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/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)); } }