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..7d8cd00b291a --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaClientTelemetryBuilder.java @@ -0,0 +1,117 @@ +/* + * 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(builder -> builder.builder); + Experimental.setSetEmitExperimentalClientTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpClientMetrics(emit)); + Experimental.setSetClientPeerService( + (builder, peerService) -> builder.builder.setPeerService(peerService)); + } + + 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 {@link AttributesExtractor} to invoke to set attributes to instrumented items. + * The {@link AttributesExtractor} will be executed after all default extractors. + */ + @CanIgnoreReturnValue + public ArmeriaClientTelemetryBuilder 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 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; + } + + /** 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()); + } +} 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..613898bdad9a --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaServerTelemetryBuilder.java @@ -0,0 +1,115 @@ +/* + * 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(builder -> builder.builder); + Experimental.setSetEmitExperimentalServerTelemetry( + (builder, emit) -> builder.builder.setEmitExperimentalHttpServerMetrics(emit)); + } + + 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 {@link AttributesExtractor} to invoke to set attributes to instrumented items. + * The {@link AttributesExtractor} will be executed after all default extractors. + */ + @CanIgnoreReturnValue + public ArmeriaServerTelemetryBuilder 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 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; + } + + /** 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()); + } +} 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..1d6cd136f859 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,14 +14,30 @@ 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}. */ + /** + * Returns a new {@link ArmeriaTelemetry} configured with the given {@link OpenTelemetry}. + * + * @deprecated Use {@link ArmeriaClientTelemetry#create(OpenTelemetry)} and {@link + * ArmeriaServerTelemetry#create(OpenTelemetry)} instead. + */ + @Deprecated public static ArmeriaTelemetry create(OpenTelemetry openTelemetry) { return builder(openTelemetry).build(); } + /** + * @deprecated Use {@link ArmeriaClientTelemetry#builder(OpenTelemetry)} and {@link + * ArmeriaServerTelemetry#builder(OpenTelemetry)} instead. + */ + @Deprecated public static ArmeriaTelemetryBuilder builder(OpenTelemetry openTelemetry) { return new ArmeriaTelemetryBuilder(openTelemetry); } @@ -39,7 +55,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 +66,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 d52523795615..5a900eb95c8c 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,11 +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 @@ -31,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); @@ -46,8 +44,8 @@ public final class ArmeriaTelemetryBuilder { /** * Sets the status extractor for both client and server spans. * - * @deprecated Use {@link #setClientStatusExtractor(Function)} or {@link - * #setServerStatusExtractor(Function)} instead. + * @deprecated Use {@link ArmeriaClientTelemetryBuilder#setStatusExtractor(Function)} and {@link + * ArmeriaServerTelemetryBuilder#setStatusExtractor(Function)} instead. */ @Deprecated @SuppressWarnings({"unchecked", "rawtypes"}) @@ -62,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< @@ -73,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< @@ -88,8 +96,9 @@ public ArmeriaTelemetryBuilder setServerStatusExtractor( * 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 #addClientAttributeExtractor(AttributesExtractor)} or {@link - * #addServerAttributeExtractor(AttributesExtractor)} instead. + * @deprecated Use {@link + * ArmeriaClientTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} and {@link + * ArmeriaServerTelemetryBuilder#addAttributesExtractor(AttributesExtractor)} instead. */ @Deprecated @CanIgnoreReturnValue @@ -104,7 +113,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#addAttributesExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addClientAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -116,7 +129,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#addAttributesExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addServerAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -124,7 +141,13 @@ 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 Experimental#setClientPeerService(ArmeriaClientTelemetryBuilder, + * String)} instead. + */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setPeerService(String peerService) { clientBuilder.setPeerService(peerService); @@ -135,7 +158,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); @@ -146,7 +171,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); @@ -157,7 +184,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); @@ -168,7 +197,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); @@ -188,7 +219,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)} and {@link + * ArmeriaServerTelemetryBuilder#setKnownMethods(Set)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { clientBuilder.setKnownMethods(knownMethods); @@ -201,7 +235,10 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { * * @param emitExperimentalHttpClientMetrics {@code true} if the experimental HTTP client metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(ArmeriaClientTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { @@ -214,7 +251,10 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( * * @param emitExperimentalHttpServerMetrics {@code true} if the experimental HTTP server metrics * are to be emitted. + * @deprecated Use {@link Experimental#setEmitExperimentalTelemetry(ArmeriaServerTelemetryBuilder, + * boolean)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { @@ -222,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< @@ -233,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< @@ -244,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 new file mode 100644 index 000000000000..ec3c65af7b86 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/Experimental.java @@ -0,0 +1,68 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaClientTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaServerTelemetryBuilder; +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; + + @Nullable + private static volatile BiConsumer setClientPeerService; + + public static void setEmitExperimentalTelemetry( + ArmeriaClientTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + if (setEmitExperimentalClientTelemetry != null) { + setEmitExperimentalClientTelemetry.accept(builder, emitExperimentalTelemetry); + } + } + + public static void setEmitExperimentalTelemetry( + ArmeriaServerTelemetryBuilder builder, boolean emitExperimentalTelemetry) { + if (setEmitExperimentalServerTelemetry != null) { + setEmitExperimentalServerTelemetry.accept(builder, emitExperimentalTelemetry); + } + } + + public static void setClientPeerService( + ArmeriaClientTelemetryBuilder builder, String peerService) { + if (setClientPeerService != null) { + setClientPeerService.accept(builder, peerService); + } + } + + public static void setSetEmitExperimentalClientTelemetry( + BiConsumer setEmitExperimentalClientTelemetry) { + Experimental.setEmitExperimentalClientTelemetry = setEmitExperimentalClientTelemetry; + } + + public static void setSetEmitExperimentalServerTelemetry( + BiConsumer setEmitExperimentalServerTelemetry) { + Experimental.setEmitExperimentalServerTelemetry = setEmitExperimentalServerTelemetry; + } + + public static void setSetClientPeerService( + BiConsumer setClientPeerService) { + Experimental.setClientPeerService = setClientPeerService; + } + + private Experimental() {} +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientOldTest.java b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientOldTest.java new file mode 100644 index 000000000000..808288f1dbb1 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpClientOldTest.java @@ -0,0 +1,46 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.linecorp.armeria.client.WebClientBuilder; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientTestOptions; +import java.util.Collections; +import org.junit.jupiter.api.extension.RegisterExtension; + +@SuppressWarnings("deprecation") // testing deprecated API +class ArmeriaHttpClientOldTest extends AbstractArmeriaHttpClientTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary(); + + @Override + protected WebClientBuilder configureClient(WebClientBuilder clientBuilder) { + return clientBuilder.decorator( + ArmeriaTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedClientRequestHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) + .setCapturedClientResponseHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) + .build() + .newClientDecorator()); + } + + @Override + protected void configure(HttpClientTestOptions.Builder optionsBuilder) { + super.configure(optionsBuilder); + + // library instrumentation doesn't have a good way of suppressing nested CLIENT spans yet + optionsBuilder.disableTestWithClientParent(); + + // Agent users have automatic propagation through executor instrumentation, but library users + // should do manually using Armeria patterns. + optionsBuilder.disableTestCallbackWithParent(); + optionsBuilder.disableTestErrorWithCallback(); + } +} 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/ArmeriaHttpServerOldTest.java b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerOldTest.java new file mode 100644 index 000000000000..cbfb829e3937 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/test/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerOldTest.java @@ -0,0 +1,40 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3; + +import com.linecorp.armeria.server.ServerBuilder; +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 java.util.Collections; +import org.junit.jupiter.api.extension.RegisterExtension; + +@SuppressWarnings("deprecation") // testing deprecated API +class ArmeriaHttpServerOldTest extends AbstractArmeriaHttpServerTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forLibrary(); + + @Override + protected ServerBuilder configureServer(ServerBuilder sb) { + return sb.decorator( + ArmeriaTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedServerRequestHeaders( + Collections.singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedServerResponseHeaders( + Collections.singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + .build() + .newServiceDecorator()); + } + + @Override + protected void configure(HttpServerTestOptions options) { + super.configure(options); + // library instrumentation does not create a span at all + options.disableTestNonStandardHttpMethod(); + } +} 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