From 7ab761680a43ec34126170597d75b2f66ea85e02 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 11 Jul 2024 15:22:16 +0200 Subject: [PATCH 01/11] use DefaultHttpClientInstrumenterBuilder and DefaultHttpServerInstrumenterBuilder for armeria --- .../DefaultHttpClientInstrumenterBuilder.java | 29 ++- .../armeria/v1_3/ArmeriaSingletons.java | 30 +-- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 173 +++++------------- .../ArmeriaHttpClientAttributesGetter.java | 6 +- .../ArmeriaHttpServerAttributesGetter.java | 3 +- .../ArmeriaInstrumenterBuilderFactory.java | 45 +++++ .../ArmeriaInstrumenterBuilderUtil.java | 67 +++++++ .../ClientRequestContextSetter.java | 2 +- .../v1_3/internal/RequestContextAccess.java | 6 +- .../{ => internal}/RequestContextGetter.java | 2 +- 10 files changed, 201 insertions(+), 162 deletions(-) rename instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/{ => internal}/ArmeriaHttpServerAttributesGetter.java (95%) create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java create mode 100644 instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java rename instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/{ => internal}/ClientRequestContextSetter.java (89%) rename instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/{ => internal}/RequestContextGetter.java (93%) diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java index 50f73aa48069..d1ecb0297e09 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java @@ -7,6 +7,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.context.propagation.TextMapSetter; import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientExperimentalMetrics; @@ -18,6 +19,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; @@ -39,11 +41,18 @@ */ public final class DefaultHttpClientInstrumenterBuilder { + // copied from PeerIncubatingAttributes + private static final AttributeKey PEER_SERVICE = AttributeKey.stringKey("peer.service"); + private final String instrumentationName; private final OpenTelemetry openTelemetry; private final List> additionalExtractors = new ArrayList<>(); + private Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractorTransformer = Function.identity(); private final HttpClientAttributesExtractorBuilder httpAttributesExtractorBuilder; private final HttpClientAttributesGetter attributesGetter; @@ -77,6 +86,16 @@ public DefaultHttpClientInstrumenterBuilder addAttributeExtra return this; } + @CanIgnoreReturnValue + public DefaultHttpClientInstrumenterBuilder setStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + this.statusExtractorTransformer = statusExtractor; + return this; + } + /** * Configures the HTTP request headers that will be captured as span attributes. * @@ -159,6 +178,13 @@ public DefaultHttpClientInstrumenterBuilder setPeerServiceRes HttpClientPeerServiceAttributesExtractor.create(attributesGetter, peerServiceResolver)); } + /** Sets the {@code peer.service} attribute for http client spans. */ + @CanIgnoreReturnValue + public DefaultHttpClientInstrumenterBuilder setPeerService( + String peerService) { + return addAttributeExtractor(AttributesExtractor.constant(PEER_SERVICE, peerService)); + } + @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder setBuilderCustomizer( Consumer> builderCustomizer) { @@ -174,7 +200,8 @@ public Instrumenter build() { InstrumenterBuilder builder = Instrumenter.builder( openTelemetry, instrumentationName, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(attributesGetter)) + .setSpanStatusExtractor( + statusExtractorTransformer.apply(HttpSpanStatusExtractor.create(attributesGetter))) .addAttributesExtractor(httpAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpClientMetrics.get()); 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 8f4800ebca34..4845c528e7e1 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 @@ -8,9 +8,10 @@ import com.linecorp.armeria.client.HttpClient; import com.linecorp.armeria.server.HttpService; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientPeerServiceAttributesExtractor; +import io.opentelemetry.instrumentation.api.incubator.config.internal.CommonConfig; import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetry; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaHttpClientAttributesGetter; +import io.opentelemetry.instrumentation.armeria.v1_3.ArmeriaTelemetryBuilder; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import java.util.function.Function; @@ -22,28 +23,15 @@ public final class ArmeriaSingletons { public static final Function SERVER_DECORATOR; static { - ArmeriaTelemetry telemetry = - ArmeriaTelemetry.builder(GlobalOpenTelemetry.get()) - .setCapturedClientRequestHeaders(AgentCommonConfig.get().getClientRequestHeaders()) - .setCapturedClientResponseHeaders(AgentCommonConfig.get().getClientResponseHeaders()) - .setCapturedServerRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedServerResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .addClientAttributeExtractor( - HttpClientPeerServiceAttributesExtractor.create( - ArmeriaHttpClientAttributesGetter.INSTANCE, - AgentCommonConfig.get().getPeerServiceResolver())) - .setEmitExperimentalHttpClientMetrics( - AgentCommonConfig.get().shouldEmitExperimentalHttpClientTelemetry()) - .setEmitExperimentalHttpServerMetrics( - AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) - .build(); + 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(); Function libraryDecorator = - telemetry - .newServiceDecorator() - .compose(service -> new ResponseCustomizingDecorator(service)); + telemetry.newServiceDecorator().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/ArmeriaTelemetryBuilder.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java index d39d8dcbb47a..196d2b80dc97 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 @@ -11,87 +11,48 @@ import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpClientExperimentalMetrics; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractorBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaHttpClientAttributesGetter; -import java.util.ArrayList; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderFactory; +import io.opentelemetry.instrumentation.armeria.v1_3.internal.ArmeriaInstrumenterBuilderUtil; import java.util.List; import java.util.Set; import java.util.function.Function; -import java.util.stream.Stream; -import javax.annotation.Nullable; public final class ArmeriaTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; - // copied from PeerIncubatingAttributes - private static final AttributeKey PEER_SERVICE = AttributeKey.stringKey("peer.service"); + private final DefaultHttpClientInstrumenterBuilder + clientBuilder; + private final DefaultHttpServerInstrumenterBuilder + serverBuilder; - private final OpenTelemetry openTelemetry; - @Nullable private String peerService; - private boolean emitExperimentalHttpClientMetrics = false; - private boolean emitExperimentalHttpServerMetrics = false; - - private final List> - additionalExtractors = new ArrayList<>(); - private final List> - additionalClientExtractors = new ArrayList<>(); - - private final HttpClientAttributesExtractorBuilder - httpClientAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(ArmeriaHttpClientAttributesGetter.INSTANCE); - private final HttpServerAttributesExtractorBuilder - httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(ArmeriaHttpServerAttributesGetter.INSTANCE); - - private final HttpSpanNameExtractorBuilder httpClientSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(ArmeriaHttpClientAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpServerSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(ArmeriaHttpServerAttributesGetter.INSTANCE); - private Function< - SpanNameExtractor, ? extends SpanNameExtractor> - clientSpanNameExtractorTransformer = Function.identity(); - private Function< - SpanNameExtractor, ? extends SpanNameExtractor> - serverSpanNameExtractorTransformer = Function.identity(); - - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(ArmeriaHttpServerAttributesGetter.INSTANCE); - - private Function< - SpanStatusExtractor, - ? extends SpanStatusExtractor> - statusExtractorTransformer = Function.identity(); + static { + ArmeriaInstrumenterBuilderUtil.setClientBuilderExtractor( + ArmeriaTelemetryBuilder::getClientBuilder); + ArmeriaInstrumenterBuilderUtil.setServerBuilderExtractor( + ArmeriaTelemetryBuilder::getServerBuilder); + } + @SuppressWarnings({"rawtypes", "unchecked"}) ArmeriaTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + clientBuilder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); + serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); } + @SuppressWarnings({"unchecked", "rawtypes"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setStatusExtractor( Function< SpanStatusExtractor, ? extends SpanStatusExtractor> statusExtractor) { - this.statusExtractorTransformer = statusExtractor; + clientBuilder.setStatusExtractor((Function) statusExtractor); + serverBuilder.setStatusExtractor((Function) statusExtractor); return this; } @@ -102,7 +63,8 @@ public ArmeriaTelemetryBuilder setStatusExtractor( @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); + serverBuilder.addAttributesExtractor(attributesExtractor); return this; } @@ -114,14 +76,14 @@ public ArmeriaTelemetryBuilder addAttributeExtractor( @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addClientAttributeExtractor( AttributesExtractor attributesExtractor) { - additionalClientExtractors.add(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } /** Sets the {@code peer.service} attribute for http client spans. */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setPeerService(String peerService) { - this.peerService = peerService; + clientBuilder.setPeerService(peerService); return this; } @@ -132,7 +94,7 @@ public ArmeriaTelemetryBuilder setPeerService(String peerService) { */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedClientRequestHeaders(List requestHeaders) { - httpClientAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -143,7 +105,7 @@ public ArmeriaTelemetryBuilder setCapturedClientRequestHeaders(List requ */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedClientResponseHeaders(List responseHeaders) { - httpClientAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -154,7 +116,7 @@ public ArmeriaTelemetryBuilder setCapturedClientResponseHeaders(List res */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedServerRequestHeaders(List requestHeaders) { - httpServerAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + serverBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -165,7 +127,7 @@ public ArmeriaTelemetryBuilder setCapturedServerRequestHeaders(List requ */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setCapturedServerResponseHeaders(List responseHeaders) { - httpServerAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + serverBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -185,11 +147,8 @@ public ArmeriaTelemetryBuilder setCapturedServerResponseHeaders(List res */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { - httpClientAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpServerAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpClientSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + clientBuilder.setKnownMethods(knownMethods); + serverBuilder.setKnownMethods(knownMethods); return this; } @@ -202,7 +161,8 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - this.emitExperimentalHttpClientMetrics = emitExperimentalHttpClientMetrics; + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -215,85 +175,46 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpServerMetrics); + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } /** Sets custom client {@link SpanNameExtractor} via transform function. */ + @SuppressWarnings({"rawtypes", "unchecked"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setClientSpanNameExtractor( Function< SpanNameExtractor, ? extends SpanNameExtractor> clientSpanNameExtractor) { - this.clientSpanNameExtractorTransformer = clientSpanNameExtractor; + clientBuilder.setSpanNameExtractor((Function) clientSpanNameExtractor); return this; } /** Sets custom server {@link SpanNameExtractor} via transform function. */ + @SuppressWarnings({"rawtypes", "unchecked"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setServerSpanNameExtractor( Function< SpanNameExtractor, ? extends SpanNameExtractor> serverSpanNameExtractor) { - this.serverSpanNameExtractorTransformer = serverSpanNameExtractor; + serverBuilder.setSpanNameExtractor((Function) serverSpanNameExtractor); return this; } public ArmeriaTelemetry build() { - ArmeriaHttpClientAttributesGetter clientAttributesGetter = - ArmeriaHttpClientAttributesGetter.INSTANCE; - ArmeriaHttpServerAttributesGetter serverAttributesGetter = - ArmeriaHttpServerAttributesGetter.INSTANCE; - - SpanNameExtractor clientSpanNameExtractor = - clientSpanNameExtractorTransformer.apply(httpClientSpanNameExtractorBuilder.build()); - SpanNameExtractor serverSpanNameExtractor = - serverSpanNameExtractorTransformer.apply(httpServerSpanNameExtractorBuilder.build()); - - InstrumenterBuilder clientInstrumenterBuilder = - Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, clientSpanNameExtractor); - InstrumenterBuilder serverInstrumenterBuilder = - Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, serverSpanNameExtractor); - - Stream.of(clientInstrumenterBuilder, serverInstrumenterBuilder) - .forEach(instrumenter -> instrumenter.addAttributesExtractors(additionalExtractors)); - - clientInstrumenterBuilder - .setSpanStatusExtractor( - statusExtractorTransformer.apply( - HttpSpanStatusExtractor.create(clientAttributesGetter))) - .addAttributesExtractor(httpClientAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalClientExtractors) - .addOperationMetrics(HttpClientMetrics.get()); - serverInstrumenterBuilder - .setSpanStatusExtractor( - statusExtractorTransformer.apply( - HttpSpanStatusExtractor.create(serverAttributesGetter))) - .addAttributesExtractor(httpServerAttributesExtractorBuilder.build()) - .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(httpServerRouteBuilder.build()); + return new ArmeriaTelemetry(clientBuilder.build(), serverBuilder.build()); + } - if (peerService != null) { - clientInstrumenterBuilder.addAttributesExtractor( - AttributesExtractor.constant(PEER_SERVICE, peerService)); - } - if (emitExperimentalHttpClientMetrics) { - clientInstrumenterBuilder - .addAttributesExtractor( - HttpExperimentalAttributesExtractor.create(clientAttributesGetter)) - .addOperationMetrics(HttpClientExperimentalMetrics.get()); - } - if (emitExperimentalHttpServerMetrics) { - serverInstrumenterBuilder - .addAttributesExtractor( - HttpExperimentalAttributesExtractor.create(serverAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } + private DefaultHttpClientInstrumenterBuilder + getClientBuilder() { + return clientBuilder; + } - return new ArmeriaTelemetry( - clientInstrumenterBuilder.buildClientInstrumenter(ClientRequestContextSetter.INSTANCE), - serverInstrumenterBuilder.buildServerInstrumenter(RequestContextGetter.INSTANCE)); + private DefaultHttpServerInstrumenterBuilder + getServerBuilder() { + return serverBuilder; } } diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java index ec6d00b8d6e2..b86986a57f66 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java @@ -16,11 +16,7 @@ import java.util.List; 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. - */ -public enum ArmeriaHttpClientAttributesGetter +enum ArmeriaHttpClientAttributesGetter implements HttpClientAttributesGetter { INSTANCE; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java similarity index 95% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java index 1f5891d9c43f..75d727c60578 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaHttpServerAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.HttpStatus; @@ -12,7 +12,6 @@ import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; -import io.opentelemetry.instrumentation.armeria.v1_3.internal.RequestContextAccess; import java.net.InetSocketAddress; import java.util.List; import javax.annotation.Nullable; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java new file mode 100644 index 000000000000..7924f91afb14 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import com.linecorp.armeria.client.ClientRequestContext; +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.DefaultHttpClientInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; +import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class ArmeriaInstrumenterBuilderFactory { + private ArmeriaInstrumenterBuilderFactory() {} + + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static DefaultHttpServerInstrumenterBuilder + getServerBuilder(OpenTelemetry openTelemetry) { + return new DefaultHttpServerInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + (HttpServerAttributesGetter) ArmeriaHttpServerAttributesGetter.INSTANCE) + .setHeaderGetter(RequestContextGetter.INSTANCE); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + public static DefaultHttpClientInstrumenterBuilder + getClientBuilder(OpenTelemetry openTelemetry) { + return new DefaultHttpClientInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + (HttpClientAttributesGetter) ArmeriaHttpClientAttributesGetter.INSTANCE) + .setHeaderSetter(ClientRequestContextSetter.INSTANCE); + } +} 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 new file mode 100644 index 000000000000..a9a7d8b43b09 --- /dev/null +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderUtil.java @@ -0,0 +1,67 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.armeria.v1_3.internal; + +import com.linecorp.armeria.client.ClientRequestContext; +import com.linecorp.armeria.common.logging.RequestLog; +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 java.util.function.Function; +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. + */ +public class ArmeriaInstrumenterBuilderUtil { + private ArmeriaInstrumenterBuilderUtil() {} + + @Nullable + private static Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + clientBuilderExtractor; + + @Nullable + private static Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor; + + @Nullable + public static Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + getClientBuilderExtractor() { + return clientBuilderExtractor; + } + + public static void setClientBuilderExtractor( + Function< + ArmeriaTelemetryBuilder, + DefaultHttpClientInstrumenterBuilder> + clientBuilderExtractor) { + ArmeriaInstrumenterBuilderUtil.clientBuilderExtractor = clientBuilderExtractor; + } + + @Nullable + public static Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + getServerBuilderExtractor() { + return serverBuilderExtractor; + } + + public static void setServerBuilderExtractor( + Function< + ArmeriaTelemetryBuilder, + DefaultHttpServerInstrumenterBuilder> + serverBuilderExtractor) { + ArmeriaInstrumenterBuilderUtil.serverBuilderExtractor = serverBuilderExtractor; + } +} diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java similarity index 89% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java index 91ce53e54805..1a225fd7108b 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ClientRequestContextSetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ClientRequestContextSetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.client.ClientRequestContext; import io.opentelemetry.context.propagation.TextMapSetter; diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java index acaf7fd9cfa0..1a7830758fd6 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextAccess.java @@ -13,11 +13,7 @@ import java.net.SocketAddress; 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. - */ -public final class RequestContextAccess { +final class RequestContextAccess { @Nullable private static final MethodHandle remoteAddress = findAccessorOrNull("remoteAddress"); @Nullable private static final MethodHandle localAddress = findAccessorOrNull("localAddress"); diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java similarity index 93% rename from instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java rename to instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java index 5163333591a0..5cae10de6578 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/RequestContextGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/RequestContextGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.armeria.v1_3; +package io.opentelemetry.instrumentation.armeria.v1_3.internal; import com.linecorp.armeria.server.ServiceRequestContext; import io.netty.util.AsciiString; From df66156732552026a0c293f001b1902365050698 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 18 Jul 2024 09:26:25 +0200 Subject: [PATCH 02/11] Update instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java Co-authored-by: Trask Stalnaker --- .../instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java | 1 - 1 file changed, 1 deletion(-) 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 196d2b80dc97..ae39b705d7fa 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 @@ -38,7 +38,6 @@ public final class ArmeriaTelemetryBuilder { ArmeriaTelemetryBuilder::getServerBuilder); } - @SuppressWarnings({"rawtypes", "unchecked"}) ArmeriaTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); From 52378e81514828dec2c6224b13defef2829d4a87 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 09:57:16 +0200 Subject: [PATCH 03/11] pr review --- .../instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java | 2 -- 1 file changed, 2 deletions(-) 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 ae39b705d7fa..9b5cd6fb05a9 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 @@ -161,7 +161,6 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -174,7 +173,6 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpServerMetrics); serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } From 8ceb8dfbc8646f671292c05ab85c57963eb4b945 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 10:31:26 +0200 Subject: [PATCH 04/11] pr review --- .../ArmeriaHttpClientAttributesGetter.java | 29 +++++++++-------- .../ArmeriaHttpServerAttributesGetter.java | 32 +++++++++---------- .../ArmeriaInstrumenterBuilderFactory.java | 16 +++------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java index b86986a57f66..29dfa4aca00b 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpClientAttributesGetter.java @@ -5,9 +5,9 @@ package io.opentelemetry.instrumentation.armeria.v1_3.internal; +import com.linecorp.armeria.client.ClientRequestContext; import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.HttpStatus; -import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.SessionProtocol; import com.linecorp.armeria.common.logging.RequestLog; import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; @@ -17,7 +17,7 @@ import javax.annotation.Nullable; enum ArmeriaHttpClientAttributesGetter - implements HttpClientAttributesGetter { + implements HttpClientAttributesGetter { INSTANCE; private static final ClassValue authorityMethodCache = @@ -34,12 +34,12 @@ protected Method computeValue(Class type) { }; @Override - public String getHttpRequestMethod(RequestContext ctx) { + public String getHttpRequestMethod(ClientRequestContext ctx) { return ctx.method().name(); } @Override - public String getUrlFull(RequestContext ctx) { + public String getUrlFull(ClientRequestContext ctx) { HttpRequest request = request(ctx); StringBuilder uri = new StringBuilder(); String scheme = request.scheme(); @@ -61,14 +61,14 @@ public String getUrlFull(RequestContext ctx) { } @Override - public List getHttpRequestHeader(RequestContext ctx, String name) { + public List getHttpRequestHeader(ClientRequestContext ctx, String name) { return request(ctx).headers().getAll(name); } @Override @Nullable public Integer getHttpResponseStatusCode( - RequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { + ClientRequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { HttpStatus status = requestLog.responseHeaders().status(); if (!status.equals(HttpStatus.UNKNOWN)) { return status.code(); @@ -78,17 +78,18 @@ public Integer getHttpResponseStatusCode( @Override public List getHttpResponseHeader( - RequestContext ctx, RequestLog requestLog, String name) { + ClientRequestContext ctx, RequestLog requestLog, String name) { return requestLog.responseHeaders().getAll(name); } @Override - public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolName(ClientRequestContext ctx, @Nullable RequestLog requestLog) { return "http"; } @Override - public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolVersion( + ClientRequestContext ctx, @Nullable RequestLog requestLog) { SessionProtocol protocol = requestLog != null ? requestLog.sessionProtocol() : ctx.sessionProtocol(); return protocol.isMultiplex() ? "2" : "1.1"; @@ -96,7 +97,7 @@ public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog @Nullable @Override - public String getServerAddress(RequestContext ctx) { + public String getServerAddress(ClientRequestContext ctx) { String authority = authority(ctx); if (authority == null) { return null; @@ -107,7 +108,7 @@ public String getServerAddress(RequestContext ctx) { @Nullable @Override - public Integer getServerPort(RequestContext ctx) { + public Integer getServerPort(ClientRequestContext ctx) { String authority = authority(ctx); if (authority == null) { return null; @@ -126,12 +127,12 @@ public Integer getServerPort(RequestContext ctx) { @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( - RequestContext ctx, @Nullable RequestLog requestLog) { + ClientRequestContext ctx, @Nullable RequestLog requestLog) { return RequestContextAccess.remoteAddress(ctx); } @Nullable - private static String authority(RequestContext ctx) { + private static String authority(ClientRequestContext ctx) { // newer armeria versions expose authority through DefaultClientRequestContext#authority // we are using this method as it provides default values based on endpoint // in older versions armeria wraps the request, and we can get the same default values through @@ -149,7 +150,7 @@ private static String authority(RequestContext ctx) { return request.authority(); } - private static HttpRequest request(RequestContext ctx) { + private static HttpRequest request(ClientRequestContext ctx) { HttpRequest request = ctx.request(); if (request == null) { throw new IllegalStateException( diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java index 75d727c60578..e27ab8e8258f 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java @@ -7,7 +7,6 @@ import com.linecorp.armeria.common.HttpRequest; import com.linecorp.armeria.common.HttpStatus; -import com.linecorp.armeria.common.RequestContext; import com.linecorp.armeria.common.SessionProtocol; import com.linecorp.armeria.common.logging.RequestLog; import com.linecorp.armeria.server.ServiceRequestContext; @@ -17,22 +16,22 @@ import javax.annotation.Nullable; enum ArmeriaHttpServerAttributesGetter - implements HttpServerAttributesGetter { + implements HttpServerAttributesGetter { INSTANCE; @Override - public String getHttpRequestMethod(RequestContext ctx) { + public String getHttpRequestMethod(ServiceRequestContext ctx) { return ctx.method().name(); } @Override @Nullable - public String getUrlScheme(RequestContext ctx) { + public String getUrlScheme(ServiceRequestContext ctx) { return request(ctx).scheme(); } @Override - public String getUrlPath(RequestContext ctx) { + public String getUrlPath(ServiceRequestContext ctx) { String fullPath = request(ctx).path(); int separatorPos = fullPath.indexOf('?'); return separatorPos == -1 ? fullPath : fullPath.substring(0, separatorPos); @@ -40,21 +39,21 @@ public String getUrlPath(RequestContext ctx) { @Nullable @Override - public String getUrlQuery(RequestContext ctx) { + public String getUrlQuery(ServiceRequestContext ctx) { String fullPath = request(ctx).path(); int separatorPos = fullPath.indexOf('?'); return separatorPos == -1 ? null : fullPath.substring(separatorPos + 1); } @Override - public List getHttpRequestHeader(RequestContext ctx, String name) { + public List getHttpRequestHeader(ServiceRequestContext ctx, String name) { return request(ctx).headers().getAll(name); } @Override @Nullable public Integer getHttpResponseStatusCode( - RequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { + ServiceRequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { HttpStatus status = requestLog.responseHeaders().status(); if (!status.equals(HttpStatus.UNKNOWN)) { return status.code(); @@ -64,26 +63,27 @@ public Integer getHttpResponseStatusCode( @Override public List getHttpResponseHeader( - RequestContext ctx, RequestLog requestLog, String name) { + ServiceRequestContext ctx, RequestLog requestLog, String name) { return requestLog.responseHeaders().getAll(name); } @Override @Nullable - public String getHttpRoute(RequestContext ctx) { + public String getHttpRoute(ServiceRequestContext ctx) { if (ctx instanceof ServiceRequestContext) { - return ((ServiceRequestContext) ctx).config().route().patternString(); + return ctx.config().route().patternString(); } return null; } @Override - public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolName(ServiceRequestContext ctx, @Nullable RequestLog requestLog) { return "http"; } @Override - public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolVersion( + ServiceRequestContext ctx, @Nullable RequestLog requestLog) { SessionProtocol protocol = ctx.sessionProtocol(); return protocol.isMultiplex() ? "2" : "1.1"; } @@ -91,18 +91,18 @@ public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( - RequestContext ctx, @Nullable RequestLog requestLog) { + ServiceRequestContext ctx, @Nullable RequestLog requestLog) { return RequestContextAccess.remoteAddress(ctx); } @Nullable @Override public InetSocketAddress getNetworkLocalInetSocketAddress( - RequestContext ctx, @Nullable RequestLog log) { + ServiceRequestContext ctx, @Nullable RequestLog log) { return RequestContextAccess.localAddress(ctx); } - private static HttpRequest request(RequestContext ctx) { + private static HttpRequest request(ServiceRequestContext ctx) { HttpRequest request = ctx.request(); if (request == null) { throw new IllegalStateException( diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java index 7924f91afb14..07a28da6da85 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaInstrumenterBuilderFactory.java @@ -11,8 +11,6 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesGetter; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; /** * This class is internal and is hence not for public use. Its APIs are unstable and can change at @@ -23,23 +21,17 @@ private ArmeriaInstrumenterBuilderFactory() {} private static final String INSTRUMENTATION_NAME = "io.opentelemetry.armeria-1.3"; - @SuppressWarnings({"unchecked", "rawtypes"}) public static DefaultHttpServerInstrumenterBuilder getServerBuilder(OpenTelemetry openTelemetry) { - return new DefaultHttpServerInstrumenterBuilder( - INSTRUMENTATION_NAME, - openTelemetry, - (HttpServerAttributesGetter) ArmeriaHttpServerAttributesGetter.INSTANCE) + return new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpServerAttributesGetter.INSTANCE) .setHeaderGetter(RequestContextGetter.INSTANCE); } - @SuppressWarnings({"unchecked", "rawtypes"}) public static DefaultHttpClientInstrumenterBuilder getClientBuilder(OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder( - INSTRUMENTATION_NAME, - openTelemetry, - (HttpClientAttributesGetter) ArmeriaHttpClientAttributesGetter.INSTANCE) + return new DefaultHttpClientInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpClientAttributesGetter.INSTANCE) .setHeaderSetter(ClientRequestContextSetter.INSTANCE); } } From d6a99f4ba9814bcbf3588a283e085800c9981be5 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 10:36:19 +0200 Subject: [PATCH 05/11] use ? super --- .../internal/DefaultHttpClientInstrumenterBuilder.java | 4 ++-- .../v4_3/ApacheHttpClientTelemetryBuilder.java | 2 +- .../v5_2/ApacheHttpClient5TelemetryBuilder.java | 2 +- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 7 +++---- .../httpclient/JavaHttpClientTelemetryBuilder.java | 2 +- .../httpclient/v12_0/JettyClientTelemetryBuilder.java | 2 +- .../jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java | 2 +- .../okhttp/v3_0/OkHttpTelemetryBuilder.java | 2 +- .../spring/web/v3_1/SpringWebTelemetryBuilder.java | 2 +- .../spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java | 2 +- 10 files changed, 13 insertions(+), 14 deletions(-) diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java index d1ecb0297e09..72ce1b77a701 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpClientInstrumenterBuilder.java @@ -59,7 +59,7 @@ public final class DefaultHttpClientInstrumenterBuilder { private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; @Nullable private TextMapSetter headerSetter; - private Function, ? extends SpanNameExtractor> + private Function, ? extends SpanNameExtractor> spanNameExtractorTransformer = Function.identity(); private boolean emitExperimentalHttpClientMetrics = false; private Consumer> builderCustomizer = b -> {}; @@ -164,7 +164,7 @@ public DefaultHttpClientInstrumenterBuilder setHeaderSetter( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { this.spanNameExtractorTransformer = spanNameExtractorTransformer; return this; diff --git a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java index 3526ca01436a..7508931128b1 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-4.3/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v4_3/ApacheHttpClientTelemetryBuilder.java @@ -98,7 +98,7 @@ public ApacheHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public ApacheHttpClientTelemetryBuilder setSpanNameExtractor( Function< - SpanNameExtractor, + SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); diff --git a/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java b/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java index e9a5eb273de0..b9b98eb5d4a6 100644 --- a/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java +++ b/instrumentation/apache-httpclient/apache-httpclient-5.2/library/src/main/java/io/opentelemetry/instrumentation/apachehttpclient/v5_2/ApacheHttpClient5TelemetryBuilder.java @@ -100,7 +100,7 @@ public ApacheHttpClient5TelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public ApacheHttpClient5TelemetryBuilder setSpanNameExtractor( Function< - SpanNameExtractor, + SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); 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 9b5cd6fb05a9..960860904f82 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 @@ -178,14 +178,13 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( } /** Sets custom client {@link SpanNameExtractor} via transform function. */ - @SuppressWarnings({"rawtypes", "unchecked"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setClientSpanNameExtractor( Function< - SpanNameExtractor, - ? extends SpanNameExtractor> + SpanNameExtractor, + ? extends SpanNameExtractor> clientSpanNameExtractor) { - clientBuilder.setSpanNameExtractor((Function) clientSpanNameExtractor); + clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; } diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java index 1e5cbd0c1490..3d6513817df8 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java @@ -95,7 +95,7 @@ public JavaHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public JavaHttpClientTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java index a914f73d266f..ec5c8b379d50 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/JettyClientTelemetryBuilder.java @@ -112,7 +112,7 @@ public JettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public JettyClientTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java index 427980f0d244..a976fe7a2f30 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/JettyClientTelemetryBuilder.java @@ -112,7 +112,7 @@ public JettyClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public JettyClientTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java index 552db08382e0..6dafba2c124d 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/OkHttpTelemetryBuilder.java @@ -95,7 +95,7 @@ public OkHttpTelemetryBuilder setEmitExperimentalHttpClientMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public OkHttpTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java index 3eab8e96bf61..01f5ff935f3e 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java @@ -74,7 +74,7 @@ public SpringWebTelemetryBuilder setCapturedResponseHeaders(List respons /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index e8387880cd32..31ca87889527 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -169,7 +169,7 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( /** Sets custom client {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> clientSpanNameExtractor) { clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; From 96473d097152f3b629287f00bbc1a5f4fd065cf6 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 10:39:01 +0200 Subject: [PATCH 06/11] use ? super --- .../internal/DefaultHttpServerInstrumenterBuilder.java | 4 ++-- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 7 +++---- .../spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java | 2 +- .../spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java | 2 +- .../spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java index b229a7126e48..b3c7976f6c8a 100644 --- a/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java +++ b/instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/builder/internal/DefaultHttpServerInstrumenterBuilder.java @@ -54,7 +54,7 @@ public final class DefaultHttpServerInstrumenterBuilder { private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; @Nullable private TextMapGetter headerGetter; - private Function, ? extends SpanNameExtractor> + private Function, ? extends SpanNameExtractor> spanNameExtractorTransformer = Function.identity(); private final HttpServerRouteBuilder httpServerRouteBuilder; private final HttpServerAttributesGetter attributesGetter; @@ -162,7 +162,7 @@ public DefaultHttpServerInstrumenterBuilder setHeaderGetter( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public DefaultHttpServerInstrumenterBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { this.spanNameExtractorTransformer = spanNameExtractorTransformer; return this; 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 960860904f82..b1819acb0a19 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 @@ -189,14 +189,13 @@ public ArmeriaTelemetryBuilder setClientSpanNameExtractor( } /** Sets custom server {@link SpanNameExtractor} via transform function. */ - @SuppressWarnings({"rawtypes", "unchecked"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setServerSpanNameExtractor( Function< - SpanNameExtractor, - ? extends SpanNameExtractor> + SpanNameExtractor, + ? extends SpanNameExtractor> serverSpanNameExtractor) { - serverBuilder.setSpanNameExtractor((Function) serverSpanNameExtractor); + serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); return this; } diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index 31ca87889527..dd7a069d0383 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -179,7 +179,7 @@ public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setServerSpanNameExtractor( Function< - SpanNameExtractor, + SpanNameExtractor, ? extends SpanNameExtractor> serverSpanNameExtractor) { serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index 588263aff6e6..4acb087b72b5 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -74,7 +74,7 @@ public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List resp @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setSpanNameExtractor( Function< - SpanNameExtractor, + SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { builder.setSpanNameExtractor(spanNameExtractor); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 7978664dd053..abf49f90fd25 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -73,7 +73,7 @@ public SpringWebMvcTelemetryBuilder setCapturedResponseHeaders(List resp @CanIgnoreReturnValue public SpringWebMvcTelemetryBuilder setSpanNameExtractor( Function< - SpanNameExtractor, + SpanNameExtractor, ? extends SpanNameExtractor> spanNameExtractor) { builder.setSpanNameExtractor(spanNameExtractor); From 32f87daa23fd7136cc180966c3ef2be03f10c2ca Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 10:39:33 +0200 Subject: [PATCH 07/11] use ? super --- .../httpclient/JavaHttpClientTelemetryBuilder.java | 4 +++- .../spring/web/v3_1/SpringWebTelemetryBuilder.java | 4 +++- .../spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java index 3d6513817df8..66d8f753c300 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/JavaHttpClientTelemetryBuilder.java @@ -95,7 +95,9 @@ public JavaHttpClientTelemetryBuilder setEmitExperimentalHttpClientMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public JavaHttpClientTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java index 01f5ff935f3e..36fde223c3ec 100644 --- a/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java +++ b/instrumentation/spring/spring-web/spring-web-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/web/v3_1/SpringWebTelemetryBuilder.java @@ -74,7 +74,9 @@ public SpringWebTelemetryBuilder setCapturedResponseHeaders(List respons /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public SpringWebTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java index dd7a069d0383..e004ee7e9a70 100644 --- a/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java +++ b/instrumentation/spring/spring-webflux/spring-webflux-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webflux/v5_3/SpringWebfluxTelemetryBuilder.java @@ -169,7 +169,9 @@ public SpringWebfluxTelemetryBuilder setEmitExperimentalHttpServerTelemetry( /** Sets custom client {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public SpringWebfluxTelemetryBuilder setClientSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> clientSpanNameExtractor) { clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; From 8dbef7984fc318dfff0d6657a715961a12a504ec Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 25 Jul 2024 10:54:27 +0200 Subject: [PATCH 08/11] add addServerAttributeExtractor --- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 b1819acb0a19..9b3c17c068c8 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 @@ -79,6 +79,18 @@ public ArmeriaTelemetryBuilder addClientAttributeExtractor( 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 ArmeriaTelemetryBuilder addServerAttributeExtractor( + AttributesExtractor attributesExtractor) { + serverBuilder.addAttributesExtractor(attributesExtractor); + return this; + } + /** Sets the {@code peer.service} attribute for http client spans. */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setPeerService(String peerService) { From 438341332fab199465d7aa851e9ce1565514376e Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 5 Aug 2024 12:55:19 +0200 Subject: [PATCH 09/11] add separate methods for client/server --- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) 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 9b3c17c068c8..87c0a6696d78 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 @@ -43,6 +43,13 @@ public final class ArmeriaTelemetryBuilder { serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); } + /** + * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented + * items. + * + * @deprecated Use {@link #setClientStatusExtractor(Function)} or {@link + * #setServerStatusExtractor(Function)} instead. + */ @SuppressWarnings({"unchecked", "rawtypes"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setStatusExtractor( @@ -55,9 +62,32 @@ public ArmeriaTelemetryBuilder setStatusExtractor( return this; } + @CanIgnoreReturnValue + public DefaultHttpClientInstrumenterBuilder + setClientStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + return clientBuilder.setStatusExtractor(statusExtractor); + } + + @CanIgnoreReturnValue + public DefaultHttpServerInstrumenterBuilder + setServerStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + return serverBuilder.setStatusExtractor(statusExtractor); + } + /** * 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. */ @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addAttributeExtractor( From a99b25abc8e4d5d094db575238d4112f0c8335be Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 5 Aug 2024 13:02:43 +0200 Subject: [PATCH 10/11] add separate methods for client/server --- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) 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 87c0a6696d78..ea9e357a62fc 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 @@ -44,8 +44,7 @@ public final class ArmeriaTelemetryBuilder { } /** - * Adds an additional {@link AttributesExtractor} to invoke to set attributes to instrumented - * items. + * Sets the status extractor for both client and server spans. * * @deprecated Use {@link #setClientStatusExtractor(Function)} or {@link * #setServerStatusExtractor(Function)} instead. @@ -62,24 +61,26 @@ public ArmeriaTelemetryBuilder setStatusExtractor( return this; } + /** Sets the status extractor for client spans. */ @CanIgnoreReturnValue - public DefaultHttpClientInstrumenterBuilder - setClientStatusExtractor( - Function< - SpanStatusExtractor, - ? extends SpanStatusExtractor> - statusExtractor) { - return clientBuilder.setStatusExtractor(statusExtractor); + public ArmeriaTelemetryBuilder setClientStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + clientBuilder.setStatusExtractor(statusExtractor); + return this; } + /** Sets the status extractor for server spans. */ @CanIgnoreReturnValue - public DefaultHttpServerInstrumenterBuilder - setServerStatusExtractor( - Function< - SpanStatusExtractor, - ? extends SpanStatusExtractor> - statusExtractor) { - return serverBuilder.setStatusExtractor(statusExtractor); + public ArmeriaTelemetryBuilder setServerStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + serverBuilder.setStatusExtractor(statusExtractor); + return this; } /** From e60b6793fc5b2884f1e7a9975b7ff0f77a7c0428 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 5 Aug 2024 14:38:53 +0200 Subject: [PATCH 11/11] add separate methods for client/server --- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 2 ++ .../v1_3/internal/ArmeriaHttpServerAttributesGetter.java | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) 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 ea9e357a62fc..5d6a17eb6586 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 @@ -49,6 +49,7 @@ public final class ArmeriaTelemetryBuilder { * @deprecated Use {@link #setClientStatusExtractor(Function)} or {@link * #setServerStatusExtractor(Function)} instead. */ + @Deprecated @SuppressWarnings({"unchecked", "rawtypes"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setStatusExtractor( @@ -90,6 +91,7 @@ public ArmeriaTelemetryBuilder setServerStatusExtractor( * @deprecated Use {@link #addClientAttributeExtractor(AttributesExtractor)} or {@link * #addServerAttributeExtractor(AttributesExtractor)} instead. */ + @Deprecated @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { diff --git a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java index e27ab8e8258f..5cef09ca7fd9 100644 --- a/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java +++ b/instrumentation/armeria/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/internal/ArmeriaHttpServerAttributesGetter.java @@ -70,10 +70,7 @@ public List getHttpResponseHeader( @Override @Nullable public String getHttpRoute(ServiceRequestContext ctx) { - if (ctx instanceof ServiceRequestContext) { - return ctx.config().route().patternString(); - } - return null; + return ctx.config().route().patternString(); } @Override