From fbc476fba9d9c6fd7bebe51f058bc5bd0970b124 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 22 Aug 2024 13:31:08 +0200 Subject: [PATCH 01/14] http server builder --- .../DefaultHttpClientInstrumenterBuilder.java | 4 + .../DefaultHttpServerInstrumenterBuilder.java | 9 ++ .../server/AkkaHttpServerSingletons.java | 42 +----- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 62 ++------- .../ArmeriaHttpClientAttributesGetter.java | 29 ++-- .../grizzly/GrizzlySingletons.java | 62 +++------ .../jetty/v12_0/Jetty12Singletons.java | 56 ++------ .../ktor/v1_0/KtorServerTracing.kt | 70 ++++------ .../ktor/v2_0/HttpClientInstrumentation.java | 10 +- .../ktor/v2_0/ServerInstrumentation.java | 12 +- .../v2_0/client/KtorClientTracingBuilder.kt | 72 +++------- .../ktor/v2_0/internal/KtorBuilderUtil.kt | 24 ++++ .../ktor/v2_0/server/KtorServerTracing.kt | 77 +++++------ .../KubernetesClientSingletons.java | 43 +++--- .../LibertyDispatcherSingletons.java | 44 +----- .../server/PekkoHttpServerSingletons.java | 40 +----- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 127 ++++-------------- .../restlet/v1_1/RestletSingletons.java | 18 +-- .../restlet/v1_1/RestletTelemetry.java | 5 - .../restlet/v1_1/RestletTelemetryBuilder.java | 66 ++------- .../{ => internal}/RestletHeadersGetter.java | 2 +- .../RestletHttpAttributesGetter.java | 4 +- .../RestletTelemetryBuilderFactory.java | 28 ++++ .../restlet/v2_0/RestletSingletons.java | 26 +--- .../restlet/v2_0/RestletTelemetryBuilder.java | 55 ++------ .../internal/RestletHttpAttributesGetter.java | 6 +- .../internal/RestletInstrumenterFactory.java | 57 -------- .../RestletTelemetryBuilderFactory.java | 26 ++++ .../servlet/ServletInstrumenterBuilder.java | 78 +++++------ .../common/TomcatInstrumenterFactory.java | 60 +++------ .../undertow/UndertowSingletons.java | 67 +++------ .../JavaagentHttpServerInstrumenters.java | 12 ++ 32 files changed, 407 insertions(+), 886 deletions(-) create mode 100644 instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt rename instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/{ => internal}/RestletHeadersGetter.java (92%) rename instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/{ => internal}/RestletHttpAttributesGetter.java (95%) create mode 100644 instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java delete mode 100644 instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java create mode 100644 instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java 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 78af582fe689..1a9b85240edd 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 @@ -224,6 +224,10 @@ InstrumenterBuilder instrumenterBuilder( return Instrumenter.builder(openTelemetry, instrumentationName, spanNameExtractor); } + public String getInstrumentationName() { + return instrumentationName; + } + @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder configure(CommonConfig config) { set(config::getKnownHttpRequestMethods, this::setKnownMethods); 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 0085f8c09a13..6124bf249380 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 @@ -172,6 +172,15 @@ public DefaultHttpServerInstrumenterBuilder setBuilderCustomi } public Instrumenter build() { + InstrumenterBuilder builder = builder(); + + if (headerGetter != null) { + return builder.buildServerInstrumenter(headerGetter); + } + return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); + } + + public InstrumenterBuilder builder() { SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java index af0a3d61da82..a52da0636ffc 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/akkahttp/server/AkkaHttpServerSingletons.java @@ -7,17 +7,8 @@ import akka.http.scaladsl.model.HttpRequest; import akka.http.scaladsl.model.HttpResponse; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil; public final class AkkaHttpServerSingletons { @@ -25,32 +16,11 @@ public final class AkkaHttpServerSingletons { private static final Instrumenter INSTRUMENTER; static { - AkkaHttpServerAttributesGetter httpAttributesGetter = new AkkaHttpServerAttributesGetter(); - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - AkkaHttpUtil.instrumentationName(), - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - INSTRUMENTER = builder.buildServerInstrumenter(AkkaHttpServerHeaders.INSTANCE); + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + AkkaHttpUtil.instrumentationName(), + new AkkaHttpServerAttributesGetter(), + AkkaHttpServerHeaders.INSTANCE); } public static Instrumenter instrumenter() { 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 5d6a17eb6586..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 @@ -38,18 +38,12 @@ 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( @@ -62,36 +56,10 @@ 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) { @@ -112,18 +80,6 @@ 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) { @@ -206,6 +162,7 @@ public ArmeriaTelemetryBuilder setKnownMethods(Set knownMethods) { public ArmeriaTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -218,29 +175,32 @@ 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(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> + SpanNameExtractor, + ? extends SpanNameExtractor> serverSpanNameExtractor) { - serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); + serverBuilder.setSpanNameExtractor((Function) 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 29dfa4aca00b..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 @@ -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(ClientRequestContext ctx) { + public String getHttpRequestMethod(RequestContext ctx) { return ctx.method().name(); } @Override - public String getUrlFull(ClientRequestContext ctx) { + public String getUrlFull(RequestContext ctx) { HttpRequest request = request(ctx); StringBuilder uri = new StringBuilder(); String scheme = request.scheme(); @@ -61,14 +61,14 @@ public String getUrlFull(ClientRequestContext ctx) { } @Override - public List getHttpRequestHeader(ClientRequestContext ctx, String name) { + public List getHttpRequestHeader(RequestContext ctx, String name) { return request(ctx).headers().getAll(name); } @Override @Nullable public Integer getHttpResponseStatusCode( - ClientRequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { + RequestContext ctx, RequestLog requestLog, @Nullable Throwable error) { HttpStatus status = requestLog.responseHeaders().status(); if (!status.equals(HttpStatus.UNKNOWN)) { return status.code(); @@ -78,18 +78,17 @@ public Integer getHttpResponseStatusCode( @Override public List getHttpResponseHeader( - ClientRequestContext ctx, RequestLog requestLog, String name) { + RequestContext ctx, RequestLog requestLog, String name) { return requestLog.responseHeaders().getAll(name); } @Override - public String getNetworkProtocolName(ClientRequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolName(RequestContext ctx, @Nullable RequestLog requestLog) { return "http"; } @Override - public String getNetworkProtocolVersion( - ClientRequestContext ctx, @Nullable RequestLog requestLog) { + public String getNetworkProtocolVersion(RequestContext ctx, @Nullable RequestLog requestLog) { SessionProtocol protocol = requestLog != null ? requestLog.sessionProtocol() : ctx.sessionProtocol(); return protocol.isMultiplex() ? "2" : "1.1"; @@ -97,7 +96,7 @@ public String getNetworkProtocolVersion( @Nullable @Override - public String getServerAddress(ClientRequestContext ctx) { + public String getServerAddress(RequestContext ctx) { String authority = authority(ctx); if (authority == null) { return null; @@ -108,7 +107,7 @@ public String getServerAddress(ClientRequestContext ctx) { @Nullable @Override - public Integer getServerPort(ClientRequestContext ctx) { + public Integer getServerPort(RequestContext ctx) { String authority = authority(ctx); if (authority == null) { return null; @@ -127,12 +126,12 @@ public Integer getServerPort(ClientRequestContext ctx) { @Override @Nullable public InetSocketAddress getNetworkPeerInetSocketAddress( - ClientRequestContext ctx, @Nullable RequestLog requestLog) { + RequestContext ctx, @Nullable RequestLog requestLog) { return RequestContextAccess.remoteAddress(ctx); } @Nullable - private static String authority(ClientRequestContext ctx) { + private static String authority(RequestContext 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 @@ -150,7 +149,7 @@ private static String authority(ClientRequestContext ctx) { return request.authority(); } - private static HttpRequest request(ClientRequestContext ctx) { + private static HttpRequest request(RequestContext ctx) { HttpRequest request = ctx.request(); if (request == null) { throw new IllegalStateException( diff --git a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java index 7633c3bf7d56..f19965d65ad4 100644 --- a/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java +++ b/instrumentation/grizzly-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java @@ -5,17 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.grizzly; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; @@ -25,43 +16,22 @@ public final class GrizzlySingletons { private static final Instrumenter INSTRUMENTER; static { - GrizzlyHttpAttributesGetter httpAttributesGetter = new GrizzlyHttpAttributesGetter(); - - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - "io.opentelemetry.grizzly-2.3", - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } INSTRUMENTER = - builder - .addContextCustomizer( - (context, request, attributes) -> - new AppServerBridge.Builder() - .captureServletAttributes() - .recordException() - .init(context)) - .addContextCustomizer( - (context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context)) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .buildServerInstrumenter(HttpRequestHeadersGetter.INSTANCE); + JavaagentHttpServerInstrumenters.create( + "io.opentelemetry.grizzly-2.3", + new GrizzlyHttpAttributesGetter(), + HttpRequestHeadersGetter.INSTANCE, + builder -> + builder + .addContextCustomizer( + (context, request, attributes) -> + new AppServerBridge.Builder() + .captureServletAttributes() + .recordException() + .init(context)) + .addContextCustomizer( + (context, httpRequestPacket, startAttributes) -> + GrizzlyErrorHolder.init(context))); } public static Instrumenter instrumenter() { diff --git a/instrumentation/jetty/jetty-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0/Jetty12Singletons.java b/instrumentation/jetty/jetty-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0/Jetty12Singletons.java index b9866c2cef93..4017379dc172 100644 --- a/instrumentation/jetty/jetty-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0/Jetty12Singletons.java +++ b/instrumentation/jetty/jetty-12.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jetty/v12_0/Jetty12Singletons.java @@ -5,17 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.jetty.v12_0; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Response; @@ -26,39 +17,18 @@ public final class Jetty12Singletons { private static final Instrumenter INSTRUMENTER; static { - Jetty12HttpAttributesGetter httpAttributesGetter = new Jetty12HttpAttributesGetter(); - - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - INSTRUMENTATION_NAME, - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - (context, request, attributes) -> - new AppServerBridge.Builder() - .captureServletAttributes() - .recordException() - .init(context)) - .addOperationMetrics(HttpServerMetrics.get()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - INSTRUMENTER = builder.buildServerInstrumenter(Jetty12TextMapGetter.INSTANCE); + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + INSTRUMENTATION_NAME, + new Jetty12HttpAttributesGetter(), + Jetty12TextMapGetter.INSTANCE, + builder -> + builder.addContextCustomizer( + (context, request, attributes) -> + new AppServerBridge.Builder() + .captureServletAttributes() + .recordException() + .init(context))); } private static final Jetty12Helper HELPER = new Jetty12Helper(INSTRUMENTER); diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 949efcf2c313..99e364af89b5 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -14,17 +14,15 @@ import io.ktor.util.pipeline.* import io.opentelemetry.api.OpenTelemetry import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement +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.SpanKindExtractor +import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor import kotlinx.coroutines.withContext class KtorServerTracing private constructor( @@ -32,30 +30,33 @@ class KtorServerTracing private constructor( ) { class Configuration { - internal lateinit var openTelemetry: OpenTelemetry - - internal val additionalExtractors = mutableListOf>() - - internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) - - internal val httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) - - internal val httpServerRouteBuilder = HttpServerRoute.builder(KtorHttpServerAttributesGetter.INSTANCE) - - internal var statusExtractor: - (SpanStatusExtractor) -> SpanStatusExtractor = { a -> a } + internal lateinit var builder: DefaultHttpServerInstrumenterBuilder internal var spanKindExtractor: (SpanKindExtractor) -> SpanKindExtractor = { a -> a } fun setOpenTelemetry(openTelemetry: OpenTelemetry) { - this.openTelemetry = openTelemetry + this.builder = + DefaultHttpServerInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + KtorHttpServerAttributesGetter.INSTANCE + ) } fun setStatusExtractor( extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { - this.statusExtractor = extractor + builder.setStatusExtractor { prevExtractor -> + SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? -> + @Suppress("UNCHECKED_CAST") + extractor(prevExtractor as SpanStatusExtractor) + .extract(spanStatusBuilder, request, response, throwable) + } + } } fun setSpanKindExtractor(extractor: (SpanKindExtractor) -> SpanKindExtractor) { @@ -63,24 +64,22 @@ class KtorServerTracing private constructor( } fun addAttributeExtractor(extractor: AttributesExtractor) { - additionalExtractors.add(extractor) + builder.addAttributesExtractor(extractor) } fun setCapturedRequestHeaders(requestHeaders: List) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders) + builder.setCapturedRequestHeaders(requestHeaders) } fun setCapturedResponseHeaders(responseHeaders: List) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders) + builder.setCapturedResponseHeaders(responseHeaders) } fun setKnownMethods(knownMethods: Set) { - httpAttributesExtractorBuilder.setKnownMethods(knownMethods) - httpSpanNameExtractorBuilder.setKnownMethods(knownMethods) - httpServerRouteBuilder.setKnownMethods(knownMethods) + builder.setKnownMethods(knownMethods) } - internal fun isOpenTelemetryInitialized(): Boolean = this::openTelemetry.isInitialized + internal fun isOpenTelemetryInitialized(): Boolean = this::builder.isInitialized } private fun start(call: ApplicationCall): Context? { @@ -97,7 +96,7 @@ class KtorServerTracing private constructor( } companion object Feature : ApplicationFeature { - private val INSTRUMENTATION_NAME = "io.opentelemetry.ktor-1.0" + private const val INSTRUMENTATION_NAME = "io.opentelemetry.ktor-1.0" private val contextKey = AttributeKey("OpenTelemetry") private val errorKey = AttributeKey("OpenTelemetryException") @@ -111,25 +110,8 @@ class KtorServerTracing private constructor( throw IllegalArgumentException("OpenTelemetry must be set") } - val httpAttributesGetter = KtorHttpServerAttributesGetter.INSTANCE - - val instrumenterBuilder = Instrumenter.builder( - configuration.openTelemetry, - INSTRUMENTATION_NAME, - configuration.httpSpanNameExtractorBuilder.build() - ) - - configuration.additionalExtractors.forEach { instrumenterBuilder.addAttributesExtractor(it) } - - with(instrumenterBuilder) { - setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))) - addAttributesExtractor(configuration.httpAttributesExtractorBuilder.build()) - addOperationMetrics(HttpServerMetrics.get()) - addContextCustomizer(configuration.httpServerRouteBuilder.build()) - } - val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( - instrumenterBuilder, + configuration.builder.builder(), ApplicationRequestGetter, configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java index 43f89f9968a5..f1b54532f728 100644 --- a/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java +++ b/instrumentation/ktor/ktor-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ktor/v2_0/HttpClientInstrumentation.java @@ -13,9 +13,9 @@ import io.ktor.client.HttpClientConfig; import io.ktor.client.engine.HttpClientEngineConfig; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracing; import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder; +import io.opentelemetry.instrumentation.ktor.v2_0.internal.KtorBuilderUtil; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -54,12 +54,8 @@ public static class SetupFunction implements Function1>() - private val httpAttributesExtractorBuilder = HttpClientAttributesExtractor.builder(KtorHttpClientAttributesGetter) - private val httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(KtorHttpClientAttributesGetter) - private var emitExperimentalHttpClientMetrics = false + private lateinit var clientBuilder: DefaultHttpClientInstrumenterBuilder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { - this.openTelemetry = openTelemetry + this.clientBuilder = DefaultHttpClientInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + KtorHttpClientAttributesGetter + ) } @Deprecated( @@ -49,7 +48,7 @@ class KtorClientTracingBuilder { fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) fun capturedRequestHeaders(headers: Iterable) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(headers.toList()) + clientBuilder.setCapturedRequestHeaders(headers.toList()) } @Deprecated( @@ -67,7 +66,7 @@ class KtorClientTracingBuilder { fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) fun capturedResponseHeaders(headers: Iterable) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(headers.toList()) + clientBuilder.setCapturedResponseHeaders(headers.toList()) } @Deprecated( @@ -84,10 +83,7 @@ class KtorClientTracingBuilder { fun knownMethods(methods: Iterable) = knownMethods(methods.map { it.value }) fun knownMethods(methods: Iterable) { - methods.toSet().apply { - httpAttributesExtractorBuilder.setKnownMethods(this) - httpSpanNameExtractorBuilder.setKnownMethods(this) - } + clientBuilder.setKnownMethods(methods.toSet()) } @Deprecated("Please use method `attributeExtractor`") @@ -105,7 +101,7 @@ class KtorClientTracingBuilder { fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - additionalExtractors.add( + this.clientBuilder.addAttributeExtractor( object : AttributesExtractor { override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: HttpRequestData) { builder.onStart(OnStartData(attributes, parentContext, request)) @@ -164,35 +160,11 @@ class KtorClientTracingBuilder { } fun emitExperimentalHttpClientMetrics() { - emitExperimentalHttpClientMetrics = true + clientBuilder.setEmitExperimentalHttpClientMetrics(true) } - internal fun build(): KtorClientTracing { - val initializedOpenTelemetry = openTelemetry - ?: throw IllegalArgumentException("OpenTelemetry must be set") - - val instrumenterBuilder = Instrumenter.builder( - initializedOpenTelemetry, - INSTRUMENTATION_NAME, - httpSpanNameExtractorBuilder.build() - ) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(KtorHttpClientAttributesGetter)) - .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addOperationMetrics(HttpClientMetrics.get()) - - if (emitExperimentalHttpClientMetrics) { - instrumenterBuilder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(KtorHttpClientAttributesGetter)) - .addOperationMetrics(HttpClientExperimentalMetrics.get()) - } - - val instrumenter = instrumenterBuilder - .buildInstrumenter(alwaysClient()) - - return KtorClientTracing( - instrumenter = instrumenter, - propagators = initializedOpenTelemetry.propagators, - ) - } + internal fun build(): KtorClientTracing = KtorClientTracing( + instrumenter = clientBuilder.build(), + propagators = clientBuilder.openTelemetry.propagators, + ) } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt new file mode 100644 index 000000000000..10bb56d5a720 --- /dev/null +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/internal/KtorBuilderUtil.kt @@ -0,0 +1,24 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ktor.v2_0.internal + +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.server.request.* +import io.ktor.server.response.* +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.client.KtorClientTracingBuilder +import io.opentelemetry.instrumentation.ktor.v2_0.server.KtorServerTracing + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +object KtorBuilderUtil { + lateinit var clientBuilderExtractor: (KtorClientTracingBuilder) -> DefaultHttpClientInstrumenterBuilder + lateinit var serverBuilderExtractor: (KtorServerTracing.Configuration) -> DefaultHttpServerInstrumenterBuilder +} diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 2e4c203eb3ed..e6bd2e2fc2cf 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -17,19 +17,17 @@ import io.opentelemetry.api.common.AttributesBuilder import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement +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.SpanKindExtractor import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusBuilder import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor import io.opentelemetry.instrumentation.ktor.v2_0.InstrumentationProperties.INSTRUMENTATION_NAME +import io.opentelemetry.instrumentation.ktor.v2_0.internal.KtorBuilderUtil import kotlinx.coroutines.withContext class KtorServerTracing private constructor( @@ -37,24 +35,24 @@ class KtorServerTracing private constructor( ) { class Configuration { - internal lateinit var openTelemetry: OpenTelemetry - - internal val additionalExtractors = mutableListOf>() - - internal val httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) - - internal val httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(KtorHttpServerAttributesGetter.INSTANCE) - - internal val httpServerRouteBuilder = HttpServerRoute.builder(KtorHttpServerAttributesGetter.INSTANCE) + companion object { + init { + KtorBuilderUtil.serverBuilderExtractor = { it.serverBuilder } + } + } - internal var statusExtractor: - (SpanStatusExtractor) -> SpanStatusExtractor = { a -> a } + internal lateinit var serverBuilder: DefaultHttpServerInstrumenterBuilder internal var spanKindExtractor: (SpanKindExtractor) -> SpanKindExtractor = { a -> a } fun setOpenTelemetry(openTelemetry: OpenTelemetry) { - this.openTelemetry = openTelemetry + this.serverBuilder = + DefaultHttpServerInstrumenterBuilder( + INSTRUMENTATION_NAME, + openTelemetry, + KtorHttpServerAttributesGetter.INSTANCE + ) } @Deprecated("Please use method `spanStatusExtractor`") @@ -67,12 +65,16 @@ class KtorServerTracing private constructor( } fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { - statusExtractor = { prevExtractor -> - SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, - request: ApplicationRequest, - response: ApplicationResponse?, - throwable: Throwable? -> - extract(SpanStatusData(spanStatusBuilder, request, response, throwable), prevExtractor) + serverBuilder.setStatusExtractor { prevExtractor -> + SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, + request: ApplicationRequest, + response: ApplicationResponse?, + throwable: Throwable? -> + @Suppress("UNCHECKED_CAST") + extract( + SpanStatusData(spanStatusBuilder, request, response, throwable), + prevExtractor as SpanStatusExtractor + ) } } } @@ -113,7 +115,7 @@ class KtorServerTracing private constructor( fun attributeExtractor(extractorBuilder: ExtractorBuilder.() -> Unit = {}) { val builder = ExtractorBuilder().apply(extractorBuilder).build() - additionalExtractors.add( + serverBuilder.addAttributesExtractor( object : AttributesExtractor { override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: ApplicationRequest) { builder.onStart(OnStartData(attributes, parentContext, request)) @@ -168,7 +170,7 @@ class KtorServerTracing private constructor( fun capturedRequestHeaders(vararg headers: String) = capturedRequestHeaders(headers.asIterable()) fun capturedRequestHeaders(headers: Iterable) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(headers.toList()) + serverBuilder.setCapturedRequestHeaders(headers.toList()) } @Deprecated( @@ -180,7 +182,7 @@ class KtorServerTracing private constructor( fun capturedResponseHeaders(vararg headers: String) = capturedResponseHeaders(headers.asIterable()) fun capturedResponseHeaders(headers: Iterable) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(headers.toList()) + serverBuilder.setCapturedResponseHeaders(headers.toList()) } @Deprecated( @@ -198,13 +200,11 @@ class KtorServerTracing private constructor( fun knownMethods(methods: Iterable) { methods.toSet().apply { - httpAttributesExtractorBuilder.setKnownMethods(this) - httpSpanNameExtractorBuilder.setKnownMethods(this) - httpServerRouteBuilder.setKnownMethods(this) + serverBuilder.setKnownMethods(this) } } - internal fun isOpenTelemetryInitialized(): Boolean = this::openTelemetry.isInitialized + internal fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized } private fun start(call: ApplicationCall): Context? { @@ -232,25 +232,8 @@ class KtorServerTracing private constructor( require(configuration.isOpenTelemetryInitialized()) { "OpenTelemetry must be set" } - val httpAttributesGetter = KtorHttpServerAttributesGetter.INSTANCE - - val instrumenterBuilder = Instrumenter.builder( - configuration.openTelemetry, - INSTRUMENTATION_NAME, - configuration.httpSpanNameExtractorBuilder.build() - ) - - configuration.additionalExtractors.forEach { instrumenterBuilder.addAttributesExtractor(it) } - - with(instrumenterBuilder) { - setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))) - addAttributesExtractor(configuration.httpAttributesExtractorBuilder.build()) - addOperationMetrics(HttpServerMetrics.get()) - addContextCustomizer(configuration.httpServerRouteBuilder.build()) - } - val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( - instrumenterBuilder, + configuration.serverBuilder.builder(), ApplicationRequestGetter, configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java index 31bad69e3bbb..5d97acc910e9 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java @@ -5,16 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.kubernetesclient; -import static io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor.alwaysClient; - import io.kubernetes.client.openapi.ApiResponse; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.context.Context; import io.opentelemetry.context.propagation.ContextPropagators; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpClientInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; import okhttp3.Request; @@ -28,28 +24,23 @@ public class KubernetesClientSingletons { private static final ContextPropagators CONTEXT_PROPAGATORS; static { - KubernetesHttpAttributesGetter httpAttributesGetter = new KubernetesHttpAttributesGetter(); - - InstrumenterBuilder> instrumenterBuilder = - Instrumenter.>builder( - GlobalOpenTelemetry.get(), + INSTRUMENTER = + new DefaultHttpClientInstrumenterBuilder<>( "io.opentelemetry.kubernetes-client-7.0", - request -> KubernetesRequestDigest.parse(request).toString()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpClientAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getClientRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getClientResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()); - - if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { - instrumenterBuilder.addAttributesExtractor(new KubernetesExperimentalAttributesExtractor()); - } - - // Initialize with .newInstrumenter(alwaysClient()) instead of .newClientInstrumenter(..) - // because Request is immutable so context must be injected manually - INSTRUMENTER = instrumenterBuilder.buildInstrumenter(alwaysClient()); + GlobalOpenTelemetry.get(), + new KubernetesHttpAttributesGetter()) + .configure(AgentCommonConfig.get()) + .setBuilderCustomizer( + instrumenterBuilder -> { + if (CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES) { + instrumenterBuilder.addAttributesExtractor( + new KubernetesExperimentalAttributesExtractor()); + } + }) + .setSpanNameExtractor( + requestSpanNameExtractor -> + request -> KubernetesRequestDigest.parse(request).toString()) + .build(); CONTEXT_PROPAGATORS = GlobalOpenTelemetry.getPropagators(); } diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java index 5dc10034fd21..609a6824b9e2 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -5,17 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.liberty.dispatcher; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; public final class LibertyDispatcherSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.liberty-dispatcher-20.0"; @@ -23,34 +14,11 @@ public final class LibertyDispatcherSingletons { private static final Instrumenter INSTRUMENTER; static { - LibertyDispatcherHttpAttributesGetter httpAttributesGetter = - new LibertyDispatcherHttpAttributesGetter(); - - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - INSTRUMENTATION_NAME, - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - INSTRUMENTER = builder.buildServerInstrumenter(LibertyDispatcherRequestGetter.INSTANCE); + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + INSTRUMENTATION_NAME, + new LibertyDispatcherHttpAttributesGetter(), + LibertyDispatcherRequestGetter.INSTANCE); } public static Instrumenter instrumenter() { diff --git a/instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerSingletons.java b/instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerSingletons.java index 8618492181d6..3c865385e14d 100644 --- a/instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerSingletons.java +++ b/instrumentation/pekko/pekko-http-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pekkohttp/v1_0/server/PekkoHttpServerSingletons.java @@ -5,17 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.server; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.instrumentation.pekkohttp.v1_0.PekkoHttpUtil; import org.apache.pekko.http.scaladsl.model.HttpRequest; import org.apache.pekko.http.scaladsl.model.HttpResponse; @@ -25,30 +16,11 @@ public final class PekkoHttpServerSingletons { private static final Instrumenter INSTRUMENTER; static { - PekkoHttpServerAttributesGetter httpAttributesGetter = new PekkoHttpServerAttributesGetter(); - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - PekkoHttpUtil.instrumentationName(), - HttpSpanNameExtractor.create(httpAttributesGetter)) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - INSTRUMENTER = builder.buildServerInstrumenter(PekkoHttpServerHeaders.INSTANCE); + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + PekkoHttpUtil.instrumentationName(), + new PekkoHttpServerAttributesGetter(), + PekkoHttpServerHeaders.INSTANCE); } public static Instrumenter instrumenter() { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 1542d5070dab..5986f1bd4615 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -7,25 +7,12 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -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.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 java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -39,38 +26,18 @@ public final class RatpackTelemetryBuilder { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.ratpack-1.7"; - private final OpenTelemetry openTelemetry; - - private final List> additionalExtractors = - new ArrayList<>(); - private final HttpClientAttributesExtractorBuilder - httpClientAttributesExtractorBuilder = - HttpClientAttributesExtractor.builder(RatpackHttpClientAttributesGetter.INSTANCE); - private final HttpServerAttributesExtractorBuilder - httpServerAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(RatpackHttpAttributesGetter.INSTANCE); - - private final HttpSpanNameExtractorBuilder httpClientSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(RatpackHttpClientAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpServerSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(RatpackHttpAttributesGetter.INSTANCE); - - private Function, ? extends SpanNameExtractor> - clientSpanNameExtractorTransformer = Function.identity(); - private Function, ? extends SpanNameExtractor> - serverSpanNameExtractorTransformer = Function.identity(); - - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(RatpackHttpAttributesGetter.INSTANCE); - - private final List> - additionalHttpClientExtractors = new ArrayList<>(); - - private boolean emitExperimentalHttpClientMetrics = false; - private boolean emitExperimentalHttpServerMetrics = false; + private final DefaultHttpClientInstrumenterBuilder clientBuilder; + private final DefaultHttpServerInstrumenterBuilder serverBuilder; RatpackTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + clientBuilder = + new DefaultHttpClientInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, RatpackHttpClientAttributesGetter.INSTANCE) + .setHeaderSetter(RequestHeaderSetter.INSTANCE); + serverBuilder = + new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, RatpackHttpAttributesGetter.INSTANCE) + .setHeaderGetter(RatpackGetter.INSTANCE); } /** @@ -80,14 +47,14 @@ public final class RatpackTelemetryBuilder { @CanIgnoreReturnValue public RatpackTelemetryBuilder addAttributeExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + serverBuilder.addAttributesExtractor(attributesExtractor); return this; } @CanIgnoreReturnValue public RatpackTelemetryBuilder addClientAttributeExtractor( AttributesExtractor attributesExtractor) { - additionalHttpClientExtractors.add(attributesExtractor); + clientBuilder.addAttributeExtractor(attributesExtractor); return this; } @@ -98,7 +65,7 @@ public RatpackTelemetryBuilder addClientAttributeExtractor( */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedServerRequestHeaders(List requestHeaders) { - httpServerAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + serverBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -109,7 +76,7 @@ public RatpackTelemetryBuilder setCapturedServerRequestHeaders(List requ */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedServerResponseHeaders(List responseHeaders) { - httpServerAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + serverBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -120,7 +87,7 @@ public RatpackTelemetryBuilder setCapturedServerResponseHeaders(List res */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedClientRequestHeaders(List requestHeaders) { - httpClientAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + clientBuilder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -131,7 +98,7 @@ public RatpackTelemetryBuilder setCapturedClientRequestHeaders(List requ */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setCapturedClientResponseHeaders(List responseHeaders) { - httpClientAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + clientBuilder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -151,11 +118,8 @@ public RatpackTelemetryBuilder setCapturedClientResponseHeaders(List res */ @CanIgnoreReturnValue public RatpackTelemetryBuilder 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; } @@ -168,7 +132,7 @@ public RatpackTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( boolean emitExperimentalHttpClientMetrics) { - this.emitExperimentalHttpClientMetrics = emitExperimentalHttpClientMetrics; + clientBuilder.setEmitExperimentalHttpClientMetrics(emitExperimentalHttpClientMetrics); return this; } @@ -181,7 +145,7 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpClientMetrics( @CanIgnoreReturnValue public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + serverBuilder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -190,7 +154,7 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( public RatpackTelemetryBuilder setClientSpanNameExtractor( Function, ? extends SpanNameExtractor> clientSpanNameExtractor) { - this.clientSpanNameExtractorTransformer = clientSpanNameExtractor; + clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; } @@ -199,53 +163,12 @@ public RatpackTelemetryBuilder setClientSpanNameExtractor( public RatpackTelemetryBuilder setServerSpanNameExtractor( Function, ? extends SpanNameExtractor> serverSpanNameExtractor) { - this.serverSpanNameExtractorTransformer = serverSpanNameExtractor; + serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); return this; } /** Returns a new {@link RatpackTelemetry} with the configuration of this builder. */ public RatpackTelemetry build() { - return new RatpackTelemetry(buildServerInstrumenter(), httpClientInstrumenter()); - } - - private Instrumenter buildServerInstrumenter() { - RatpackHttpAttributesGetter httpAttributes = RatpackHttpAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - serverSpanNameExtractorTransformer.apply(httpServerSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes)) - .addAttributesExtractor(httpServerAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(httpServerRouteBuilder.build()); - if (emitExperimentalHttpServerMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributes)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - return builder.buildServerInstrumenter(RatpackGetter.INSTANCE); - } - - private Instrumenter httpClientInstrumenter() { - RatpackHttpClientAttributesGetter httpAttributes = RatpackHttpClientAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - clientSpanNameExtractorTransformer.apply(httpClientSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributes)) - .addAttributesExtractor(httpClientAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalHttpClientExtractors) - .addOperationMetrics(HttpClientMetrics.get()); - if (emitExperimentalHttpClientMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributes)) - .addOperationMetrics(HttpClientExperimentalMetrics.get()); - } - return builder.buildClientInstrumenter(RequestHeaderSetter.INSTANCE); + return new RatpackTelemetry(serverBuilder.build(), clientBuilder.build()); } } diff --git a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java index 0e2332b1e984..fbdb30e05d47 100644 --- a/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java +++ b/instrumentation/restlet/restlet-1.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletSingletons.java @@ -8,21 +8,21 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteGetter; -import io.opentelemetry.instrumentation.restlet.v1_1.RestletTelemetry; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.restlet.data.Request; import org.restlet.data.Response; public final class RestletSingletons { - private static final Instrumenter INSTRUMENTER = - RestletTelemetry.builder(GlobalOpenTelemetry.get()) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build() - .getServerInstrumenter(); + private static final Instrumenter INSTRUMENTER; + + static { + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + RestletTelemetryBuilderFactory.create(GlobalOpenTelemetry.get())); + } public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetry.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetry.java index ba29b9b6d64d..996a912004d0 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetry.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetry.java @@ -39,9 +39,4 @@ public static RestletTelemetryBuilder builder(OpenTelemetry openTelemetry) { public Filter newFilter(String path) { return new TracingFilter(serverInstrumenter, path); } - - /** Returns a server {@link Instrumenter}. */ - public Instrumenter getServerInstrumenter() { - return serverInstrumenter; - } } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index d5711895e9d5..0f7630e5a9c4 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -7,21 +7,11 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; -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.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.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 java.util.ArrayList; +import io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletTelemetryBuilderFactory; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -31,24 +21,10 @@ /** A builder of {@link RestletTelemetry}. */ public final class RestletTelemetryBuilder { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-1.1"; - - private final OpenTelemetry openTelemetry; - private final List> additionalExtractors = - new ArrayList<>(); - private final HttpServerAttributesExtractorBuilder - httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(RestletHttpAttributesGetter.INSTANCE); - private Function, ? extends SpanNameExtractor> - spanNameExtractorTransformer = Function.identity(); - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(RestletHttpAttributesGetter.INSTANCE); - private boolean emitExperimentalHttpServerMetrics = false; + private final DefaultHttpServerInstrumenterBuilder builder; RestletTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + builder = RestletTelemetryBuilderFactory.create(openTelemetry); } /** @@ -58,7 +34,7 @@ public final class RestletTelemetryBuilder { @CanIgnoreReturnValue public RestletTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -69,7 +45,7 @@ public RestletTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -80,7 +56,7 @@ public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHea */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -99,9 +75,7 @@ public RestletTelemetryBuilder setCapturedResponseHeaders(List responseH */ @CanIgnoreReturnValue public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { - httpAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -114,7 +88,7 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -123,7 +97,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( public RestletTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - this.spanNameExtractorTransformer = spanNameExtractorTransformer; + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -132,24 +106,6 @@ public RestletTelemetryBuilder setSpanNameExtractor( * RestletTelemetryBuilder}. */ public RestletTelemetry build() { - RestletHttpAttributesGetter httpAttributesGetter = RestletHttpAttributesGetter.INSTANCE; - SpanNameExtractor spanNameExtractor = - spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor(httpAttributesExtractorBuilder.build()) - .addAttributesExtractors(additionalExtractors) - .addContextCustomizer(httpServerRouteBuilder.build()) - .addOperationMetrics(HttpServerMetrics.get()); - if (emitExperimentalHttpServerMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - - return new RestletTelemetry(builder.buildServerInstrumenter(RestletHeadersGetter.INSTANCE)); + return new RestletTelemetry(builder.build()); } } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java similarity index 92% rename from instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java rename to instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java index 13d06f8ce1b9..7f137049d502 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHeadersGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHeadersGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.restlet.v1_1; +package io.opentelemetry.instrumentation.restlet.v1_1.internal; import io.opentelemetry.context.propagation.TextMapGetter; import java.util.Locale; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java similarity index 95% rename from instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java rename to instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java index 8378b494045e..64d52656d373 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletHttpAttributesGetter.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletHttpAttributesGetter.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.restlet.v1_1; +package io.opentelemetry.instrumentation.restlet.v1_1.internal; -import static io.opentelemetry.instrumentation.restlet.v1_1.RestletHeadersGetter.getHeaders; +import static io.opentelemetry.instrumentation.restlet.v1_1.internal.RestletHeadersGetter.getHeaders; import com.noelios.restlet.http.HttpCall; import com.noelios.restlet.http.HttpRequest; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java new file mode 100644 index 000000000000..a4a1f1cc2890 --- /dev/null +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.restlet.v1_1.internal; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import org.restlet.data.Request; +import org.restlet.data.Response; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class RestletTelemetryBuilderFactory { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-1.1"; + + private RestletTelemetryBuilderFactory() {} + + public static DefaultHttpServerInstrumenterBuilder create( + OpenTelemetry openTelemetry) { + return new DefaultHttpServerInstrumenterBuilder<>( + INSTRUMENTATION_NAME, openTelemetry, RestletHttpAttributesGetter.INSTANCE) + .setHeaderGetter(RestletHeadersGetter.INSTANCE); + } +} diff --git a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java index 0b8f6607964c..59d25f717636 100644 --- a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java +++ b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletSingletons.java @@ -7,36 +7,18 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteGetter; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletHttpAttributesGetter; -import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletInstrumenterFactory; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletTelemetryBuilderFactory; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; -import java.util.Collections; import org.restlet.Request; import org.restlet.Response; public final class RestletSingletons { private static final Instrumenter INSTRUMENTER = - RestletInstrumenterFactory.newServerInstrumenter( - GlobalOpenTelemetry.get(), - HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build(), - HttpSpanNameExtractor.builder(RestletHttpAttributesGetter.INSTANCE) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build(), - HttpServerRoute.builder(RestletHttpAttributesGetter.INSTANCE) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build(), - Collections.emptyList(), - AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()); + JavaagentHttpServerInstrumenters.create( + RestletTelemetryBuilderFactory.create(GlobalOpenTelemetry.get())); public static Instrumenter instrumenter() { return INSTRUMENTER; diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index 86cc9544a729..6c49897500ed 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -7,18 +7,11 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractorBuilder; -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.restlet.v2_0.internal.RestletHttpAttributesGetter; -import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletInstrumenterFactory; -import java.util.ArrayList; +import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletTelemetryBuilderFactory; import java.util.List; import java.util.Set; import java.util.function.Function; @@ -28,22 +21,10 @@ /** A builder of {@link RestletTelemetry}. */ public final class RestletTelemetryBuilder { - private final OpenTelemetry openTelemetry; - private final List> additionalExtractors = - new ArrayList<>(); - private final HttpServerAttributesExtractorBuilder - httpAttributesExtractorBuilder = - HttpServerAttributesExtractor.builder(RestletHttpAttributesGetter.INSTANCE); - private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder = - HttpSpanNameExtractor.builder(RestletHttpAttributesGetter.INSTANCE); - private Function, ? extends SpanNameExtractor> - spanNameExtractorTransformer = Function.identity(); - private final HttpServerRouteBuilder httpServerRouteBuilder = - HttpServerRoute.builder(RestletHttpAttributesGetter.INSTANCE); - private boolean emitExperimentalHttpServerMetrics = false; + private final DefaultHttpServerInstrumenterBuilder builder; RestletTelemetryBuilder(OpenTelemetry openTelemetry) { - this.openTelemetry = openTelemetry; + builder = RestletTelemetryBuilderFactory.create(openTelemetry); } /** @@ -53,7 +34,7 @@ public final class RestletTelemetryBuilder { @CanIgnoreReturnValue public RestletTelemetryBuilder addAttributesExtractor( AttributesExtractor attributesExtractor) { - additionalExtractors.add(attributesExtractor); + builder.addAttributesExtractor(attributesExtractor); return this; } @@ -64,7 +45,7 @@ public RestletTelemetryBuilder addAttributesExtractor( */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHeaders) { - httpAttributesExtractorBuilder.setCapturedRequestHeaders(requestHeaders); + builder.setCapturedRequestHeaders(requestHeaders); return this; } @@ -75,7 +56,7 @@ public RestletTelemetryBuilder setCapturedRequestHeaders(List requestHea */ @CanIgnoreReturnValue public RestletTelemetryBuilder setCapturedResponseHeaders(List responseHeaders) { - httpAttributesExtractorBuilder.setCapturedResponseHeaders(responseHeaders); + builder.setCapturedResponseHeaders(responseHeaders); return this; } @@ -94,9 +75,7 @@ public RestletTelemetryBuilder setCapturedResponseHeaders(List responseH */ @CanIgnoreReturnValue public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { - httpAttributesExtractorBuilder.setKnownMethods(knownMethods); - httpSpanNameExtractorBuilder.setKnownMethods(knownMethods); - httpServerRouteBuilder.setKnownMethods(knownMethods); + builder.setKnownMethods(knownMethods); return this; } @@ -109,7 +88,7 @@ public RestletTelemetryBuilder setKnownMethods(Set knownMethods) { @CanIgnoreReturnValue public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( boolean emitExperimentalHttpServerMetrics) { - this.emitExperimentalHttpServerMetrics = emitExperimentalHttpServerMetrics; + builder.setEmitExperimentalHttpServerMetrics(emitExperimentalHttpServerMetrics); return this; } @@ -118,7 +97,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( public RestletTelemetryBuilder setSpanNameExtractor( Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { - this.spanNameExtractorTransformer = spanNameExtractorTransformer; + builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; } @@ -127,18 +106,6 @@ public RestletTelemetryBuilder setSpanNameExtractor( * RestletTelemetryBuilder}. */ public RestletTelemetry build() { - SpanNameExtractor spanNameExtractor = - spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); - - Instrumenter serverInstrumenter = - RestletInstrumenterFactory.newServerInstrumenter( - openTelemetry, - httpAttributesExtractorBuilder.build(), - spanNameExtractor, - httpServerRouteBuilder.build(), - additionalExtractors, - emitExperimentalHttpServerMetrics); - - return new RestletTelemetry(serverInstrumenter); + return new RestletTelemetry(builder.build()); } } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java index 38c5a96c2ffc..fa5554e81e9f 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletHttpAttributesGetter.java @@ -16,11 +16,7 @@ import org.restlet.Response; import org.restlet.util.Series; -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public enum RestletHttpAttributesGetter implements HttpServerAttributesGetter { +enum RestletHttpAttributesGetter implements HttpServerAttributesGetter { INSTANCE; @Override diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java deleted file mode 100644 index 54a60a980ec4..000000000000 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.restlet.v2_0.internal; - -import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; -import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; -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.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import java.util.List; -import org.restlet.Request; -import org.restlet.Response; - -/** - * This class is internal and is hence not for public use. Its APIs are unstable and can change at - * any time. - */ -public final class RestletInstrumenterFactory { - - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.restlet-2.0"; - - public static Instrumenter newServerInstrumenter( - OpenTelemetry openTelemetry, - AttributesExtractor httpServerAttributesExtractor, - SpanNameExtractor httpServerSpanNameExtractor, - ContextCustomizer httpServerRoute, - List> additionalExtractors, - boolean emitExperimentalHttpServerMetrics) { - - RestletHttpAttributesGetter httpAttributesGetter = RestletHttpAttributesGetter.INSTANCE; - - InstrumenterBuilder builder = - Instrumenter.builder( - openTelemetry, INSTRUMENTATION_NAME, httpServerSpanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor(httpServerAttributesExtractor) - .addAttributesExtractors(additionalExtractors) - .addContextCustomizer(httpServerRoute) - .addOperationMetrics(HttpServerMetrics.get()); - if (emitExperimentalHttpServerMetrics) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - return builder.buildServerInstrumenter(new RestletHeadersGetter()); - } - - private RestletInstrumenterFactory() {} -} diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java new file mode 100644 index 000000000000..309149fe2845 --- /dev/null +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.restlet.v2_0.internal; + +import io.opentelemetry.api.OpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.builder.internal.DefaultHttpServerInstrumenterBuilder; +import org.restlet.Request; +import org.restlet.Response; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public class RestletTelemetryBuilderFactory { + private RestletTelemetryBuilderFactory() {} + + public static DefaultHttpServerInstrumenterBuilder create( + OpenTelemetry openTelemetry) { + return new DefaultHttpServerInstrumenterBuilder<>( + "io.opentelemetry.restlet-2.0", openTelemetry, RestletHttpAttributesGetter.INSTANCE) + .setHeaderGetter(new RestletHeadersGetter()); + } +} diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index 10b221f613a1..224fb1687d6f 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -7,21 +7,16 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.api.GlobalOpenTelemetry; -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.DefaultHttpServerInstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; 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.internal.InstrumenterUtil; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import java.util.ArrayList; import java.util.List; @@ -58,46 +53,35 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> httpAttributesGetter) { - ServletErrorCauseExtractor errorCauseExtractor = - new ServletErrorCauseExtractor<>(accessor); - AttributesExtractor, ServletResponseContext> - additionalAttributesExtractor = new ServletAdditionalAttributesExtractor<>(accessor); - - InstrumenterBuilder, ServletResponseContext> builder = - Instrumenter., ServletResponseContext>builder( - GlobalOpenTelemetry.get(), instrumentationName, spanNameExtractor) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .setErrorCauseExtractor(errorCauseExtractor) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addAttributesExtractor(additionalAttributesExtractor) - .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()); - if (ServletRequestParametersExtractor.enabled()) { - AttributesExtractor, ServletResponseContext> - requestParametersExtractor = new ServletRequestParametersExtractor<>(accessor); - builder.addAttributesExtractor(requestParametersExtractor); - } - for (ContextCustomizer> contextCustomizer : - contextCustomizers) { - builder.addContextCustomizer(contextCustomizer); - } - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - if (propagateOperationListenersToOnEnd) { - InstrumenterUtil.propagateOperationListenersToOnEnd(builder); - } - return builder.buildServerInstrumenter(new ServletRequestGetter<>(accessor)); + DefaultHttpServerInstrumenterBuilder< + ServletRequestContext, ServletResponseContext> + serverBuilder = + new DefaultHttpServerInstrumenterBuilder<>( + instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter) + .setHeaderGetter(new ServletRequestGetter<>(accessor)); + serverBuilder.setSpanNameExtractor(e -> spanNameExtractor); + + return JavaagentHttpServerInstrumenters.create( + serverBuilder, + builder -> { + if (ServletRequestParametersExtractor.enabled()) { + AttributesExtractor, ServletResponseContext> + requestParametersExtractor = new ServletRequestParametersExtractor<>(accessor); + builder.addAttributesExtractor(requestParametersExtractor); + } + for (ContextCustomizer> contextCustomizer : + contextCustomizers) { + builder.addContextCustomizer(contextCustomizer); + } + + if (propagateOperationListenersToOnEnd) { + InstrumenterUtil.propagateOperationListenersToOnEnd(builder); + } + + builder + .addAttributesExtractor(new ServletAdditionalAttributesExtractor<>(accessor)) + .setErrorCauseExtractor(new ServletErrorCauseExtractor<>(accessor)); + }); } public Instrumenter, ServletResponseContext> build( diff --git a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java index b89d70bc77d3..c2a632918752 100644 --- a/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java +++ b/instrumentation/tomcat/tomcat-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tomcat/common/TomcatInstrumenterFactory.java @@ -5,18 +5,9 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.common; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.internal.InstrumenterUtil; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.instrumentation.servlet.ServletAccessor; import io.opentelemetry.javaagent.instrumentation.servlet.ServletErrorCauseExtractor; @@ -29,40 +20,19 @@ private TomcatInstrumenterFactory() {} public static Instrumenter create( String instrumentationName, ServletAccessor accessor) { - TomcatHttpAttributesGetter httpAttributesGetter = new TomcatHttpAttributesGetter(); - - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - instrumentationName, - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .setErrorCauseExtractor(new ServletErrorCauseExtractor<>(accessor)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - (context, request, attributes) -> - new AppServerBridge.Builder() - .captureServletAttributes() - .recordException() - .init(context)) - .addOperationMetrics(HttpServerMetrics.get()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - InstrumenterUtil.propagateOperationListenersToOnEnd(builder); - return builder.buildServerInstrumenter(TomcatRequestGetter.INSTANCE); + return JavaagentHttpServerInstrumenters.create( + instrumentationName, + new TomcatHttpAttributesGetter(), + TomcatRequestGetter.INSTANCE, + builder -> + InstrumenterUtil.propagateOperationListenersToOnEnd( + builder + .setErrorCauseExtractor(new ServletErrorCauseExtractor<>(accessor)) + .addContextCustomizer( + (context, request, attributes) -> + new AppServerBridge.Builder() + .captureServletAttributes() + .recordException() + .init(context)))); } } diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java index cb4e9007afab..14c21b0aab58 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java @@ -5,17 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.undertow; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.api.incubator.semconv.http.HttpServerExperimentalMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerMetrics; -import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanNameExtractor; -import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; -import io.opentelemetry.javaagent.bootstrap.internal.AgentCommonConfig; +import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpServerInstrumenters; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.bootstrap.undertow.UndertowActiveHandlers; import io.undertow.server.HttpServerExchange; @@ -26,44 +17,24 @@ public final class UndertowSingletons { private static final Instrumenter INSTRUMENTER; static { - UndertowHttpAttributesGetter httpAttributesGetter = new UndertowHttpAttributesGetter(); - - InstrumenterBuilder builder = - Instrumenter.builder( - GlobalOpenTelemetry.get(), - INSTRUMENTATION_NAME, - HttpSpanNameExtractor.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter)) - .addAttributesExtractor( - HttpServerAttributesExtractor.builder(httpAttributesGetter) - .setCapturedRequestHeaders(AgentCommonConfig.get().getServerRequestHeaders()) - .setCapturedResponseHeaders(AgentCommonConfig.get().getServerResponseHeaders()) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - HttpServerRoute.builder(httpAttributesGetter) - .setKnownMethods(AgentCommonConfig.get().getKnownHttpRequestMethods()) - .build()) - .addContextCustomizer( - (context, request, attributes) -> { - // span is ended when counter reaches 0, we start from 2 which accounts for the - // handler that started the span and exchange completion listener - context = UndertowActiveHandlers.init(context, 2); - - return new AppServerBridge.Builder() - .captureServletAttributes() - .recordException() - .init(context); - }) - .addOperationMetrics(HttpServerMetrics.get()); - if (AgentCommonConfig.get().shouldEmitExperimentalHttpServerTelemetry()) { - builder - .addAttributesExtractor(HttpExperimentalAttributesExtractor.create(httpAttributesGetter)) - .addOperationMetrics(HttpServerExperimentalMetrics.get()); - } - INSTRUMENTER = builder.buildServerInstrumenter(UndertowExchangeGetter.INSTANCE); + INSTRUMENTER = + JavaagentHttpServerInstrumenters.create( + INSTRUMENTATION_NAME, + new UndertowHttpAttributesGetter(), + UndertowExchangeGetter.INSTANCE, + builder -> + builder.addContextCustomizer( + (context, request, attributes) -> { + // span is ended when counter reaches 0, we start from 2 which accounts for + // the + // handler that started the span and exchange completion listener + context = UndertowActiveHandlers.init(context, 2); + + return new AppServerBridge.Builder() + .captureServletAttributes() + .recordException() + .init(context); + })); } private static final UndertowHelper HELPER = new UndertowHelper(INSTRUMENTER); diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java index 6e4ce0e43c88..2b83cfcf261e 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java @@ -21,6 +21,18 @@ public final class JavaagentHttpServerInstrumenters { private JavaagentHttpServerInstrumenters() {} + public static Instrumenter create( + String instrumentationName, + HttpServerAttributesGetter httpAttributesGetter, + TextMapGetter headerGetter) { + return create(instrumentationName, httpAttributesGetter, headerGetter, customizer -> {}); + } + + public static Instrumenter create( + DefaultHttpServerInstrumenterBuilder builder) { + return create(builder, customizer -> {}); + } + public static Instrumenter create( String instrumentationName, HttpServerAttributesGetter httpAttributesGetter, From 41efcc53fa15838ff688d52c847637ed5e3bfc62 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 22 Aug 2024 13:32:39 +0200 Subject: [PATCH 02/14] http server builder --- .../armeria/v1_3/ArmeriaTelemetryBuilder.java | 62 +++++++++++++++---- .../ArmeriaHttpClientAttributesGetter.java | 29 ++++----- 2 files changed, 66 insertions(+), 25 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 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( From 773c98ee8fe810a3f4c238ca6fc828b50532edc7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 26 Sep 2024 16:47:04 +0200 Subject: [PATCH 03/14] http server builder --- .../ktor/v2_0/client/KtorClientTracingBuilder.kt | 4 +++- .../instrumentation/ktor/v2_0/server/KtorServerTracing.kt | 3 ++- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 7 +++---- .../instrumentation/undertow/UndertowSingletons.java | 3 +-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt index 14de724b6834..edf09d59d164 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt @@ -23,9 +23,11 @@ class KtorClientTracingBuilder { } } + private lateinit var openTelemetry: OpenTelemetry private lateinit var clientBuilder: DefaultHttpClientInstrumenterBuilder fun setOpenTelemetry(openTelemetry: OpenTelemetry) { + this.openTelemetry = openTelemetry this.clientBuilder = DefaultHttpClientInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, @@ -165,6 +167,6 @@ class KtorClientTracingBuilder { internal fun build(): KtorClientTracing = KtorClientTracing( instrumenter = clientBuilder.build(), - propagators = clientBuilder.openTelemetry.propagators, + propagators = openTelemetry.propagators, ) } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index e6bd2e2fc2cf..b6990763e34f 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -51,7 +51,8 @@ class KtorServerTracing private constructor( DefaultHttpServerInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, - KtorHttpServerAttributesGetter.INSTANCE + KtorHttpServerAttributesGetter.INSTANCE, + null ) } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 5986f1bd4615..4139aa1dccca 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -36,8 +36,7 @@ public final class RatpackTelemetryBuilder { .setHeaderSetter(RequestHeaderSetter.INSTANCE); serverBuilder = new DefaultHttpServerInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RatpackHttpAttributesGetter.INSTANCE) - .setHeaderGetter(RatpackGetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, RatpackHttpAttributesGetter.INSTANCE, RatpackGetter.INSTANCE); } /** @@ -152,7 +151,7 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( /** Sets custom client {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setClientSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> clientSpanNameExtractor) { clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; @@ -161,7 +160,7 @@ public RatpackTelemetryBuilder setClientSpanNameExtractor( /** Sets custom server {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setServerSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> serverSpanNameExtractor) { serverBuilder.setSpanNameExtractor(serverSpanNameExtractor); return this; diff --git a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java index 14c21b0aab58..fa8e7055c549 100644 --- a/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java +++ b/instrumentation/undertow-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/undertow/UndertowSingletons.java @@ -26,8 +26,7 @@ public final class UndertowSingletons { builder.addContextCustomizer( (context, request, attributes) -> { // span is ended when counter reaches 0, we start from 2 which accounts for - // the - // handler that started the span and exchange completion listener + // the handler that started the span and exchange completion listener context = UndertowActiveHandlers.init(context, 2); return new AppServerBridge.Builder() From ab9b52b7a45e3b4f6b36d976b0aac0a247a2b329 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Thu, 26 Sep 2024 17:29:27 +0200 Subject: [PATCH 04/14] how to debug tests --- .../internal/DefaultHttpServerInstrumenterBuilder.java | 10 +++------- .../instrumentation/ktor/v1_0/KtorServerTracing.kt | 5 +++-- .../ktor/v2_0/server/KtorServerTracing.kt | 2 +- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 9 +++++++-- .../restlet/v1_1/RestletTelemetryBuilder.java | 2 +- .../v1_1/internal/RestletTelemetryBuilderFactory.java | 6 ++++-- .../restlet/v2_0/RestletTelemetryBuilder.java | 2 +- .../v2_0/internal/RestletTelemetryBuilderFactory.java | 6 ++++-- .../servlet/ServletInstrumenterBuilder.java | 6 ++++-- .../internal/JavaagentHttpServerInstrumenters.java | 2 +- 10 files changed, 29 insertions(+), 21 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 6124bf249380..0ca29c76aefe 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 @@ -172,7 +172,7 @@ public DefaultHttpServerInstrumenterBuilder setBuilderCustomi } public Instrumenter build() { - InstrumenterBuilder builder = builder(); + InstrumenterBuilder builder = instrumenterBuilder(); if (headerGetter != null) { return builder.buildServerInstrumenter(headerGetter); @@ -180,7 +180,7 @@ public Instrumenter build() { return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); } - public InstrumenterBuilder builder() { + public InstrumenterBuilder instrumenterBuilder() { SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); @@ -199,11 +199,7 @@ public InstrumenterBuilder builder() { .addOperationMetrics(HttpServerExperimentalMetrics.get()); } builderCustomizer.accept(builder); - - if (headerGetter != null) { - return builder.buildServerInstrumenter(headerGetter); - } - return builder.buildInstrumenter(SpanKindExtractor.alwaysServer()); + return builder; } @CanIgnoreReturnValue diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 99e364af89b5..661cb48dbead 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -40,7 +40,8 @@ class KtorServerTracing private constructor( DefaultHttpServerInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, - KtorHttpServerAttributesGetter.INSTANCE + KtorHttpServerAttributesGetter.INSTANCE, + null ) } @@ -111,7 +112,7 @@ class KtorServerTracing private constructor( } val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( - configuration.builder.builder(), + configuration.builder.instrumenterBuilder(), ApplicationRequestGetter, configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index b6990763e34f..3992acb3b09f 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -234,7 +234,7 @@ class KtorServerTracing private constructor( require(configuration.isOpenTelemetryInitialized()) { "OpenTelemetry must be set" } val instrumenter = InstrumenterUtil.buildUpstreamInstrumenter( - configuration.serverBuilder.builder(), + configuration.serverBuilder.instrumenterBuilder(), ApplicationRequestGetter, configuration.spanKindExtractor(SpanKindExtractor.alwaysServer()) ) diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 4139aa1dccca..5f0191ecaa10 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -36,7 +36,10 @@ public final class RatpackTelemetryBuilder { .setHeaderSetter(RequestHeaderSetter.INSTANCE); serverBuilder = new DefaultHttpServerInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RatpackHttpAttributesGetter.INSTANCE, RatpackGetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + RatpackHttpAttributesGetter.INSTANCE, + RatpackGetter.INSTANCE); } /** @@ -151,7 +154,9 @@ public RatpackTelemetryBuilder setEmitExperimentalHttpServerMetrics( /** Sets custom client {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public RatpackTelemetryBuilder setClientSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function< + SpanNameExtractor, + ? extends SpanNameExtractor> clientSpanNameExtractor) { clientBuilder.setSpanNameExtractor(clientSpanNameExtractor); return this; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index 0f7630e5a9c4..3ff61af4a73f 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -95,7 +95,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public RestletTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java index a4a1f1cc2890..7ffac6aa5084 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java @@ -22,7 +22,9 @@ private RestletTelemetryBuilderFactory() {} public static DefaultHttpServerInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpServerInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RestletHttpAttributesGetter.INSTANCE) - .setHeaderGetter(RestletHeadersGetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + RestletHttpAttributesGetter.INSTANCE, + RestletHeadersGetter.INSTANCE); } } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java index 6c49897500ed..a933f52cdea4 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/RestletTelemetryBuilder.java @@ -95,7 +95,7 @@ public RestletTelemetryBuilder setEmitExperimentalHttpServerMetrics( /** Sets custom {@link SpanNameExtractor} via transform function. */ @CanIgnoreReturnValue public RestletTelemetryBuilder setSpanNameExtractor( - Function, ? extends SpanNameExtractor> + Function, ? extends SpanNameExtractor> spanNameExtractorTransformer) { builder.setSpanNameExtractor(spanNameExtractorTransformer); return this; diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java index 309149fe2845..9d2aa96f6915 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java @@ -20,7 +20,9 @@ private RestletTelemetryBuilderFactory() {} public static DefaultHttpServerInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpServerInstrumenterBuilder<>( - "io.opentelemetry.restlet-2.0", openTelemetry, RestletHttpAttributesGetter.INSTANCE) - .setHeaderGetter(new RestletHeadersGetter()); + "io.opentelemetry.restlet-2.0", + openTelemetry, + RestletHttpAttributesGetter.INSTANCE, + new RestletHeadersGetter()); } } diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index 224fb1687d6f..75875ecadde6 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -57,8 +57,10 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> serverBuilder = new DefaultHttpServerInstrumenterBuilder<>( - instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter) - .setHeaderGetter(new ServletRequestGetter<>(accessor)); + instrumentationName, + GlobalOpenTelemetry.get(), + httpAttributesGetter, + new ServletRequestGetter<>(accessor)); serverBuilder.setSpanNameExtractor(e -> spanNameExtractor); return JavaagentHttpServerInstrumenters.create( diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java index 2b83cfcf261e..7b46b82c420b 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java @@ -44,7 +44,7 @@ public static Instrumenter create( instrumenterBuilderConsumer); } - private static Instrumenter create( + public static Instrumenter create( DefaultHttpServerInstrumenterBuilder builder, Consumer> builderCustomizer) { return builder From ff71f59197e89f56a13848df4e26f65cc2f2e79d Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 1 Oct 2024 15:47:19 +0200 Subject: [PATCH 05/14] remove unused method --- .../internal/DefaultHttpClientInstrumenterBuilder.java | 5 ----- 1 file changed, 5 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 1a9b85240edd..78768604e9e0 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 @@ -193,7 +193,6 @@ public DefaultHttpClientInstrumenterBuilder setBuilderCustomi } public Instrumenter build() { - SpanNameExtractor spanNameExtractor = spanNameExtractorTransformer.apply(httpSpanNameExtractorBuilder.build()); @@ -224,10 +223,6 @@ InstrumenterBuilder instrumenterBuilder( return Instrumenter.builder(openTelemetry, instrumentationName, spanNameExtractor); } - public String getInstrumentationName() { - return instrumentationName; - } - @CanIgnoreReturnValue public DefaultHttpClientInstrumenterBuilder configure(CommonConfig config) { set(config::getKnownHttpRequestMethods, this::setKnownMethods); From fcfd6a367255f4fb3b5c2f827b11a2c9aa85df15 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 1 Oct 2024 16:16:16 +0200 Subject: [PATCH 06/14] remove unchecked cast --- .../instrumentation/ktor/v1_0/KtorServerTracing.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 661cb48dbead..07c1a1de1c6c 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -46,16 +46,14 @@ class KtorServerTracing private constructor( } fun setStatusExtractor( - extractor: (SpanStatusExtractor) -> SpanStatusExtractor + extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { builder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, request: ApplicationRequest, response: ApplicationResponse?, throwable: Throwable? -> - @Suppress("UNCHECKED_CAST") - extractor(prevExtractor as SpanStatusExtractor) - .extract(spanStatusBuilder, request, response, throwable) + extractor(prevExtractor).extract(spanStatusBuilder, request, response, throwable) } } } From 87b766e95fe6fb1447320987b6b8edc3a465fcc7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 2 Oct 2024 11:23:01 +0200 Subject: [PATCH 07/14] avoid unchecked cast --- .../instrumentation/ktor/v2_0/server/KtorServerTracing.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 3992acb3b09f..54003d9bfb88 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -58,23 +58,22 @@ class KtorServerTracing private constructor( @Deprecated("Please use method `spanStatusExtractor`") fun setStatusExtractor( - extractor: (SpanStatusExtractor) -> SpanStatusExtractor + extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { spanStatusExtractor { prevStatusExtractor -> extractor(prevStatusExtractor).extract(spanStatusBuilder, request, response, error) } } - fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { + fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { serverBuilder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, request: ApplicationRequest, response: ApplicationResponse?, throwable: Throwable? -> - @Suppress("UNCHECKED_CAST") extract( SpanStatusData(spanStatusBuilder, request, response, throwable), - prevExtractor as SpanStatusExtractor + prevExtractor ) } } From eb1cd81ef03099a38d818e1c3e0145a9cf8a3039 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 2 Oct 2024 11:33:05 +0200 Subject: [PATCH 08/14] add comment --- .../instrumentation/ktor/v2_0/server/KtorServerTracing.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 54003d9bfb88..f4c8e15d0667 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -58,14 +58,14 @@ class KtorServerTracing private constructor( @Deprecated("Please use method `spanStatusExtractor`") fun setStatusExtractor( - extractor: (SpanStatusExtractor) -> SpanStatusExtractor + extractor: (SpanStatusExtractor) -> SpanStatusExtractor ) { spanStatusExtractor { prevStatusExtractor -> extractor(prevStatusExtractor).extract(spanStatusBuilder, request, response, error) } } - fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { + fun spanStatusExtractor(extract: SpanStatusData.(SpanStatusExtractor) -> Unit) { serverBuilder.setStatusExtractor { prevExtractor -> SpanStatusExtractor { spanStatusBuilder: SpanStatusBuilder, request: ApplicationRequest, @@ -204,6 +204,9 @@ class KtorServerTracing private constructor( } } + /** + * {@link #setOpenTelemetry(OpenTelemetry)} sets the serverBuilder to a non-null value. + */ internal fun isOpenTelemetryInitialized(): Boolean = this::serverBuilder.isInitialized } From 4235f34fedc9f2079fb3e4b44ec475c55e22e810 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 2 Oct 2024 11:40:06 +0200 Subject: [PATCH 09/14] remove setHeaderSetter --- .../DefaultHttpClientInstrumenterBuilder.java | 19 ++++++++++++------- .../ArmeriaInstrumenterBuilderFactory.java | 3 +-- ...yHttpClientInstrumenterBuilderFactory.java | 3 +-- ...yHttpClientInstrumenterBuilderFactory.java | 3 +-- ...NettyClientInstrumenterBuilderFactory.java | 3 +-- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 3 +-- .../web/v3_1/SpringWebTelemetryBuilder.java | 3 +-- .../JavaagentHttpClientInstrumenters.java | 9 ++++----- 8 files changed, 22 insertions(+), 24 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 78768604e9e0..bff9fa9e0d27 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 @@ -65,6 +65,18 @@ public final class DefaultHttpClientInstrumenterBuilder { private Consumer> builderCustomizer = b -> {}; public DefaultHttpClientInstrumenterBuilder( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpClientAttributesGetter attributesGetter, + TextMapSetter headerSetter) { + this( + instrumentationName, + openTelemetry, + attributesGetter); + this.headerSetter = headerSetter; + } + + public DefaultHttpClientInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpClientAttributesGetter attributesGetter) { @@ -141,13 +153,6 @@ public DefaultHttpClientInstrumenterBuilder setKnownMethods( return this; } - @CanIgnoreReturnValue - public DefaultHttpClientInstrumenterBuilder setHeaderSetter( - @Nullable TextMapSetter headerSetter) { - this.headerSetter = headerSetter; - return this; - } - /** * Configures the instrumentation to emit experimental HTTP client metrics. * 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 37834dccc286..48e4c2751bff 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 @@ -33,7 +33,6 @@ private ArmeriaInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder getClientBuilder(OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpClientAttributesGetter.INSTANCE) - .setHeaderSetter(ClientRequestContextSetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpClientAttributesGetter.INSTANCE,ClientRequestContextSetter.INSTANCE); } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java index 386a5e6c816b..6d92553a2ba7 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -22,7 +22,6 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE) - .setHeaderSetter(HttpHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE,HttpHeaderSetter.INSTANCE); } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java index f2be57153580..04873db4118f 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -22,7 +22,6 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE) - .setHeaderSetter(HttpHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE,HttpHeaderSetter.INSTANCE); } } diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java index 088fb0031338..42683ef6f54f 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java @@ -21,7 +21,6 @@ public static DefaultHttpClientInstrumenterBuilder( - instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter()) - .setHeaderSetter(HttpRequestHeadersSetter.INSTANCE); + instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter(),HttpRequestHeadersSetter.INSTANCE); } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 5f0191ecaa10..a6ebd71a8f14 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -32,8 +32,7 @@ public final class RatpackTelemetryBuilder { RatpackTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RatpackHttpClientAttributesGetter.INSTANCE) - .setHeaderSetter(RequestHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, RatpackHttpClientAttributesGetter.INSTANCE,RequestHeaderSetter.INSTANCE); serverBuilder = new DefaultHttpServerInstrumenterBuilder<>( INSTRUMENTATION_NAME, 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 36fde223c3ec..9b340fc6cc59 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 @@ -30,8 +30,7 @@ public final class SpringWebTelemetryBuilder { SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { builder = new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE) - .setHeaderSetter(HttpRequestSetter.INSTANCE); + INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE,HttpRequestSetter.INSTANCE); } private DefaultHttpClientInstrumenterBuilder getBuilder() { diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java index e7331c550fff..5a9862e44552 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java @@ -44,13 +44,12 @@ public static Instrumenter create( HttpClientAttributesGetter httpAttributesGetter, TextMapSetter headerSetter, Consumer> instrumenterBuilderConsumer) { - DefaultHttpClientInstrumenterBuilder defaultHttpClientTelemetryBuilder = - new DefaultHttpClientInstrumenterBuilder<>( - instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter); if (headerSetter != null) { - defaultHttpClientTelemetryBuilder.setHeaderSetter(headerSetter); + return create(new DefaultHttpClientInstrumenterBuilder<>( + instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerSetter), instrumenterBuilderConsumer); } - return create(defaultHttpClientTelemetryBuilder, instrumenterBuilderConsumer); + return create(new DefaultHttpClientInstrumenterBuilder<>( + instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter), instrumenterBuilderConsumer); } private static Instrumenter create( From 33536f9f088e60e070f304c12fd1939a4966a085 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 2 Oct 2024 11:47:49 +0200 Subject: [PATCH 10/14] remove setHeaderSetter --- .../DefaultHttpClientInstrumenterBuilder.java | 20 +++++++++---------- .../ArmeriaInstrumenterBuilderFactory.java | 5 ++++- ...yHttpClientInstrumenterBuilderFactory.java | 5 ++++- ...yHttpClientInstrumenterBuilderFactory.java | 5 ++++- .../v3_8/client/NettyClientSingletons.java | 8 ++++---- ...NettyClientInstrumenterBuilderFactory.java | 5 ++++- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 5 ++++- .../web/v3_1/SpringWebTelemetryBuilder.java | 5 ++++- .../JavaagentHttpClientInstrumenters.java | 15 +++++++------- 9 files changed, 45 insertions(+), 28 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 bff9fa9e0d27..6661f8a9257b 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 @@ -29,6 +29,7 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; @@ -68,23 +69,20 @@ public DefaultHttpClientInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpClientAttributesGetter attributesGetter, - TextMapSetter headerSetter) { - this( - instrumentationName, - openTelemetry, - attributesGetter); - this.headerSetter = headerSetter; - } + TextMapSetter headerSetter) { + this(instrumentationName, openTelemetry, attributesGetter); + this.headerSetter = Objects.requireNonNull(headerSetter, "headerSetter"); + } - public DefaultHttpClientInstrumenterBuilder( + public DefaultHttpClientInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpClientAttributesGetter attributesGetter) { - this.instrumentationName = instrumentationName; - this.openTelemetry = openTelemetry; + this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName"); + this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry"); + this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter"); httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); httpAttributesExtractorBuilder = HttpClientAttributesExtractor.builder(attributesGetter); - this.attributesGetter = attributesGetter; } /** 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 48e4c2751bff..5442100f4c91 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 @@ -33,6 +33,9 @@ private ArmeriaInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder getClientBuilder(OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpClientAttributesGetter.INSTANCE,ClientRequestContextSetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + ArmeriaHttpClientAttributesGetter.INSTANCE, + ClientRequestContextSetter.INSTANCE); } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java index 6d92553a2ba7..4c717aa29bac 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -22,6 +22,9 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE,HttpHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + JettyClientHttpAttributesGetter.INSTANCE, + HttpHeaderSetter.INSTANCE); } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java index 04873db4118f..f059b9ff705a 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -22,6 +22,9 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { return new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE,HttpHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + JettyClientHttpAttributesGetter.INSTANCE, + HttpHeaderSetter.INSTANCE); } } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java index 3db67f23dc80..08733dd46d42 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/client/NettyClientSingletons.java @@ -31,10 +31,10 @@ public final class NettyClientSingletons { INSTRUMENTATION_NAME, new NettyHttpClientAttributesGetter(), HttpRequestHeadersSetter.INSTANCE, - builder -> { - builder.addContextCustomizer( - (context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context)); - }); + builder -> + builder.addContextCustomizer( + (context, requestAndChannel, startAttributes) -> + NettyErrorHolder.init(context))); CONNECTION_INSTRUMENTER = Instrumenter.builder( diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java index 42683ef6f54f..31c5718fa012 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java @@ -21,6 +21,9 @@ public static DefaultHttpClientInstrumenterBuilder( - instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter(),HttpRequestHeadersSetter.INSTANCE); + instrumentationName, + openTelemetry, + new NettyHttpClientAttributesGetter(), + HttpRequestHeadersSetter.INSTANCE); } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index a6ebd71a8f14..30c860823ab5 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -32,7 +32,10 @@ public final class RatpackTelemetryBuilder { RatpackTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, RatpackHttpClientAttributesGetter.INSTANCE,RequestHeaderSetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + RatpackHttpClientAttributesGetter.INSTANCE, + RequestHeaderSetter.INSTANCE); serverBuilder = new DefaultHttpServerInstrumenterBuilder<>( INSTRUMENTATION_NAME, 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 9b340fc6cc59..890bcf57fa63 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 @@ -30,7 +30,10 @@ public final class SpringWebTelemetryBuilder { SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { builder = new DefaultHttpClientInstrumenterBuilder<>( - INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE,HttpRequestSetter.INSTANCE); + INSTRUMENTATION_NAME, + openTelemetry, + SpringWebHttpAttributesGetter.INSTANCE, + HttpRequestSetter.INSTANCE); } private DefaultHttpClientInstrumenterBuilder getBuilder() { diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java index 5a9862e44552..5f295bad9edc 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java @@ -24,7 +24,10 @@ private JavaagentHttpClientInstrumenters() {} public static Instrumenter create( String instrumentationName, HttpClientAttributesGetter httpAttributesGetter) { - return create(instrumentationName, httpAttributesGetter, null); + return create( + new DefaultHttpClientInstrumenterBuilder<>( + instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter), + b -> {}); } public static Instrumenter create( @@ -44,12 +47,10 @@ public static Instrumenter create( HttpClientAttributesGetter httpAttributesGetter, TextMapSetter headerSetter, Consumer> instrumenterBuilderConsumer) { - if (headerSetter != null) { - return create(new DefaultHttpClientInstrumenterBuilder<>( - instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerSetter), instrumenterBuilderConsumer); - } - return create(new DefaultHttpClientInstrumenterBuilder<>( - instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter), instrumenterBuilderConsumer); + return create( + new DefaultHttpClientInstrumenterBuilder<>( + instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerSetter), + instrumenterBuilderConsumer); } private static Instrumenter create( From b31690db8431036974fa2428e2436685569747d2 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 2 Oct 2024 11:54:13 +0200 Subject: [PATCH 11/14] don't pass null header getter --- .../DefaultHttpServerInstrumenterBuilder.java | 20 +++++++++++++------ .../ktor/v1_0/KtorServerTracing.kt | 3 +-- .../ktor/v2_0/server/KtorServerTracing.kt | 3 +-- 3 files changed, 16 insertions(+), 10 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 0ca29c76aefe..0cb81dda1295 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 @@ -28,6 +28,7 @@ import io.opentelemetry.instrumentation.api.semconv.http.HttpSpanStatusExtractor; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; @@ -53,7 +54,7 @@ public final class DefaultHttpServerInstrumenterBuilder { httpAttributesExtractorBuilder; private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; - @Nullable private final TextMapGetter headerGetter; + @Nullable private TextMapGetter headerGetter; private Function, ? extends SpanNameExtractor> spanNameExtractorTransformer = Function.identity(); private final HttpServerRouteBuilder httpServerRouteBuilder; @@ -65,14 +66,21 @@ public DefaultHttpServerInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpServerAttributesGetter attributesGetter, - @Nullable TextMapGetter headerGetter) { - this.instrumentationName = instrumentationName; - this.openTelemetry = openTelemetry; + TextMapGetter headerGetter) { + this(instrumentationName, openTelemetry, attributesGetter); + this.headerGetter = Objects.requireNonNull(headerGetter, "headerGetter"); + } + + public DefaultHttpServerInstrumenterBuilder( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpServerAttributesGetter attributesGetter) { + this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName"); + this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry"); + this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter"); httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(attributesGetter); httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); httpServerRouteBuilder = HttpServerRoute.builder(attributesGetter); - this.attributesGetter = attributesGetter; - this.headerGetter = headerGetter; } /** diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 07c1a1de1c6c..2e67e004d885 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -40,8 +40,7 @@ class KtorServerTracing private constructor( DefaultHttpServerInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, - KtorHttpServerAttributesGetter.INSTANCE, - null + KtorHttpServerAttributesGetter.INSTANCE ) } diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index f4c8e15d0667..99748a82fb6a 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -51,8 +51,7 @@ class KtorServerTracing private constructor( DefaultHttpServerInstrumenterBuilder( INSTRUMENTATION_NAME, openTelemetry, - KtorHttpServerAttributesGetter.INSTANCE, - null + KtorHttpServerAttributesGetter.INSTANCE ) } From 37a947e4599762cb8fa96b6d4b8554ada427f573 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 7 Oct 2024 10:27:58 +0200 Subject: [PATCH 12/14] add factory method --- .../DefaultHttpClientInstrumenterBuilder.java | 33 +++++++++++++------ .../DefaultHttpServerInstrumenterBuilder.java | 33 +++++++++++++------ .../ApacheHttpClientTelemetryBuilder.java | 2 +- .../ApacheHttpClient5TelemetryBuilder.java | 2 +- .../ArmeriaInstrumenterBuilderFactory.java | 4 +-- ...aHttpClientInstrumenterBuilderFactory.java | 2 +- ...yHttpClientInstrumenterBuilderFactory.java | 2 +- ...yHttpClientInstrumenterBuilderFactory.java | 2 +- .../KubernetesClientSingletons.java | 2 +- ...NettyClientInstrumenterBuilderFactory.java | 2 +- .../v4_1/NettyServerTelemetryBuilder.java | 2 +- ...kHttpClientInstrumenterBuilderFactory.java | 2 +- .../ratpack/v1_7/RatpackTelemetryBuilder.java | 4 +-- .../RestletTelemetryBuilderFactory.java | 2 +- .../RestletTelemetryBuilderFactory.java | 2 +- .../servlet/ServletInstrumenterBuilder.java | 2 +- .../web/v3_1/SpringWebTelemetryBuilder.java | 2 +- .../v5_3/SpringWebfluxTelemetryBuilder.java | 4 +-- .../v5_3/SpringWebMvcTelemetryBuilder.java | 2 +- .../v6_0/SpringWebMvcTelemetryBuilder.java | 2 +- .../JavaagentHttpClientInstrumenters.java | 4 +-- .../JavaagentHttpServerInstrumenters.java | 2 +- 22 files changed, 70 insertions(+), 44 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 6661f8a9257b..d2ef015383d9 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,30 +59,43 @@ public final class DefaultHttpClientInstrumenterBuilder { private final HttpClientAttributesGetter attributesGetter; private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; - @Nullable private TextMapSetter headerSetter; + @Nullable private final TextMapSetter headerSetter; private Function, ? extends SpanNameExtractor> spanNameExtractorTransformer = Function.identity(); private boolean emitExperimentalHttpClientMetrics = false; private Consumer> builderCustomizer = b -> {}; - public DefaultHttpClientInstrumenterBuilder( + private DefaultHttpClientInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpClientAttributesGetter attributesGetter, TextMapSetter headerSetter) { - this(instrumentationName, openTelemetry, attributesGetter); - this.headerSetter = Objects.requireNonNull(headerSetter, "headerSetter"); - } - - public DefaultHttpClientInstrumenterBuilder( - String instrumentationName, - OpenTelemetry openTelemetry, - HttpClientAttributesGetter attributesGetter) { this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName"); this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry"); this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter"); httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); httpAttributesExtractorBuilder = HttpClientAttributesExtractor.builder(attributesGetter); + this.headerSetter = headerSetter; + } + + public static DefaultHttpClientInstrumenterBuilder create( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpClientAttributesGetter attributesGetter) { + return new DefaultHttpClientInstrumenterBuilder( + instrumentationName, openTelemetry, attributesGetter, null); + } + + public static DefaultHttpClientInstrumenterBuilder create( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpClientAttributesGetter attributesGetter, + TextMapSetter headerSetter) { + return new DefaultHttpClientInstrumenterBuilder( + instrumentationName, + openTelemetry, + attributesGetter, + Objects.requireNonNull(headerSetter, "headerSetter")); } /** 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 0cb81dda1295..caee6c007da7 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 { httpAttributesExtractorBuilder; private final HttpSpanNameExtractorBuilder httpSpanNameExtractorBuilder; - @Nullable private TextMapGetter headerGetter; + @Nullable private final TextMapGetter headerGetter; private Function, ? extends SpanNameExtractor> spanNameExtractorTransformer = Function.identity(); private final HttpServerRouteBuilder httpServerRouteBuilder; @@ -62,25 +62,38 @@ public final class DefaultHttpServerInstrumenterBuilder { private boolean emitExperimentalHttpServerMetrics = false; private Consumer> builderCustomizer = b -> {}; - public DefaultHttpServerInstrumenterBuilder( + private DefaultHttpServerInstrumenterBuilder( String instrumentationName, OpenTelemetry openTelemetry, HttpServerAttributesGetter attributesGetter, TextMapGetter headerGetter) { - this(instrumentationName, openTelemetry, attributesGetter); - this.headerGetter = Objects.requireNonNull(headerGetter, "headerGetter"); - } - - public DefaultHttpServerInstrumenterBuilder( - String instrumentationName, - OpenTelemetry openTelemetry, - HttpServerAttributesGetter attributesGetter) { this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName"); this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry"); this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter"); httpAttributesExtractorBuilder = HttpServerAttributesExtractor.builder(attributesGetter); httpSpanNameExtractorBuilder = HttpSpanNameExtractor.builder(attributesGetter); httpServerRouteBuilder = HttpServerRoute.builder(attributesGetter); + this.headerGetter = headerGetter; + } + + public static DefaultHttpServerInstrumenterBuilder create( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpServerAttributesGetter attributesGetter) { + return new DefaultHttpServerInstrumenterBuilder<>( + instrumentationName, openTelemetry, attributesGetter, null); + } + + public static DefaultHttpServerInstrumenterBuilder create( + String instrumentationName, + OpenTelemetry openTelemetry, + HttpServerAttributesGetter attributesGetter, + TextMapGetter headerGetter) { + return new DefaultHttpServerInstrumenterBuilder<>( + instrumentationName, + openTelemetry, + attributesGetter, + Objects.requireNonNull(headerGetter, "headerGetter")); } /** 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 dd128f7930ef..1d0d497317b9 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 @@ -25,7 +25,7 @@ public final class ApacheHttpClientTelemetryBuilder { ApacheHttpClientTelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClientHttpAttributesGetter.INSTANCE); this.openTelemetry = openTelemetry; } 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 061919ff1587..8d7b323462cf 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 @@ -26,7 +26,7 @@ public final class ApacheHttpClient5TelemetryBuilder { ApacheHttpClient5TelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, ApacheHttpClient5HttpAttributesGetter.INSTANCE); this.openTelemetry = openTelemetry; } 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 5442100f4c91..7ac77ba5287c 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 @@ -23,7 +23,7 @@ private ArmeriaInstrumenterBuilderFactory() {} public static DefaultHttpServerInstrumenterBuilder getServerBuilder(OpenTelemetry openTelemetry) { - return new DefaultHttpServerInstrumenterBuilder<>( + return DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpServerAttributesGetter.INSTANCE, @@ -32,7 +32,7 @@ private ArmeriaInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder getClientBuilder(OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, ArmeriaHttpClientAttributesGetter.INSTANCE, diff --git a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/JavaHttpClientInstrumenterBuilderFactory.java b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/JavaHttpClientInstrumenterBuilderFactory.java index 9f9bb506f643..bb8b2e48ba07 100644 --- a/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/JavaHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/java-http-client/library/src/main/java/io/opentelemetry/instrumentation/httpclient/internal/JavaHttpClientInstrumenterBuilderFactory.java @@ -21,7 +21,7 @@ private JavaHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder> create( OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, JavaHttpClientAttributesGetter.INSTANCE); } } diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java index 4c717aa29bac..b395f04f872a 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -21,7 +21,7 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE, diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java index f059b9ff705a..df476aabed38 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-9.2/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v9_2/internal/JettyHttpClientInstrumenterBuilderFactory.java @@ -21,7 +21,7 @@ private JettyHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, JettyClientHttpAttributesGetter.INSTANCE, diff --git a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java index 5d97acc910e9..b6ce1ac000ff 100644 --- a/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java +++ b/instrumentation/kubernetes-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kubernetesclient/KubernetesClientSingletons.java @@ -25,7 +25,7 @@ public class KubernetesClientSingletons { static { INSTRUMENTER = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( "io.opentelemetry.kubernetes-client-7.0", GlobalOpenTelemetry.get(), new KubernetesHttpAttributesGetter()) diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java index 31c5718fa012..713fc73834ef 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/client/NettyClientInstrumenterBuilderFactory.java @@ -20,7 +20,7 @@ private NettyClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( String instrumentationName, OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( instrumentationName, openTelemetry, new NettyHttpClientAttributesGetter(), diff --git a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java index 0744ab4658a3..874bcb586bed 100644 --- a/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java +++ b/instrumentation/netty/netty-4.1/library/src/main/java/io/opentelemetry/instrumentation/netty/v4_1/NettyServerTelemetryBuilder.java @@ -32,7 +32,7 @@ public final class NettyServerTelemetryBuilder { NettyServerTelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( "io.opentelemetry.netty-4.1", openTelemetry, new NettyHttpServerAttributesGetter(), diff --git a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpClientInstrumenterBuilderFactory.java b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpClientInstrumenterBuilderFactory.java index 4dbaf771d24d..7d79a333c7ee 100644 --- a/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpClientInstrumenterBuilderFactory.java +++ b/instrumentation/okhttp/okhttp-3.0/library/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/internal/OkHttpClientInstrumenterBuilderFactory.java @@ -21,7 +21,7 @@ private OkHttpClientInstrumenterBuilderFactory() {} public static DefaultHttpClientInstrumenterBuilder create( OpenTelemetry openTelemetry) { - return new DefaultHttpClientInstrumenterBuilder<>( + return DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, OkHttpAttributesGetter.INSTANCE); } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java index 30c860823ab5..a7e56610913a 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackTelemetryBuilder.java @@ -31,13 +31,13 @@ public final class RatpackTelemetryBuilder { RatpackTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, RatpackHttpClientAttributesGetter.INSTANCE, RequestHeaderSetter.INSTANCE); serverBuilder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, RatpackHttpAttributesGetter.INSTANCE, diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java index 7ffac6aa5084..9c7ead4b2582 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/internal/RestletTelemetryBuilderFactory.java @@ -21,7 +21,7 @@ private RestletTelemetryBuilderFactory() {} public static DefaultHttpServerInstrumenterBuilder create( OpenTelemetry openTelemetry) { - return new DefaultHttpServerInstrumenterBuilder<>( + return DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, RestletHttpAttributesGetter.INSTANCE, diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java index 9d2aa96f6915..552e0c301ac5 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletTelemetryBuilderFactory.java @@ -19,7 +19,7 @@ private RestletTelemetryBuilderFactory() {} public static DefaultHttpServerInstrumenterBuilder create( OpenTelemetry openTelemetry) { - return new DefaultHttpServerInstrumenterBuilder<>( + return DefaultHttpServerInstrumenterBuilder.create( "io.opentelemetry.restlet-2.0", openTelemetry, RestletHttpAttributesGetter.INSTANCE, diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java index 75875ecadde6..28327c9cdfa8 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletInstrumenterBuilder.java @@ -56,7 +56,7 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> serverBuilder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, 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 890bcf57fa63..86771bfa3313 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 @@ -29,7 +29,7 @@ public final class SpringWebTelemetryBuilder { SpringWebTelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, SpringWebHttpAttributesGetter.INSTANCE, 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 d8dbc868b211..602ded9c1d4d 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 @@ -40,10 +40,10 @@ public final class SpringWebfluxTelemetryBuilder { SpringWebfluxTelemetryBuilder(OpenTelemetry openTelemetry) { clientBuilder = - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, WebClientHttpAttributesGetter.INSTANCE); serverBuilder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, WebfluxServerHttpAttributesGetter.INSTANCE, 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 b6e47c868ff9..0c31ace56234 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 @@ -32,7 +32,7 @@ public final class SpringWebMvcTelemetryBuilder { SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE, 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 c87ecf3ab5b4..1c34c847a3b2 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 @@ -31,7 +31,7 @@ public final class SpringWebMvcTelemetryBuilder { SpringWebMvcTelemetryBuilder(OpenTelemetry openTelemetry) { builder = - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, SpringWebMvcHttpAttributesGetter.INSTANCE, diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java index 5f295bad9edc..915ab0fa1a26 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpClientInstrumenters.java @@ -25,7 +25,7 @@ public static Instrumenter create( String instrumentationName, HttpClientAttributesGetter httpAttributesGetter) { return create( - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter), b -> {}); } @@ -48,7 +48,7 @@ public static Instrumenter create( TextMapSetter headerSetter, Consumer> instrumenterBuilderConsumer) { return create( - new DefaultHttpClientInstrumenterBuilder<>( + DefaultHttpClientInstrumenterBuilder.create( instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerSetter), instrumenterBuilderConsumer); } diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java index 7b46b82c420b..b27cefbfa3a0 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal/JavaagentHttpServerInstrumenters.java @@ -39,7 +39,7 @@ public static Instrumenter create( TextMapGetter headerGetter, Consumer> instrumenterBuilderConsumer) { return create( - new DefaultHttpServerInstrumenterBuilder<>( + DefaultHttpServerInstrumenterBuilder.create( instrumentationName, GlobalOpenTelemetry.get(), httpAttributesGetter, headerGetter), instrumenterBuilderConsumer); } From 19b0c82e7b29b615a4448a8113db69afb8fec11c Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 7 Oct 2024 17:01:31 +0200 Subject: [PATCH 13/14] add factory method --- .../ktor/v2_0/client/KtorClientTracingBuilder.kt | 2 +- .../instrumentation/ktor/v2_0/server/KtorServerTracing.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt index edf09d59d164..f03128224b07 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/client/KtorClientTracingBuilder.kt @@ -28,7 +28,7 @@ class KtorClientTracingBuilder { fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.openTelemetry = openTelemetry - this.clientBuilder = DefaultHttpClientInstrumenterBuilder( + this.clientBuilder = DefaultHttpClientInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, KtorHttpClientAttributesGetter diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt index 99748a82fb6a..66d0324a60e1 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/server/KtorServerTracing.kt @@ -48,7 +48,7 @@ class KtorServerTracing private constructor( fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.serverBuilder = - DefaultHttpServerInstrumenterBuilder( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, KtorHttpServerAttributesGetter.INSTANCE From 8b9d03a074af2be642990ac5e1030472133fe728 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 7 Oct 2024 17:16:18 +0200 Subject: [PATCH 14/14] add factory method --- .../instrumentation/ktor/v1_0/KtorServerTracing.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 2e67e004d885..844cbe2895fd 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -37,7 +37,7 @@ class KtorServerTracing private constructor( fun setOpenTelemetry(openTelemetry: OpenTelemetry) { this.builder = - DefaultHttpServerInstrumenterBuilder( + DefaultHttpServerInstrumenterBuilder.create( INSTRUMENTATION_NAME, openTelemetry, KtorHttpServerAttributesGetter.INSTANCE