From 71e277c0d0dfc03d23edca64e34dd5548b93f805 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Sun, 8 Dec 2024 08:17:55 -0800 Subject: [PATCH] Split ArmeriaTelemetry into client and server --- .../armeria/v1_3/ArmeriaSingletons.java | 28 +++- .../armeria/v1_3/ArmeriaClientTelemetry.java | 42 +++++ .../v1_3/ArmeriaClientTelemetryBuilder.java | 149 ++++++++++++++++++ .../armeria/v1_3/ArmeriaServerTelemetry.java | 42 +++++ .../v1_3/ArmeriaServerTelemetryBuilder.java | 136 ++++++++++++++++ .../armeria/v1_3/ArmeriaTelemetry.java | 13 +- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 86 +++++++--- .../ArmeriaInstrumenterBuilderUtil.java | 15 +- .../armeria/v1_3/internal/Experimental.java | 34 +++- .../armeria/v1_3/ArmeriaHttpClientTest.java | 8 +- .../armeria/v1_3/ArmeriaHttpServerTest.java | 8 +- 11 files changed, 507 insertions(+), 54 deletions(-) create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetry.java create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.java create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetry.java create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.java diff --git a/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java b/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java index 4845c528e7e1..8d1fe03762ea 100644 --- a/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java +++ b/instrumentation/armeria/armeria-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/armeria/v1_3/ArmeriaSingletons.java @@ -9,8 +9,10 @@ import com.linecorp.armeria.server.HttpService; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; -import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetry; -import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaClientTelemetry; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaClientTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaServerTelemetry; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaServerTelemetryBuilder; import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import java.util.function.Function; @@ -23,15 +25,25 @@ public final class ArmeriaSingletons { public static final Function SERVER_DECORATOR; static { - ArmeriaTelemetryBuilder builder = ArmeriaTelemetry.builder(GlobalOpenTelemetry.get()); CommonConfig config = AgentCommonConfig.get(); - ArmeriaInstrumenterBuilderUtil.getClientBuilderExtractor().apply(builder).configure(config); - ArmeriaInstrumenterBuilderUtil.getServerBuilderExtractor().apply(builder).configure(config); - ArmeriaTelemetry telemetry = builder.build(); - CLIENT_DECORATOR = telemetry.newClientDecorator(); + ArmeriaClientTelemetryBuilder clientBuilder = + ArmeriaClientTelemetry.builder(GlobalOpenTelemetry.get()); + ArmeriaInstrumenterBuilderUtil.getClientBuilderExtractor() + .apply(clientBuilder) + .configure(config); + ArmeriaClientTelemetry clientTelemetry = clientBuilder.build(); + + ArmeriaServerTelemetryBuilder serverBuilder = + ArmeriaServerTelemetry.builder(GlobalOpenTelemetry.get()); + ArmeriaInstrumenterBuilderUtil.getServerBuilderExtractor() + .apply(serverBuilder) + .configure(config); + ArmeriaServerTelemetry serverTelemetry = serverBuilder.build(); + + CLIENT_DECORATOR = clientTelemetry.newDecorator(); Function libraryDecorator = - telemetry.newServiceDecorator().compose(ResponseCustomizingDecorator::new); + serverTelemetry.newDecorator().compose(ResponseCustomizingDecorator::new); SERVER_DECORATOR = service -> new ServerDecorator(service, libraryDecorator.apply(service)); } diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetry.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetry.java new file mode 100644 index 000000000000..b6da6cb0a8be --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetry.java @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.client.HttpClient; +import com.linecorp.armeria.common.logging.RequestLog; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import java.util.function.Function; + +/** Entrypoint for instrumenting Armeria clients. */ +public final class ArmeriaClientTelemetry { + + /** + * Returns a new {@link ArmeriaClientTelemetry} configured with the given {@link OpenTelemetry}. + */ + public static ArmeriaClientTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + public static ArmeriaClientTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new ArmeriaClientTelemetryBuilder(openTelemetry); + } + + private final Instrumenter instrumenter; + + ArmeriaClientTelemetry(Instrumenter instrumenter) { + this.instrumenter = instrumenter; + } + + /** + * Returns a new {@link HttpClient} decorator for use with methods like {@link + * com.linecorp.armeria.client.ClientBuilder#decorator(Function)}. + */ + public Function newDecorator() { + return client -> new OpenTelemetryClient(client, instrumenter); + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.java new file mode 100644 index 000000000000..b2a6c75cf622 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.java @@ -0,0 +1,149 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.common.logging.RequestLog; +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.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.Experimental; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +public final class ArmeriaClientTelemetryBuilder { + + private final DefaultHttpClientInstrumenterBuilder builder; + + static { + ArmeriaInstrumenterBuilderUtil.setClientBuilderExtractor( + ArmeriaClientTelemetryBuilder::getBuilder); + } + + ArmeriaClientTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); + } + + /** Sets the status extractor for client spans. */ + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder setStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + builder.setStatusExtractor(statusExtractor); + return this; + } + + /** + * Adds an extra client-only {@link AttributesExtractor} to invoke to set attributes to + * instrumented items. The {@link AttributesExtractor} will be executed after all default + * extractors. + */ + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder addAttributeExtractor( + AttributesExtractor attributesExtractor) { + builder.addAttributeExtractor(attributesExtractor); + return this; + } + + /** + * Sets the {@code peer.service} attribute for http client spans. + * + * @deprecated Use {@link Experimental#setClientPeerService(ArmeriaClientTelemetryBuilder, + * String)} instead. + */ + @Deprecated + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder setPeerService(String peerService) { + builder.setPeerService(peerService); + 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 ArmeriaClientTelemetryBuilder 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 ArmeriaClientTelemetryBuilder 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 ArmeriaClientTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** + * Configures the instrumentation to emit experimental HTTP client metrics. + * + * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics + * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalHttpClientMetrics(ArmeriaClientTelemetryBuilder, boolean)} + * instead. + */ + @Deprecated + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( + boolean emitExperimentalHttpClientMetrics) { + builder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + return this; + } + + /** Sets custom client {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + clientSpanNameExtractor) { + builder.setSpanNameExtractor(clientSpanNameExtractor); + return this; + } + + public ArmeriaClientTelemetry build() { + return new ArmeriaClientTelemetry(builder.build()); + } + + private DefaultHttpClientInstrumenterBuilder getBuilder() { + return builder; + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetry.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetry.java new file mode 100644 index 000000000000..827610367620 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetry.java @@ -0,0 +1,42 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.linecorp.armeria.common.logging.RequestLog; +import com.linecorp.armeria.server.HttpService; +import com.linecorp.armeria.server.ServiceRequestContext; +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import java.util.function.Function; + +/** Entrypoint for instrumenting Armeria services. */ +public final class ArmeriaServerTelemetry { + + /** + * Returns a new {@link ArmeriaServerTelemetry} configured with the given {@link OpenTelemetry}. + */ + public static ArmeriaServerTelemetry create(OpenTelemetry openTelemetry) { + return builder(openTelemetry).build(); + } + + public static ArmeriaServerTelemetryBuilder builder(OpenTelemetry openTelemetry) { + return new ArmeriaServerTelemetryBuilder(openTelemetry); + } + + private final Instrumenter instrumenter; + + ArmeriaServerTelemetry(Instrumenter instrumenter) { + this.instrumenter = instrumenter; + } + + /** + * Returns a new {@link HttpService} decorator for use with methods like {@link + * HttpService#decorate(Function)}. + */ + public Function newDecorator() { + return service -> new OpenTelemetryService(service, instrumenter); + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.java new file mode 100644 index 000000000000..02f1a5624114 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.java @@ -0,0 +1,136 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.google.errorprone.annotations.CanIgnoreReturnValue; +import com.linecorp.armeria.common.logging.RequestLog; +import com.linecorp.armeria.server.ServiceRequestContext; +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.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.Experimental; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +public final class ArmeriaServerTelemetryBuilder { + + private final DefaultHttpServerInstrumenterBuilder builder; + + static { + ArmeriaInstrumenterBuilderUtil.setServerBuilderExtractor( + ArmeriaServerTelemetryBuilder::getBuilder); + } + + ArmeriaServerTelemetryBuilder(OpenTelemetry openTelemetry) { + builder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); + } + + /** Sets the status extractor for server spans. */ + @CanIgnoreReturnValue + public ArmeriaServerTelemetryBuilder setStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + builder.setStatusExtractor(statusExtractor); + return this; + } + + /** + * Adds an extra server-only {@link AttributesExtractor} to invoke to set attributes to + * instrumented items. The {@link AttributesExtractor} will be executed after all default + * extractors. + */ + @CanIgnoreReturnValue + public ArmeriaServerTelemetryBuilder addAttributeExtractor( + 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 ArmeriaServerTelemetryBuilder 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 ArmeriaServerTelemetryBuilder 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 ArmeriaServerTelemetryBuilder setKnownMethods(Set knownMethods) { + builder.setKnownMethods(knownMethods); + return this; + } + + /** + * Configures the instrumentation to emit experimental HTTP server metrics. + * + * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics + * are to be emitted. + * @deprecated Use {@link + * Experimental#setEmitExperimentalHttpServerMetrics(ArmeriaServerTelemetryBuilder, boolean)} + * instead. + */ + @Deprecated + @CanIgnoreReturnValue + public ArmeriaServerTelemetryBuilder setEmitExperimentalHttpServerMetrics( + boolean emitExperimentalHttpServerMetrics) { + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); + return this; + } + + /** Sets custom server {@link SpanNameExtractor} via transform function. */ + @CanIgnoreReturnValue + public ArmeriaServerTelemetryBuilder setSpanNameExtractor( + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> + serverSpanNameExtractor) { + builder.setSpanNameExtractor(serverSpanNameExtractor); + return this; + } + + public ArmeriaServerTelemetry build() { + return new ArmeriaServerTelemetry(builder.build()); + } + + private DefaultHttpServerInstrumenterBuilder getBuilder() { + return builder; + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetry.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetry.java index 94accffa1a73..771b04c142cb 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetry.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetry.java @@ -14,7 +14,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import java.util.function.Function; -/** Entrypoint for instrumenting Armeria services or clients. */ +/** + * Entrypoint for instrumenting Armeria services or clients. + * + * @deprecated Use {@link ArmeriaClientTelemetry} and {@link ArmeriaServerTelemetry} instead. + */ +@Deprecated public final class ArmeriaTelemetry { /** Returns a new {@link ArmeriaTelemetry} configured with the given {@link OpenTelemetry}. */ @@ -39,7 +44,10 @@ public static ArmeriaTelemetryBuilder builder(OpenTelemetry openTelemetry) { /** * Returns a new {@link HttpClient} decorator for use with methods like {@link * com.linecorp.armeria.client.ClientBuilder#decorator(Function)}. + * + * @deprecated Use {@link ArmeriaClientTelemetry#newDecorator()} instead. */ + @Deprecated public Function newClientDecorator() { return client -> new OpenTelemetryClient(client, clientInstrumenter); } @@ -47,7 +55,10 @@ public static ArmeriaTelemetryBuilder builder(OpenTelemetry openTelemetry) { /** * Returns a new {@link HttpService} decorator for use with methods like {@link * HttpService#decorate(Function)}. + * + * @deprecated Use {@link ArmeriaServerTelemetry#newDecorator()} instead. */ + @Deprecated public Function newServiceDecorator() { return service -> new OpenTelemetryService(service, serverInstrumenter); } diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java index bb59d2d9cb39..076650836ae2 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java @@ -19,12 +19,16 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; import io.opentelemetry.instrumentation.armeria.v1_3.internal.Experimental; import java.util.List; import java.util.Set; import java.util.function.Function; +/** + * @deprecated Use {@link ArmeriaClientTelemetryBuilder} and {@link ArmeriaServerTelemetryBuilder} + * instead. + */ +@Deprecated public final class ArmeriaTelemetryBuilder { private final DefaultHttpClientInstrumenterBuilder @@ -32,13 +36,6 @@ public final class ArmeriaTelemetryBuilder { private final DefaultHttpServerInstrumenterBuilder serverBuilder; - static { - ArmeriaInstrumenterBuilderUtil.setClientBuilderExtractor( - ArmeriaTelemetryBuilder::getClientBuilder); - ArmeriaInstrumenterBuilderUtil.setServerBuilderExtractor( - ArmeriaTelemetryBuilder::getServerBuilder); - } - ArmeriaTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); @@ -63,7 +60,12 @@ public ArmeriaTelemetryBuilder setStatusExtractor( return this; } - /** Sets the status extractor for client spans. */ + /** + * Sets the status extractor for client spans. + * + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setStatusExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setClientStatusExtractor( Function< @@ -74,7 +76,12 @@ public ArmeriaTelemetryBuilder setClientStatusExtractor( return this; } - /** Sets the status extractor for server spans. */ + /** + * Sets the status extractor for server spans. + * + * @deprecated Use {@link ArmeriaServerTelemetryBuilder#setStatusExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setServerStatusExtractor( Function< @@ -105,7 +112,11 @@ public ArmeriaTelemetryBuilder addAttributeExtractor( * Adds an extra client-only {@link AttributesExtractor} to invoke to set attributes to * instrumented items. The {@link AttributesExtractor} will be executed after all default * extractors. + * + * @deprecated Use {@link + * ArmeriaClientTelemetryBuilder#addAttributeExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addClientAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -117,7 +128,11 @@ public ArmeriaTelemetryBuilder addClientAttributeExtractor( * Adds an extra server-only {@link AttributesExtractor} to invoke to set attributes to * instrumented items. The {@link AttributesExtractor} will be executed after all default * extractors. + * + * @deprecated Use {@link + * ArmeriaServerTelemetryBuilder#addAttributeExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addServerAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -125,7 +140,12 @@ public ArmeriaTelemetryBuilder addServerAttributeExtractor( return this; } - /** Sets the {@code peer.service} attribute for http client spans. */ + /** + * Sets the {@code peer.service} attribute for http client spans. + * + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setPeerService(String)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setPeerService(String peerService) { clientBuilder.setPeerService(peerService); @@ -136,7 +156,9 @@ public ArmeriaTelemetryBuilder setPeerService(String peerService) { * Configures the HTTP client request headers that will be captured as span attributes. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setCapturedRequestHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedClientRequestHeaders(List requestHeaders) { clientBuilder.setCapturedRequestHeaders(requestHeaders); @@ -147,7 +169,9 @@ public ArmeriaTelemetryBuilder 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 ArmeriaClientTelemetryBuilder#setCapturedResponseHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedClientResponseHeaders(List responseHeaders) { clientBuilder.setCapturedResponseHeaders(responseHeaders); @@ -158,7 +182,9 @@ public ArmeriaTelemetryBuilder setCapturedClientResponseHeaders(List res * Configures the HTTP server request headers that will be captured as span attributes. * * @param requestHeaders A list of HTTP header names. + * @deprecated Use {@link ArmeriaServerTelemetryBuilder#setCapturedRequestHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedServerRequestHeaders(List requestHeaders) { serverBuilder.setCapturedRequestHeaders(requestHeaders); @@ -169,7 +195,9 @@ public ArmeriaTelemetryBuilder 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 ArmeriaServerTelemetryBuilder#setCapturedResponseHeaders(List)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedServerResponseHeaders(List responseHeaders) { serverBuilder.setCapturedResponseHeaders(responseHeaders); @@ -189,7 +217,10 @@ public ArmeriaTelemetryBuilder setCapturedServerResponseHeaders(List res * @param knownMethods A set of recognized HTTP request methods. * @see HttpClientAttributesExtractorBuilder#setKnownMethods(Set) * @see HttpServerAttributesExtractorBuilder#setKnownMethods(Set) + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setKnownMethods(Set)} or {@link + * ArmeriaServerTelemetryBuilder#setKnownMethods(Set)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { clientBuilder.setKnownMethods(knownMethods); @@ -203,7 +234,7 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. * @deprecated Use {@link - * Experimental#setEmitExperimentalHttpClientMetrics(ArmeriaTelemetryBuilder, boolean)} + * Experimental#setEmitExperimentalHttpClientMetrics(ArmeriaClientTelemetryBuilder, boolean)} * instead. */ @Deprecated @@ -220,7 +251,7 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. * @deprecated Use {@link - * Experimental#setEmitExperimentalHttpServerMetrics(ArmeriaTelemetryBuilder, boolean)} + * Experimental#setEmitExperimentalHttpServerMetrics(ArmeriaServerTelemetryBuilder, boolean)} * instead. */ @Deprecated @@ -231,7 +262,12 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( return this; } - /** Sets custom client {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom client {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setSpanNameExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setClientSpanNameExtractor( Function< @@ -242,7 +278,12 @@ public ArmeriaTelemetryBuilder setClientSpanNameExtractor( return this; } - /** Sets custom server {@link SpanNameExtractor} via transform function. */ + /** + * Sets custom server {@link SpanNameExtractor} via transform function. + * + * @deprecated Use {@link ArmeriaServerTelemetryBuilder#setSpanNameExtractor(Function)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setServerSpanNameExtractor( Function< @@ -253,17 +294,12 @@ public ArmeriaTelemetryBuilder setServerSpanNameExtractor( return this; } + /** + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#build()} and {@link + * ArmeriaServerTelemetryBuilder#build()} instead. + */ + @Deprecated public ArmeriaTelemetry build() { return new ArmeriaTelemetry(clientBuilder.build(), serverBuilder.build()); } - - private DefaultHttpClientInstrumenterBuilder - getClientBuilder() { - return clientBuilder; - } - - private DefaultHttpServerInstrumenterBuilder - getServerBuilder() { - return serverBuilder; - } } diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java index a9a7d8b43b09..448a244d48e3 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java @@ -10,7 +10,8 @@ import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; -import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaClientTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaServerTelemetryBuilder; import java.util.function.Function; import javax.annotation.Nullable; @@ -23,19 +24,19 @@ private ArmeriaInstrumenterBuilderUtil() {} @Nullable private static Function< - ArmeriaTelemetryBuilder, + ArmeriaClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor; @Nullable private static Function< - ArmeriaTelemetryBuilder, + ArmeriaServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor; @Nullable public static Function< - ArmeriaTelemetryBuilder, + ArmeriaClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> getClientBuilderExtractor() { return clientBuilderExtractor; @@ -43,7 +44,7 @@ private ArmeriaInstrumenterBuilderUtil() {} public static void setClientBuilderExtractor( Function< - ArmeriaTelemetryBuilder, + ArmeriaClientTelemetryBuilder, DefaultHttpClientInstrumenterBuilder> clientBuilderExtractor) { ArmeriaInstrumenterBuilderUtil.clientBuilderExtractor = clientBuilderExtractor; @@ -51,7 +52,7 @@ public static void setClientBuilderExtractor( @Nullable public static Function< - ArmeriaTelemetryBuilder, + ArmeriaServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> getServerBuilderExtractor() { return serverBuilderExtractor; @@ -59,7 +60,7 @@ public static void setClientBuilderExtractor( public static void setServerBuilderExtractor( Function< - ArmeriaTelemetryBuilder, + ArmeriaServerTelemetryBuilder, DefaultHttpServerInstrumenterBuilder> serverBuilderExtractor) { ArmeriaInstrumenterBuilderUtil.serverBuilderExtractor = serverBuilderExtractor; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/Experimental.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/Experimental.java index b5703c771dd9..481a8da4cb5d 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/Experimental.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/Experimental.java @@ -7,7 +7,8 @@ import static java.util.logging.Level.FINE; -import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaClientTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaServerTelemetryBuilder; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.logging.Logger; @@ -27,12 +28,14 @@ public class Experimental { private static final Method emitExperimentalHttpClientMetricsMethod = getEmitExperimentalHttpClientMetricsMethod(); + @Nullable private static final Method emitClientPeerServiceMethod = getClientPeerServiceMethod(); + @Nullable private static final Method emitExperimentalHttpServerMetricsMethod = getEmitExperimentalHttpServerMetricsMethod(); public void setEmitExperimentalHttpClientMetrics( - ArmeriaTelemetryBuilder builder, boolean emitExperimentalHttpClientMetrics) { + ArmeriaClientTelemetryBuilder builder, boolean emitExperimentalHttpClientMetrics) { if (emitExperimentalHttpClientMetricsMethod != null) { try { @@ -44,7 +47,7 @@ public void setEmitExperimentalHttpClientMetrics( } public void setEmitExperimentalHttpServerMetrics( - ArmeriaTelemetryBuilder builder, boolean emitExperimentalHttpServerMetrics) { + ArmeriaServerTelemetryBuilder builder, boolean emitExperimentalHttpServerMetrics) { if (emitExperimentalHttpServerMetricsMethod != null) { try { @@ -55,10 +58,21 @@ public void setEmitExperimentalHttpServerMetrics( } } + public void setClientPeerService(ArmeriaClientTelemetryBuilder builder, String peerService) { + + if (emitClientPeerServiceMethod != null) { + try { + emitClientPeerServiceMethod.invoke(builder, peerService); + } catch (IllegalAccessException | InvocationTargetException e) { + logger.log(FINE, e.getMessage(), e); + } + } + } + @Nullable private static Method getEmitExperimentalHttpClientMetricsMethod() { try { - return ArmeriaTelemetryBuilder.class.getMethod( + return ArmeriaClientTelemetryBuilder.class.getMethod( "setEmitExperimentalHttpClientMetrics", boolean.class); } catch (NoSuchMethodException e) { logger.log(FINE, e.getMessage(), e); @@ -66,10 +80,20 @@ private static Method getEmitExperimentalHttpClientMetricsMethod() { } } + @Nullable + private static Method getClientPeerServiceMethod() { + try { + return ArmeriaClientTelemetryBuilder.class.getMethod("setPeerService", String.class); + } catch (NoSuchMethodException e) { + logger.log(FINE, e.getMessage(), e); + return null; + } + } + @Nullable private static Method getEmitExperimentalHttpServerMetricsMethod() { try { - return ArmeriaTelemetryBuilder.class.getMethod( + return ArmeriaServerTelemetryBuilder.class.getMethod( "setEmitExperimentalHttpServerMetrics", boolean.class); } catch (NoSuchMethodException e) { logger.log(FINE, e.getMessage(), e); diff --git a/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java index eb35610d5023..3cb317cd7f34 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java +++ b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientTest.java @@ -21,13 +21,13 @@ class ArmeriaHttpClientTest extends AbstractArmeriaHttpClientTest { @Override protected WebClientBuilder configureClient(WebClientBuilder clientBuilder) { return clientBuilder.decorator( - ArmeriaTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedClientRequestHeaders( + ArmeriaClientTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) - .setCapturedClientResponseHeaders( + .setCapturedResponseHeaders( Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) .build() - .newClientDecorator()); + .newDecorator()); } @Override diff --git a/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.java b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.java index 283261595fa8..399eeee0f897 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.java +++ b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerTest.java @@ -21,13 +21,13 @@ class ArmeriaHttpServerTest extends AbstractArmeriaHttpServerTest { @Override protected ServerBuilder configureServer(ServerBuilder sb) { return sb.decorator( - ArmeriaTelemetry.builder(testing.getOpenTelemetry()) - .setCapturedServerRequestHeaders( + ArmeriaServerTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedRequestHeaders( Collections.singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) - .setCapturedServerResponseHeaders( + .setCapturedResponseHeaders( Collections.singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) .build() - .newServiceDecorator()); + .newDecorator()); } @Override