From 163693e9f90b8d91c3c02a593eb8b8033a3aa081 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Mon, 24 Jan 2022 10:49:26 +0100 Subject: [PATCH 1/2] Rename ServerSpanNaming to HttpRouteHolder --- .../instrumenter/http/HttpRouteGetter.java | 21 +++ .../instrumenter/http/HttpRouteGetter2.java | 21 +++ .../instrumenter/http/HttpRouteHolder.java | 157 +++++++++++++++++ .../instrumenter/http/HttpRouteSource.java | 30 ++++ .../api/server/ServerSpanNameSupplier.java | 16 -- .../server/ServerSpanNameTwoArgSupplier.java | 16 -- .../api/server/ServerSpanNaming.java | 163 ------------------ .../server/AkkaHttpServerSingletons.java | 4 +- .../armeria/v1_3/ArmeriaTracingBuilder.java | 4 +- .../finatra/FinatraSingletons.java | 7 +- .../grails/GrailsServerSpanNaming.java | 4 +- ...ingsInfoHandlerAdapterInstrumentation.java | 6 +- .../grizzly/GrizzlySingletons.java | 4 +- .../v1_0/JaxrsAnnotationsInstrumentation.java | 7 +- .../jaxrs/v1_0/JaxrsServerSpanNaming.java | 4 +- .../DefaultRequestContextInstrumentation.java | 7 +- .../v2_0/JaxrsAnnotationsInstrumentation.java | 7 +- .../jaxrs/v2_0/JaxrsServerSpanNaming.java | 4 +- .../jaxrs/v2_0/RequestContextHelper.java | 7 +- .../jaxrs/v2_0/CxfSpanName.java | 10 +- .../jaxrs/v2_0/JerseySpanName.java | 10 +- .../jaxrs/v2_0/ResteasySpanName.java | 10 +- .../jsf/JsfServerSpanNaming.java | 4 +- .../RestoreViewPhaseInstrumentation.java | 6 +- .../RestoreViewExecutorInstrumentation.java | 6 +- .../ktor/v1_0/KtorServerTracing.kt | 7 +- .../LibertyDispatcherSingletons.java | 4 +- .../v3_8/server/NettyServerSingletons.java | 4 +- .../NettyServerInstrumenterFactory.java | 4 +- .../ratpack/RatpackSingletons.java | 7 +- .../restlet/v1_0/RestletSingletons.java | 4 +- .../restlet/v1_0/RouteInstrumentation.java | 7 +- .../restlet/v1_0/ServerInstrumentation.java | 6 +- .../restlet/v1_0/TracingFilter.java | 6 +- .../restlet/v2_0/RestletSingletons.java | 4 +- .../restlet/v2_0/RouteInstrumentation.java | 7 +- .../restlet/v2_0/ServerInstrumentation.java | 6 +- .../restlet/v2_0/TracingFilter.java | 6 +- .../servlet/BaseServletHelper.java | 8 +- .../servlet/ServletInstrumenterBuilder.java | 4 +- .../servlet/ServletSpanNameProvider.java | 4 +- .../HandlerAdapterInstrumentation.java | 6 +- .../SpringWebMvcServerSpanNaming.java | 4 +- .../OpenTelemetryHandlerMappingFilter.java | 10 +- .../webmvc/SpringWebMvcTracingBuilder.java | 4 +- .../ActionInvocationInstrumentation.java | 6 +- .../struts2/StrutsServerSpanNaming.java | 4 +- ...itializeActivePageNameInstrumentation.java | 8 +- .../tapestry/TapestryServerSpanNaming.java | 4 +- .../common/TomcatInstrumenterFactory.java | 4 +- .../undertow/UndertowSingletons.java | 4 +- .../instrumentation/vaadin/VaadinHelper.java | 11 +- ...RequestHandlerExecutorInstrumentation.java | 6 +- .../wicket/WicketServerSpanNaming.java | 4 +- 54 files changed, 369 insertions(+), 329 deletions(-) create mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter.java create mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java create mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java create mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteSource.java delete mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameSupplier.java delete mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameTwoArgSupplier.java delete mode 100644 instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNaming.java diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter.java new file mode 100644 index 000000000000..a76cbf2ad8ff --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter.java @@ -0,0 +1,21 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.context.Context; +import javax.annotation.Nullable; + +/** An interface for getting the {@code http.route} attribute. */ +@FunctionalInterface +public interface HttpRouteGetter { + + /** + * Returns the {@code http.route} attribute extracted from {@code context} and {@code arg}; or + * {@code null} if it was not found. + */ + @Nullable + String get(Context context, T arg); +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java new file mode 100644 index 000000000000..a93df506c2d3 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java @@ -0,0 +1,21 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.context.Context; +import javax.annotation.Nullable; + +/** An interface for getting the {@code http.route} attribute. */ +@FunctionalInterface +public interface HttpRouteGetter2 { + + /** + * Returns the {@code http.route} attribute extracted from {@code context}, {@code arg1} and + * {@code arg2}; or {@code null} if it was not found. + */ + @Nullable + String get(Context context, T arg1, U arg2); +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java new file mode 100644 index 000000000000..f3d74ef0f6a6 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -0,0 +1,157 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.server.ServerSpan; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import javax.annotation.Nullable; + +/** + * A helper class that keeps track of the {@code http.route} attribute value during HTTP server + * request processing. + * + *

Usually the route is not accessible when the request processing starts; and needs to be set + * later, after the instrumented operation starts. This class provides several static methods that + * allow the isntrumentation author to provide the matching HTTP route to the instrumentation when + * it is discovered. + */ +public final class HttpRouteHolder { + + private static final ContextKey CONTEXT_KEY = + ContextKey.named("opentelemetry-http-server-route-key"); + + /** + * Returns a {@link ContextCustomizer} that initializes a {@link HttpRouteHolder} in the {@link + * Context} returned from {@link Instrumenter#start(Context, Object)}. + */ + public static ContextCustomizer get() { + return (context, request, startAttributes) -> { + if (context.get(CONTEXT_KEY) != null) { + return context; + } + return context.with(CONTEXT_KEY, new HttpRouteHolder()); + }; + } + + private volatile int updatedBySourceOrder = 0; + @Nullable private volatile String route; + + private HttpRouteHolder() {} + + /** + * Updates the {@code http.route} attribute in the received {@code context}. + * + *

If there is a server span in the context, and the context has been customized with a {@link + * HttpRouteHolder}, then this method will update the route using the provided {@link + * HttpRouteGetter} if and only if the last {@link HttpRouteSource} to update the route using this + * method has strictly lower priority than the provided {@link HttpRouteSource}, and the value + * returned from the {@link HttpRouteGetter} is non-null. + * + *

If there is a server span in the context, and the context has NOT been customized with a + * {@link HttpRouteHolder}, then this method will update the route using the provided {@link + * HttpRouteGetter} if the value returned from it is non-null. + */ + public static void updateHttpRoute( + Context context, HttpRouteSource source, HttpRouteGetter httpRouteGetter, T arg1) { + updateHttpRoute(context, source, OneArgAdapter.getInstance(), arg1, httpRouteGetter); + } + + /** + * Updates the {@code http.route} attribute in the received {@code context}. + * + *

If there is a server span in the context, and the context has been customized with a {@link + * HttpRouteHolder}, then this method will update the route using the provided {@link + * HttpRouteGetter2} if and only if the last {@link HttpRouteSource} to update the route using + * this method has strictly lower priority than the provided {@link HttpRouteSource}, and the + * value returned from the {@link HttpRouteGetter2} is non-null. + * + *

If there is a server span in the context, and the context has NOT been customized with a + * {@code ServerSpanName}, then this method will update the route using the provided {@link + * HttpRouteGetter2} if the value returned from it is non-null. + */ + public static void updateHttpRoute( + Context context, + HttpRouteSource source, + HttpRouteGetter2 httpRouteGetter, + T arg1, + U arg2) { + Span serverSpan = ServerSpan.fromContextOrNull(context); + // checking isRecording() is a helpful optimization for more expensive suppliers + // (e.g. Spring MVC instrumentation's HandlerAdapterInstrumentation) + if (serverSpan == null || !serverSpan.isRecording()) { + return; + } + HttpRouteHolder httpRouteHolder = context.get(CONTEXT_KEY); + if (httpRouteHolder == null) { + String httpRoute = httpRouteGetter.get(context, arg1, arg2); + if (httpRoute != null && !httpRoute.isEmpty()) { + updateSpanData(serverSpan, httpRoute); + } + return; + } + // special case for servlet filters, even when we have a route from previous filter see whether + // the new route is better and if so use it instead + boolean onlyIfBetterRoute = + !source.useFirst && source.order == httpRouteHolder.updatedBySourceOrder; + if (source.order > httpRouteHolder.updatedBySourceOrder || onlyIfBetterRoute) { + String route = httpRouteGetter.get(context, arg1, arg2); + if (route != null + && !route.isEmpty() + && (!onlyIfBetterRoute || httpRouteHolder.isBetterRoute(route))) { + updateSpanData(serverSpan, route); + httpRouteHolder.updatedBySourceOrder = source.order; + httpRouteHolder.route = route; + } + } + } + + // TODO: instead of calling setAttribute() consider storing the route in context end retrieving it + // in the AttributesExtractor + private static void updateSpanData(Span serverSpan, String route) { + serverSpan.updateName(route); + serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, route); + } + + // This is used when setting route from a servlet filter to pick the most descriptive (longest) + // route. + private boolean isBetterRoute(String name) { + String route = this.route; + int routeLength = route == null ? 0 : route.length(); + return name.length() > routeLength; + } + + // TODO: use that in HttpServerMetrics + /** + * Returns the {@code http.route} attribute value that's stored in the passed {@code context}, or + * null if it was not set before. + */ + @Nullable + public static String getRoute(Context context) { + HttpRouteHolder httpRouteHolder = context.get(CONTEXT_KEY); + return httpRouteHolder == null ? null : httpRouteHolder.route; + } + + private static final class OneArgAdapter implements HttpRouteGetter2> { + + private static final OneArgAdapter INSTANCE = new OneArgAdapter<>(); + + @SuppressWarnings("unchecked") + static OneArgAdapter getInstance() { + return (OneArgAdapter) INSTANCE; + } + + @Override + @Nullable + public String get(Context context, T arg, HttpRouteGetter httpRouteGetter) { + return httpRouteGetter.get(context, arg); + } + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteSource.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteSource.java new file mode 100644 index 000000000000..e566d7ea80e3 --- /dev/null +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteSource.java @@ -0,0 +1,30 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +/** Represents the source that provided the {@code http.route} attribute. */ +public enum HttpRouteSource { + // for servlet filters we try to find the best name which isn't necessarily from the first + // filter that is called + FILTER(1, /* useFirst= */ false), + SERVLET(2), + CONTROLLER(3), + // Some frameworks, e.g. JaxRS, allow for nested controller/paths and we want to select the + // longest one + NESTED_CONTROLLER(4, false); + + final int order; + final boolean useFirst; + + HttpRouteSource(int order) { + this(order, /* useFirst= */ true); + } + + HttpRouteSource(int order, boolean useFirst) { + this.order = order; + this.useFirst = useFirst; + } +} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameSupplier.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameSupplier.java deleted file mode 100644 index 747c4e2c43fa..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameSupplier.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.server; - -import io.opentelemetry.context.Context; -import javax.annotation.Nullable; - -@FunctionalInterface -public interface ServerSpanNameSupplier { - - @Nullable - String get(Context context, T arg); -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameTwoArgSupplier.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameTwoArgSupplier.java deleted file mode 100644 index 49efe04e7a72..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNameTwoArgSupplier.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.server; - -import io.opentelemetry.context.Context; -import javax.annotation.Nullable; - -@FunctionalInterface -public interface ServerSpanNameTwoArgSupplier { - - @Nullable - String get(Context context, T arg1, U arg2); -} diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNaming.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNaming.java deleted file mode 100644 index 16658016d55e..000000000000 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/server/ServerSpanNaming.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.api.server; - -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.ContextKey; -import io.opentelemetry.instrumentation.api.instrumenter.ContextCustomizer; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import javax.annotation.Nullable; - -// TODO: move to ...instrumenter.http and rename to HttpRouteHolder (?) -/** Helper container for tracking whether instrumentation should update server span name or not. */ -public final class ServerSpanNaming { - - private static final ContextKey CONTEXT_KEY = - ContextKey.named("opentelemetry-http-server-route-key"); - - public static ContextCustomizer get() { - return (context, request, startAttributes) -> { - if (context.get(CONTEXT_KEY) != null) { - return context; - } - return context.with(CONTEXT_KEY, new ServerSpanNaming(Source.CONTAINER)); - }; - } - - private volatile Source updatedBySource; - @Nullable private volatile String route; - - private ServerSpanNaming(Source initialSource) { - this.updatedBySource = initialSource; - } - - /** - * If there is a server span in the context, and the context has been customized with a {@code - * ServerSpanName}, then this method will update the server span name using the provided {@link - * ServerSpanNameSupplier} if and only if the last {@link Source} to update the span name using - * this method has strictly lower priority than the provided {@link Source}, and the value - * returned from the {@link ServerSpanNameSupplier} is non-null. - * - *

If there is a server span in the context, and the context has NOT been customized with a - * {@code ServerSpanName}, then this method will update the server span name using the provided - * {@link ServerSpanNameSupplier} if the value returned from it is non-null. - */ - public static void updateServerSpanName( - Context context, Source source, ServerSpanNameSupplier serverSpanName, T arg1) { - updateServerSpanName(context, source, OneArgAdapter.getInstance(), arg1, serverSpanName); - } - - /** - * If there is a server span in the context, and the context has been customized with a {@code - * ServerSpanName}, then this method will update the server span name using the provided {@link - * ServerSpanNameTwoArgSupplier} if and only if the last {@link Source} to update the span name - * using this method has strictly lower priority than the provided {@link Source}, and the value - * returned from the {@link ServerSpanNameTwoArgSupplier} is non-null. - * - *

If there is a server span in the context, and the context has NOT been customized with a - * {@code ServerSpanName}, then this method will update the server span name using the provided - * {@link ServerSpanNameTwoArgSupplier} if the value returned from it is non-null. - */ - public static void updateServerSpanName( - Context context, - Source source, - ServerSpanNameTwoArgSupplier serverSpanName, - T arg1, - U arg2) { - Span serverSpan = ServerSpan.fromContextOrNull(context); - // checking isRecording() is a helpful optimization for more expensive suppliers - // (e.g. Spring MVC instrumentation's HandlerAdapterInstrumentation) - if (serverSpan == null || !serverSpan.isRecording()) { - return; - } - ServerSpanNaming serverSpanNaming = context.get(CONTEXT_KEY); - if (serverSpanNaming == null) { - String name = serverSpanName.get(context, arg1, arg2); - if (name != null && !name.isEmpty()) { - updateSpanData(serverSpan, name); - } - return; - } - // special case for servlet filters, even when we have a name from previous filter see whether - // the new name is better and if so use it instead - boolean onlyIfBetterName = - !source.useFirst && source.order == serverSpanNaming.updatedBySource.order; - if (source.order > serverSpanNaming.updatedBySource.order || onlyIfBetterName) { - String name = serverSpanName.get(context, arg1, arg2); - if (name != null - && !name.isEmpty() - && (!onlyIfBetterName || serverSpanNaming.isBetterName(name))) { - updateSpanData(serverSpan, name); - serverSpanNaming.updatedBySource = source; - serverSpanNaming.route = name; - } - } - } - - // TODO: instead of calling setAttribute() consider storing the route in context end retrieving it - // in the AttributesExtractor - private static void updateSpanData(Span serverSpan, String route) { - serverSpan.updateName(route); - serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, route); - } - - // This is used when setting name from a servlet filter to pick the most descriptive (longest) - // route. - private boolean isBetterName(String name) { - String route = this.route; - int routeLength = route == null ? 0 : route.length(); - return name.length() > routeLength; - } - - // TODO: use that in HttpServerMetrics - @Nullable - public static String getRoute(Context context) { - ServerSpanNaming serverSpanNaming = context.get(CONTEXT_KEY); - return serverSpanNaming == null ? null : serverSpanNaming.route; - } - - public enum Source { - CONTAINER(1), - // for servlet filters we try to find the best name which isn't necessarily from the first - // filter that is called - FILTER(2, /* useFirst= */ false), - SERVLET(3), - CONTROLLER(4), - // Some frameworks, e.g. JaxRS, allow for nested controller/paths and we want to select the - // longest one - NESTED_CONTROLLER(5, false); - - private final int order; - private final boolean useFirst; - - Source(int order) { - this(order, /* useFirst= */ true); - } - - Source(int order, boolean useFirst) { - this.order = order; - this.useFirst = useFirst; - } - } - - private static class OneArgAdapter - implements ServerSpanNameTwoArgSupplier> { - - private static final OneArgAdapter INSTANCE = new OneArgAdapter<>(); - - @SuppressWarnings("unchecked") - static OneArgAdapter getInstance() { - return (OneArgAdapter) INSTANCE; - } - - @Override - @Nullable - public String get(Context context, T arg, ServerSpanNameSupplier serverSpanNameSupplier) { - return serverSpanNameSupplier.get(context, arg); - } - } -} 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 f5f6fb8b9c6f..fd48dbba5782 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 @@ -9,10 +9,10 @@ import akka.http.scaladsl.model.HttpResponse; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.instrumentation.akkahttp.AkkaHttpUtil; public class AkkaHttpServerSingletons { @@ -30,7 +30,7 @@ public class AkkaHttpServerSingletons { .setSpanStatusExtractor(HttpSpanStatusExtractor.create(httpAttributesExtractor)) .addAttributesExtractor(httpAttributesExtractor) .addRequestMetrics(HttpServerMetrics.get()) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .newServerInstrumenter(AkkaHttpServerHeaders.INSTANCE); } diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java index ced45980afb1..a269e7b3467d 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTracingBuilder.java @@ -18,12 +18,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.ArrayList; import java.util.List; @@ -142,7 +142,7 @@ public ArmeriaTracing build() { NetServerAttributesExtractor.create(new ArmeriaNetServerAttributesGetter())) .addAttributesExtractor(serverAttributesExtractor) .addRequestMetrics(HttpServerMetrics.get()) - .addContextCustomizer(ServerSpanNaming.get()); + .addContextCustomizer(HttpRouteHolder.get()); if (peerService != null) { clientInstrumenterBuilder.addAttributesExtractor( diff --git a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java index 43f7472e97fc..d0e0d2acb746 100644 --- a/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java +++ b/instrumentation/finatra-2.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/finatra/FinatraSingletons.java @@ -10,7 +10,8 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.ClassNames; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; public final class FinatraSingletons { @@ -24,8 +25,8 @@ public static Instrumenter, Void> instrumenter() { } public static void updateServerSpanName(Context context, RouteInfo routeInfo) { - ServerSpanNaming.updateServerSpanName( - context, ServerSpanNaming.Source.CONTROLLER, (c, route) -> route.path(), routeInfo); + HttpRouteHolder.updateHttpRoute( + context, HttpRouteSource.CONTROLLER, (c, route) -> route.path(), routeInfo); } private FinatraSingletons() {} diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java index dc6f76999d83..620b455205dc 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/GrailsServerSpanNaming.java @@ -5,13 +5,13 @@ package io.opentelemetry.javaagent.instrumentation.grails; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.grails.web.mapping.mvc.GrailsControllerUrlMappingInfo; public class GrailsServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, info) -> { String action = info.getActionName() != null diff --git a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/UrlMappingsInfoHandlerAdapterInstrumentation.java b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/UrlMappingsInfoHandlerAdapterInstrumentation.java index 0c2b1c925c65..5d4689f58694 100644 --- a/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/UrlMappingsInfoHandlerAdapterInstrumentation.java +++ b/instrumentation/grails-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grails/UrlMappingsInfoHandlerAdapterInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.grails; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -13,7 +13,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; @@ -48,7 +48,7 @@ public static void nameSpan(@Advice.Argument(2) Object handler) { if (handler instanceof GrailsControllerUrlMappingInfo) { Context parentContext = Java8BytecodeBridge.currentContext(); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, CONTROLLER, GrailsServerSpanNaming.SERVER_SPAN_NAME, diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java index 08d33deae98c..4cddbe0f0d93 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlySingletons.java @@ -7,11 +7,11 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; @@ -34,7 +34,7 @@ public final class GrizzlySingletons { .addRequestMetrics(HttpServerMetrics.get()) .addContextCustomizer( (context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context)) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .newServerInstrumenter(HttpRequestHeadersGetter.INSTANCE); } diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsAnnotationsInstrumentation.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsAnnotationsInstrumentation.java index 31407b66c0e0..59db2cc538e1 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsAnnotationsInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsAnnotationsInstrumentation.java @@ -17,7 +17,8 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.CallDepth; @@ -79,9 +80,9 @@ public static void nameSpan( Context parentContext = Java8BytecodeBridge.currentContext(); handlerData = new HandlerData(target.getClass(), method); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, - ServerSpanNaming.Source.CONTROLLER, + HttpRouteSource.CONTROLLER, JaxrsServerSpanNaming.SERVER_SPAN_NAME, handlerData); diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsServerSpanNaming.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsServerSpanNaming.java index 5599b0abc199..24d81c86af0b 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsServerSpanNaming.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v1_0/JaxrsServerSpanNaming.java @@ -5,13 +5,13 @@ package io.opentelemetry.javaagent.instrumentation.jaxrs.v1_0; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; public class JaxrsServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, handlerData) -> { String pathBasedSpanName = handlerData.getServerSpanName(); // If path based name is empty skip prepending context path so that path based name would diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/DefaultRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/DefaultRequestContextInstrumentation.java index ffd0b0d3e483..e953a572464b 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/DefaultRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/DefaultRequestContextInstrumentation.java @@ -9,7 +9,8 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import java.lang.reflect.Method; import javax.ws.rs.container.ContainerRequestContext; @@ -61,9 +62,9 @@ public static void createGenericSpan( Context parentContext = Java8BytecodeBridge.currentContext(); handlerData = new HandlerData(filterClass, method); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, - ServerSpanNaming.Source.CONTROLLER, + HttpRouteSource.CONTROLLER, JaxrsServerSpanNaming.SERVER_SPAN_NAME, handlerData); diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java index eaae8666e576..5bfd69b4ac2c 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsAnnotationsInstrumentation.java @@ -18,7 +18,8 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.field.VirtualField; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.CallDepth; @@ -103,9 +104,9 @@ public static void nameSpan( Context parentContext = Java8BytecodeBridge.currentContext(); handlerData = new HandlerData(target.getClass(), method); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, - ServerSpanNaming.Source.CONTROLLER, + HttpRouteSource.CONTROLLER, JaxrsServerSpanNaming.SERVER_SPAN_NAME, handlerData); diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsServerSpanNaming.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsServerSpanNaming.java index e8428becca01..3bcb6c35c748 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsServerSpanNaming.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JaxrsServerSpanNaming.java @@ -5,13 +5,13 @@ package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; public class JaxrsServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, handlerData) -> { String pathBasedSpanName = handlerData.getServerSpanName(); // If path based name is empty skip prepending context path so that path based name would diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/RequestContextHelper.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/RequestContextHelper.java index ed7216e1a2cc..e8021a3c9f35 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/RequestContextHelper.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/RequestContextHelper.java @@ -9,8 +9,9 @@ import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.instrumentation.api.server.ServerSpan; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; import javax.ws.rs.container.ContainerRequestContext; @@ -27,9 +28,9 @@ public static Context createOrUpdateAbortSpan( Span serverSpan = ServerSpan.fromContextOrNull(parentContext); Span currentSpan = Java8BytecodeBridge.spanFromContext(parentContext); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, - ServerSpanNaming.Source.CONTROLLER, + HttpRouteSource.CONTROLLER, JaxrsServerSpanNaming.SERVER_SPAN_NAME, handlerData); diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfSpanName.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfSpanName.java index 65be579b7319..2b9187075cf8 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfSpanName.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfSpanName.java @@ -8,8 +8,9 @@ import static io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0.JaxrsPathUtil.normalizePath; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.apache.cxf.jaxrs.model.ClassResourceInfo; @@ -17,7 +18,7 @@ import org.apache.cxf.jaxrs.model.URITemplate; import org.apache.cxf.message.Exchange; -public final class CxfSpanName implements ServerSpanNameSupplier { +public final class CxfSpanName implements HttpRouteGetter { public static final CxfSpanName INSTANCE = new CxfSpanName(); @@ -25,8 +26,7 @@ public Context updateServerSpanName(Exchange exchange) { Context context = Context.current(); String jaxrsName = calculateJaxrsName(context, exchange); - ServerSpanNaming.updateServerSpanName( - context, ServerSpanNaming.Source.NESTED_CONTROLLER, this, jaxrsName); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.NESTED_CONTROLLER, this, jaxrsName); return JaxrsContextPath.init(context, jaxrsName); } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JerseySpanName.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JerseySpanName.java index 35b6ec1d4584..0c7e7f6f85c8 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JerseySpanName.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/JerseySpanName.java @@ -8,8 +8,9 @@ import static io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0.JaxrsPathUtil.normalizePath; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.annotation.Nullable; @@ -18,14 +19,13 @@ import org.glassfish.jersey.server.ContainerRequest; import org.glassfish.jersey.server.ExtendedUriInfo; -public class JerseySpanName implements ServerSpanNameSupplier { +public class JerseySpanName implements HttpRouteGetter { public static final JerseySpanName INSTANCE = new JerseySpanName(); public void updateServerSpanName(Request request) { Context context = Context.current(); - ServerSpanNaming.updateServerSpanName( - context, ServerSpanNaming.Source.NESTED_CONTROLLER, this, request); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.NESTED_CONTROLLER, this, request); } @Override diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasySpanName.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasySpanName.java index 000d05503739..bf7d2ddbe77b 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasySpanName.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrs/v2_0/ResteasySpanName.java @@ -5,22 +5,22 @@ package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.NESTED_CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.NESTED_CONTROLLER; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.bootstrap.jaxrs.JaxrsContextPath; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.annotation.Nullable; -public final class ResteasySpanName implements ServerSpanNameSupplier { +public final class ResteasySpanName implements HttpRouteGetter { public static final ResteasySpanName INSTANCE = new ResteasySpanName(); public void updateServerSpanName(Context context, String name) { if (name != null) { - ServerSpanNaming.updateServerSpanName(context, NESTED_CONTROLLER, this, name); + HttpRouteHolder.updateHttpRoute(context, NESTED_CONTROLLER, this, name); } } diff --git a/instrumentation/jsf/jsf-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/JsfServerSpanNaming.java b/instrumentation/jsf/jsf-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/JsfServerSpanNaming.java index a2cdde3369df..19968bb99b0a 100644 --- a/instrumentation/jsf/jsf-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/JsfServerSpanNaming.java +++ b/instrumentation/jsf/jsf-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsf/JsfServerSpanNaming.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.jsf; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.faces.component.UIViewRoot; import javax.faces.context.FacesContext; public class JsfServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, facesContext) -> { UIViewRoot uiViewRoot = facesContext.getViewRoot(); if (uiViewRoot == null) { diff --git a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/RestoreViewPhaseInstrumentation.java b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/RestoreViewPhaseInstrumentation.java index f3896db4b4c2..0a7eff416cb3 100644 --- a/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/RestoreViewPhaseInstrumentation.java +++ b/instrumentation/jsf/jsf-mojarra-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mojarra/RestoreViewPhaseInstrumentation.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.mojarra; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.jsf.JsfServerSpanNaming; @@ -38,7 +38,7 @@ public static class ExecuteAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit(@Advice.Argument(0) FacesContext facesContext) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( currentContext(), CONTROLLER, JsfServerSpanNaming.SERVER_SPAN_NAME, facesContext); } } diff --git a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/RestoreViewExecutorInstrumentation.java b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/RestoreViewExecutorInstrumentation.java index d2fde63f5f0b..bb1bbf6a8322 100644 --- a/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/RestoreViewExecutorInstrumentation.java +++ b/instrumentation/jsf/jsf-myfaces-1.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/myfaces/RestoreViewExecutorInstrumentation.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.myfaces; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.jsf.JsfServerSpanNaming; @@ -38,7 +38,7 @@ public static class ExecuteAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit(@Advice.Argument(0) FacesContext facesContext) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( currentContext(), CONTROLLER, JsfServerSpanNaming.SERVER_SPAN_NAME, facesContext); } } diff --git a/instrumentation/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index b6f0a9af0923..599cd7cfac8f 100644 --- a/instrumentation/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -19,11 +19,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming import kotlinx.coroutines.withContext class KtorServerTracing private constructor( @@ -102,7 +103,7 @@ class KtorServerTracing private constructor( addAttributesExtractor(NetServerAttributesExtractor.create(KtorNetServerAttributesGetter())) addAttributesExtractor(httpAttributesExtractor) addRequestMetrics(HttpServerMetrics.get()) - addContextCustomizer(ServerSpanNaming.get()) + addContextCustomizer(HttpRouteHolder.get()) } val instrumenter = instrumenterBuilder.newServerInstrumenter(ApplicationRequestGetter) @@ -152,7 +153,7 @@ class KtorServerTracing private constructor( pipeline.environment.monitor.subscribe(Routing.RoutingCallStarted) { call -> val context = call.attributes.getOrNull(contextKey) if (context != null) { - ServerSpanNaming.updateServerSpanName(context, ServerSpanNaming.Source.SERVLET, { _, arg -> arg.route.parent.toString() }, call) + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, { _, arg -> arg.route.parent.toString() }, call) } } diff --git a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java index 04a85e15a8ec..44cf9de9d65f 100644 --- a/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java +++ b/instrumentation/liberty/liberty-dispatcher/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -9,12 +9,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; public final class LibertyDispatcherSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.liberty-dispatcher"; @@ -37,7 +37,7 @@ public final class LibertyDispatcherSingletons { .setSpanStatusExtractor(spanStatusExtractor) .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .addRequestMetrics(HttpServerMetrics.get()) .newServerInstrumenter(LibertyDispatcherRequestGetter.INSTANCE); } diff --git a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java index 8ab24ea04764..b0951d323533 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java +++ b/instrumentation/netty/netty-3.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/v3_8/server/NettyServerSingletons.java @@ -7,11 +7,11 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder; import io.opentelemetry.javaagent.instrumentation.netty.v3_8.HttpRequestAndChannel; import org.jboss.netty.handler.codec.http.HttpResponse; @@ -36,7 +36,7 @@ final class NettyServerSingletons { .addRequestMetrics(HttpServerMetrics.get()) .addContextCustomizer( (context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context)) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .newServerInstrumenter(NettyHeadersGetter.INSTANCE); } diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyServerInstrumenterFactory.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyServerInstrumenterFactory.java index 70b8b661d12d..085557034c8f 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyServerInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyServerInstrumenterFactory.java @@ -8,11 +8,11 @@ import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; import io.opentelemetry.javaagent.instrumentation.netty.common.NettyErrorHolder; @@ -34,7 +34,7 @@ public static Instrumenter create( NetServerAttributesExtractor.create(new NettyNetServerAttributesGetter())) .addRequestMetrics(HttpServerMetrics.get()) .addContextCustomizer((context, request, attributes) -> NettyErrorHolder.init(context)) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .newServerInstrumenter(HttpRequestHeadersGetter.INSTANCE); } diff --git a/instrumentation/ratpack/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackSingletons.java b/instrumentation/ratpack/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackSingletons.java index 2832f2fa73be..2545f321ec4b 100644 --- a/instrumentation/ratpack/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackSingletons.java +++ b/instrumentation/ratpack/ratpack-1.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/RatpackSingletons.java @@ -10,7 +10,8 @@ import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.instrumentation.api.instrumenter.ErrorCauseExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import ratpack.handling.Context; public final class RatpackSingletons { @@ -40,8 +41,8 @@ public static String updateServerSpanName( } // update the netty server span name; FILTER is probably the best match for ratpack Handlers - ServerSpanNaming.updateServerSpanName( - otelContext, ServerSpanNaming.Source.FILTER, (context, name) -> name, matchedRoute); + HttpRouteHolder.updateHttpRoute( + otelContext, HttpRouteSource.FILTER, (context, name) -> name, matchedRoute); return matchedRoute; } diff --git a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RestletSingletons.java b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RestletSingletons.java index 39b2d00634ce..4071624e619c 100644 --- a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RestletSingletons.java +++ b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RestletSingletons.java @@ -7,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.instrumentation.restlet.v1_0.RestletTracing; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.restlet.data.Request; @@ -22,7 +22,7 @@ public static Instrumenter instrumenter() { return INSTRUMENTER; } - public static ServerSpanNameSupplier serverSpanName() { + public static HttpRouteGetter serverSpanName() { return ServletContextPath::prepend; } diff --git a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RouteInstrumentation.java b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RouteInstrumentation.java index 6d0f0425421b..e9c9c96b5a65 100644 --- a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RouteInstrumentation.java +++ b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/RouteInstrumentation.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v1_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.instrumentation.restlet.v1_0.RestletSingletons.serverSpanName; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -44,8 +44,7 @@ public static class RouteBeforeHandleAdvice { public static void getRouteInfo(@Advice.This Route route, @Advice.Argument(0) Request request) { String pattern = route.getTemplate().getPattern(); - ServerSpanNaming.updateServerSpanName( - currentContext(), CONTROLLER, serverSpanName(), pattern); + HttpRouteHolder.updateHttpRoute(currentContext(), CONTROLLER, serverSpanName(), pattern); } } } diff --git a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/ServerInstrumentation.java b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/ServerInstrumentation.java index cd712723ab8b..0b1065912266 100644 --- a/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/ServerInstrumentation.java +++ b/instrumentation/restlet/restlet-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v1_0/ServerInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v1_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.instrumentation.restlet.v1_0.RestletSingletons.instrumenter; import static io.opentelemetry.javaagent.instrumentation.restlet.v1_0.RestletSingletons.serverSpanName; @@ -15,7 +15,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -76,7 +76,7 @@ public static void finishRequest( scope.close(); if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) { - ServerSpanNaming.updateServerSpanName(context, CONTROLLER, serverSpanName(), "/*"); + HttpRouteHolder.updateHttpRoute(context, CONTROLLER, serverSpanName(), "/*"); } if (exception != null) { diff --git a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/TracingFilter.java b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/TracingFilter.java index 3a324633219d..585410e46c6a 100644 --- a/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/TracingFilter.java +++ b/instrumentation/restlet/restlet-1.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_0/TracingFilter.java @@ -5,12 +5,12 @@ package io.opentelemetry.instrumentation.restlet.v1_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import org.restlet.Filter; import org.restlet.data.Request; import org.restlet.data.Response; @@ -38,7 +38,7 @@ public int doHandle(Request request, Response response) { scope = context.makeCurrent(); } - ServerSpanNaming.updateServerSpanName(context, CONTROLLER, (ctx, s) -> s, path); + HttpRouteHolder.updateHttpRoute(context, CONTROLLER, (ctx, s) -> s, path); Throwable statusThrowable = null; try { 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 ef06a86fca8e..43ee5de33dc3 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,7 +7,7 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.instrumentation.restlet.v2_0.internal.RestletInstrumenterFactory; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.restlet.Request; @@ -22,7 +22,7 @@ public static Instrumenter instrumenter() { return INSTRUMENTER; } - public static ServerSpanNameSupplier serverSpanName() { + public static HttpRouteGetter serverSpanName() { return ServletContextPath::prepend; } diff --git a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RouteInstrumentation.java b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RouteInstrumentation.java index fb99ad4fcb66..d803747078b5 100644 --- a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RouteInstrumentation.java +++ b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RouteInstrumentation.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v2_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.instrumentation.restlet.v2_0.RestletSingletons.serverSpanName; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -45,8 +45,7 @@ public static void getRouteInfo( @Advice.This TemplateRoute route, @Advice.Argument(0) Request request) { String pattern = route.getTemplate().getPattern(); - ServerSpanNaming.updateServerSpanName( - currentContext(), CONTROLLER, serverSpanName(), pattern); + HttpRouteHolder.updateHttpRoute(currentContext(), CONTROLLER, serverSpanName(), pattern); } } } diff --git a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/ServerInstrumentation.java b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/ServerInstrumentation.java index 0818ec14a75e..8379366588f3 100644 --- a/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/ServerInstrumentation.java +++ b/instrumentation/restlet/restlet-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/ServerInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v2_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.instrumentation.restlet.v2_0.RestletSingletons.instrumenter; import static io.opentelemetry.javaagent.instrumentation.restlet.v2_0.RestletSingletons.serverSpanName; @@ -15,7 +15,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -76,7 +76,7 @@ public static void finishRequest( scope.close(); if (Status.CLIENT_ERROR_NOT_FOUND.equals(response.getStatus())) { - ServerSpanNaming.updateServerSpanName(context, CONTROLLER, serverSpanName(), "/*"); + HttpRouteHolder.updateHttpRoute(context, CONTROLLER, serverSpanName(), "/*"); } if (exception != null) { diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/TracingFilter.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/TracingFilter.java index c74a005c18e1..05d092361035 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/TracingFilter.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/TracingFilter.java @@ -5,12 +5,12 @@ package io.opentelemetry.instrumentation.restlet.v2_0; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import org.restlet.Request; import org.restlet.Response; import org.restlet.resource.ResourceException; @@ -39,7 +39,7 @@ public int doHandle(Request request, Response response) { scope = context.makeCurrent(); } - ServerSpanNaming.updateServerSpanName(context, CONTROLLER, (ctx, s) -> s, path); + HttpRouteHolder.updateHttpRoute(context, CONTROLLER, (ctx, s) -> s, path); Throwable statusThrowable = null; try { diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java index 5c0ec8e40149..6e240c025559 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/BaseServletHelper.java @@ -5,15 +5,15 @@ package io.opentelemetry.javaagent.instrumentation.servlet; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.FILTER; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.SERVLET; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.FILTER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.SERVLET; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.server.ServerSpan; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.bootstrap.servlet.MappingResolver; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; @@ -84,7 +84,7 @@ public Context updateContext( Context context, REQUEST request, MappingResolver mappingResolver, boolean servlet) { Context result = addServletContextPath(context, request); if (mappingResolver != null) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( result, servlet ? SERVLET : FILTER, spanNameProvider, mappingResolver, request); } 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 06074f8da818..3ae79ba406b3 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 @@ -12,12 +12,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import java.util.ArrayList; import java.util.List; @@ -64,7 +64,7 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> requestParametersExtractor = new ServletRequestParametersExtractor<>(accessor); diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java index 7295bb831484..16ea2019b5d1 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java @@ -6,14 +6,14 @@ package io.opentelemetry.javaagent.instrumentation.servlet; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameTwoArgSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter2; import io.opentelemetry.javaagent.bootstrap.servlet.MappingResolver; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.annotation.Nullable; /** Helper class for constructing span name for given servlet/filter mapping and request. */ public class ServletSpanNameProvider - implements ServerSpanNameTwoArgSupplier { + implements HttpRouteGetter2 { private final ServletAccessor servletAccessor; public ServletSpanNameProvider(ServletAccessor servletAccessor) { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerAdapterInstrumentation.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerAdapterInstrumentation.java index 47969fadacb2..01cf025e9c7a 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerAdapterInstrumentation.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/HandlerAdapterInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.javaagent.instrumentation.springwebmvc.IsGrailsHandler.isGrailsHandler; @@ -19,7 +19,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; @@ -74,7 +74,7 @@ public static void nameResourceAndStartSpan( } // Name the parent span based on the matching pattern - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, CONTROLLER, SpringWebMvcServerSpanNaming.SERVER_SPAN_NAME, request); if (!handlerInstrumenter().shouldStart(parentContext, handler)) { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/SpringWebMvcServerSpanNaming.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/SpringWebMvcServerSpanNaming.java index baf1512d5342..08863a5bdb4b 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/SpringWebMvcServerSpanNaming.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/springwebmvc/SpringWebMvcServerSpanNaming.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.springwebmvc; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.servlet.http.HttpServletRequest; import org.springframework.web.servlet.HandlerMapping; public class SpringWebMvcServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, request) -> { Object bestMatchingPattern = request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/org/springframework/web/servlet/OpenTelemetryHandlerMappingFilter.java b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/org/springframework/web/servlet/OpenTelemetryHandlerMappingFilter.java index a3c22de9004d..82c25a456e8d 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/org/springframework/web/servlet/OpenTelemetryHandlerMappingFilter.java +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/main/java/org/springframework/web/servlet/OpenTelemetryHandlerMappingFilter.java @@ -5,11 +5,11 @@ package org.springframework.web.servlet; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.instrumentation.springwebmvc.SpringWebMvcServerSpanNaming; import java.io.IOException; import java.lang.invoke.MethodHandle; @@ -35,7 +35,7 @@ public class OpenTelemetryHandlerMappingFilter implements Filter, Ordered { private static final MethodHandle usesPathPatternsMh = getUsesPathPatternsMh(); private static final MethodHandle parseAndCacheMh = parseAndCacheMh(); - private final ServerSpanNameSupplier serverSpanName = + private final HttpRouteGetter serverSpanName = (context, request) -> { Object previousValue = null; if (this.parseRequestPath && PATH_ATTRIBUTE != null) { @@ -82,7 +82,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha } finally { if (handlerMappings != null) { Context context = Context.current(); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( context, CONTROLLER, serverSpanName, (HttpServletRequest) request); } } diff --git a/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcTracingBuilder.java b/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcTracingBuilder.java index 0853ba63b8a9..2b11ae49e913 100644 --- a/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcTracingBuilder.java +++ b/instrumentation/spring/spring-webmvc-3.1/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/SpringWebMvcTracingBuilder.java @@ -10,11 +10,11 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -76,7 +76,7 @@ public SpringWebMvcTracing build() { NetServerAttributesExtractor.create(new SpringWebMvcNetAttributesGetter())) .addAttributesExtractors(additionalExtractors) .addRequestMetrics(HttpServerMetrics.get()) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .newServerInstrumenter(JavaxHttpServletRequestGetter.INSTANCE); return new SpringWebMvcTracing(instrumenter); diff --git a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/ActionInvocationInstrumentation.java b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/ActionInvocationInstrumentation.java index c58568cb35db..e4ca7f1046e8 100644 --- a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/ActionInvocationInstrumentation.java +++ b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/ActionInvocationInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.struts2; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.javaagent.instrumentation.struts2.StrutsSingletons.instrumenter; @@ -16,7 +16,7 @@ import com.opensymphony.xwork2.ActionInvocation; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; @@ -53,7 +53,7 @@ public static void onEnter( @Advice.Local("otelScope") Scope scope) { Context parentContext = Java8BytecodeBridge.currentContext(); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( parentContext, CONTROLLER, StrutsServerSpanNaming.SERVER_SPAN_NAME, diff --git a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/StrutsServerSpanNaming.java b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/StrutsServerSpanNaming.java index 989f28f36530..06766c314328 100644 --- a/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/StrutsServerSpanNaming.java +++ b/instrumentation/struts-2.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/struts2/StrutsServerSpanNaming.java @@ -6,12 +6,12 @@ package io.opentelemetry.javaagent.instrumentation.struts2; import com.opensymphony.xwork2.ActionProxy; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; public class StrutsServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, actionProxy) -> { // We take name from the config, because it contains the path pattern from the // configuration. diff --git a/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/InitializeActivePageNameInstrumentation.java b/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/InitializeActivePageNameInstrumentation.java index 96d0040b5002..72f1c694f99c 100644 --- a/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/InitializeActivePageNameInstrumentation.java +++ b/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/InitializeActivePageNameInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.tapestry; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -13,7 +13,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -58,7 +58,7 @@ public static class HandleComponentEventAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void onEnter(@Advice.Argument(0) ComponentEventRequestParameters parameters) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( currentContext(), CONTROLLER, TapestryServerSpanNaming.SERVER_SPAN_NAME, @@ -71,7 +71,7 @@ public static class HandlePageRenderAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void onEnter(@Advice.Argument(0) PageRenderRequestParameters parameters) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( currentContext(), CONTROLLER, TapestryServerSpanNaming.SERVER_SPAN_NAME, diff --git a/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/TapestryServerSpanNaming.java b/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/TapestryServerSpanNaming.java index 85b3b7d28789..c4195cf38760 100644 --- a/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/TapestryServerSpanNaming.java +++ b/instrumentation/tapestry-5.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/tapestry/TapestryServerSpanNaming.java @@ -5,12 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.tapestry; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; public class TapestryServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, pageName) -> { if (pageName == null) { return null; 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 53a1e07c6c2e..a945944c1e82 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 @@ -10,12 +10,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.instrumentation.servlet.ServletAccessor; import io.opentelemetry.javaagent.instrumentation.servlet.ServletErrorCauseExtractor; @@ -48,7 +48,7 @@ public static Instrumenter create( .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) .addAttributesExtractor(additionalAttributeExtractor) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .addContextCustomizer( (context, request, attributes) -> new AppServerBridge.Builder() 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 a940eb740a6d..2824cdfd8af0 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 @@ -9,12 +9,12 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.bootstrap.undertow.UndertowActiveHandlers; import io.undertow.server.HttpServerExchange; @@ -40,7 +40,7 @@ public final class UndertowSingletons { .setSpanStatusExtractor(spanStatusExtractor) .addAttributesExtractor(httpAttributesExtractor) .addAttributesExtractor(netAttributesExtractor) - .addContextCustomizer(ServerSpanNaming.get()) + .addContextCustomizer(HttpRouteHolder.get()) .addContextCustomizer( (context, request, attributes) -> { // span is ended when counter reaches 0, we start from 2 which accounts for the diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHelper.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHelper.java index 0a87a6a5e38d..5dbbcc54f658 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHelper.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinHelper.java @@ -12,7 +12,8 @@ import com.vaadin.flow.router.Location; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.annotation.Nullable; @@ -41,9 +42,9 @@ public void endVaadinServiceSpan( Context context, VaadinServiceRequest request, Throwable throwable) { serviceInstrumenter.end(context, request, null, throwable); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( context, - ServerSpanNaming.Source.CONTROLLER, + HttpRouteSource.CONTROLLER, (c, req) -> getSpanNameForVaadinServiceContext(c, req), request); } @@ -106,9 +107,9 @@ public void updateServerSpanName(UI ui) { public void updateServerSpanName(Location location) { Context context = Context.current(); - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( context, - ServerSpanNaming.Source.NESTED_CONTROLLER, + HttpRouteSource.NESTED_CONTROLLER, (c, loc) -> ServletContextPath.prepend(c, getSpanNameForLocation(loc)), location); } diff --git a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java index cf32c27506c5..dfd61d7e67cb 100644 --- a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java +++ b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/RequestHandlerExecutorInstrumentation.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.wicket; -import static io.opentelemetry.instrumentation.api.server.ServerSpanNaming.Source.CONTROLLER; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.server.ServerSpan; -import io.opentelemetry.instrumentation.api.server.ServerSpanNaming; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; @@ -47,7 +47,7 @@ public static void onExit(@Advice.Argument(0) IRequestHandler handler) { return; } if (handler instanceof IPageClassRequestHandler) { - ServerSpanNaming.updateServerSpanName( + HttpRouteHolder.updateHttpRoute( context, CONTROLLER, WicketServerSpanNaming.SERVER_SPAN_NAME, diff --git a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java index 568c312098ec..a2b9d9349b0b 100644 --- a/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java +++ b/instrumentation/wicket-8.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketServerSpanNaming.java @@ -5,14 +5,14 @@ package io.opentelemetry.javaagent.instrumentation.wicket; -import io.opentelemetry.instrumentation.api.server.ServerSpanNameSupplier; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import org.apache.wicket.core.request.handler.IPageClassRequestHandler; import org.apache.wicket.request.cycle.RequestCycle; public final class WicketServerSpanNaming { - public static final ServerSpanNameSupplier SERVER_SPAN_NAME = + public static final HttpRouteGetter SERVER_SPAN_NAME = (context, handler) -> { // using class name as page name String pageName = handler.getPageClass().getName(); From 344c7f4efbce460b78524c031c62115992873d51 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 25 Jan 2022 10:40:14 +0100 Subject: [PATCH 2/2] HttpRouteBiGetter --- .../{HttpRouteGetter2.java => HttpRouteBiGetter.java} | 2 +- .../api/instrumenter/http/HttpRouteHolder.java | 10 +++++----- .../servlet/ServletSpanNameProvider.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/{HttpRouteGetter2.java => HttpRouteBiGetter.java} (92%) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteBiGetter.java similarity index 92% rename from instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java rename to instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteBiGetter.java index a93df506c2d3..4a7008953bd8 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteGetter2.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteBiGetter.java @@ -10,7 +10,7 @@ /** An interface for getting the {@code http.route} attribute. */ @FunctionalInterface -public interface HttpRouteGetter2 { +public interface HttpRouteBiGetter { /** * Returns the {@code http.route} attribute extracted from {@code context}, {@code arg1} and diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index f3d74ef0f6a6..ddf3ed74b0e8 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -69,18 +69,18 @@ public static void updateHttpRoute( * *

If there is a server span in the context, and the context has been customized with a {@link * HttpRouteHolder}, then this method will update the route using the provided {@link - * HttpRouteGetter2} if and only if the last {@link HttpRouteSource} to update the route using + * HttpRouteBiGetter} if and only if the last {@link HttpRouteSource} to update the route using * this method has strictly lower priority than the provided {@link HttpRouteSource}, and the - * value returned from the {@link HttpRouteGetter2} is non-null. + * value returned from the {@link HttpRouteBiGetter} is non-null. * *

If there is a server span in the context, and the context has NOT been customized with a * {@code ServerSpanName}, then this method will update the route using the provided {@link - * HttpRouteGetter2} if the value returned from it is non-null. + * HttpRouteBiGetter} if the value returned from it is non-null. */ public static void updateHttpRoute( Context context, HttpRouteSource source, - HttpRouteGetter2 httpRouteGetter, + HttpRouteBiGetter httpRouteGetter, T arg1, U arg2) { Span serverSpan = ServerSpan.fromContextOrNull(context); @@ -139,7 +139,7 @@ public static String getRoute(Context context) { return httpRouteHolder == null ? null : httpRouteHolder.route; } - private static final class OneArgAdapter implements HttpRouteGetter2> { + private static final class OneArgAdapter implements HttpRouteBiGetter> { private static final OneArgAdapter INSTANCE = new OneArgAdapter<>(); diff --git a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java index 16ea2019b5d1..7c22758fcbc3 100644 --- a/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java +++ b/instrumentation/servlet/servlet-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/ServletSpanNameProvider.java @@ -6,14 +6,14 @@ package io.opentelemetry.javaagent.instrumentation.servlet; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteGetter2; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteBiGetter; import io.opentelemetry.javaagent.bootstrap.servlet.MappingResolver; import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; import javax.annotation.Nullable; /** Helper class for constructing span name for given servlet/filter mapping and request. */ public class ServletSpanNameProvider - implements HttpRouteGetter2 { + implements HttpRouteBiGetter { private final ServletAccessor servletAccessor; public ServletSpanNameProvider(ServletAccessor servletAccessor) {