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..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 @@ -38,12 +38,18 @@ public final class ArmeriaTelemetryBuilder { ArmeriaTelemetryBuilder::getServerBuilder); } - @SuppressWarnings({"rawtypes", "unchecked"}) ArmeriaTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = ArmeriaInstrumenterBuilderFactory.getClientBuilder(openTelemetry); serverBuilder = ArmeriaInstrumenterBuilderFactory.getServerBuilder(openTelemetry); } + /** + * Sets the status extractor for both client and server spans. + * + * @deprecated Use {@link #setClientStatusExtractor(Function)} or {@link + * #setServerStatusExtractor(Function)} instead. + */ + @Deprecated @SuppressWarnings({"unchecked", "rawtypes"}) @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setStatusExtractor( @@ -56,10 +62,36 @@ public ArmeriaTelemetryBuilder setStatusExtractor( return this; } + /** Sets the status extractor for client spans. */ + @CanIgnoreReturnValue + public ArmeriaTelemetryBuilder setClientStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + clientBuilder.setStatusExtractor(statusExtractor); + return this; + } + + /** Sets the status extractor for server spans. */ + @CanIgnoreReturnValue + public ArmeriaTelemetryBuilder setServerStatusExtractor( + Function< + SpanStatusExtractor, + ? extends SpanStatusExtractor> + statusExtractor) { + serverBuilder.setStatusExtractor(statusExtractor); + return this; + } + /** * 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 @CanIgnoreReturnValue public ArmeriaTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { @@ -80,6 +112,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) { @@ -162,7 +206,6 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); - serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -175,32 +218,29 @@ public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public ArmeriaTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean 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> + SpanNameExtractor, + ? extends SpanNameExtractor> clientSpanNameExtractor) { - clientBuilder.setSpanNameExtractor((Function) clientSpanNameExtractor); + clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; } /** 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/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(