diff --git a/examples/distro/instrumentation/servlet-3/src/test/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationTest.java b/examples/distro/instrumentation/servlet-3/src/test/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationTest.java index 4cb22b8ae19c..96039f43ee67 100644 --- a/examples/distro/instrumentation/servlet-3/src/test/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationTest.java +++ b/examples/distro/instrumentation/servlet-3/src/test/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationTest.java @@ -86,7 +86,7 @@ void shouldAddCustomHeader() throws Exception { trace .hasSize(1) .hasSpansSatisfyingExactly( - span -> span.hasName("/servlet").hasKind(SpanKind.SERVER))); + span -> span.hasName("GET /servlet").hasKind(SpanKind.SERVER))); var traceId = instrumentation.spans().get(0).getTraceId(); assertEquals(traceId, response.header("X-server-id")); diff --git a/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java b/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java index 571f56974070..576488938fe0 100644 --- a/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java +++ b/examples/distro/smoke-tests/src/test/java/com/example/javaagent/smoketest/SpringBootSmokeTest.java @@ -47,7 +47,7 @@ public void springBootSmokeTestOnJDK() throws IOException, InterruptedException Assertions.assertEquals(1, response.headers("X-server-id").size()); Assertions.assertTrue(TraceId.isValid(response.header("X-server-id"))); Assertions.assertEquals("Hi!", response.body().string()); - Assertions.assertEquals(1, countSpansByName(traces, "/greeting")); + Assertions.assertEquals(1, countSpansByName(traces, "GET /greeting")); Assertions.assertEquals(0, countSpansByName(traces, "WebController.greeting")); Assertions.assertEquals(1, countSpansByName(traces, "WebController.withSpan")); Assertions.assertEquals(2, countSpansByAttributeValue(traces, "custom", "demo")); diff --git a/examples/extension/src/test/java/com/example/javaagent/smoketest/SpringBootIntegrationTest.java b/examples/extension/src/test/java/com/example/javaagent/smoketest/SpringBootIntegrationTest.java index 80cb84f0ab48..c320031344d5 100644 --- a/examples/extension/src/test/java/com/example/javaagent/smoketest/SpringBootIntegrationTest.java +++ b/examples/extension/src/test/java/com/example/javaagent/smoketest/SpringBootIntegrationTest.java @@ -71,7 +71,7 @@ private void testAndVerify() throws IOException, InterruptedException { Assertions.assertEquals(1, response.headers("X-server-id").size()); Assertions.assertTrue(TraceId.isValid(response.header("X-server-id"))); Assertions.assertEquals("Hi!", response.body().string()); - Assertions.assertEquals(1, countSpansByName(traces, "/greeting")); + Assertions.assertEquals(1, countSpansByName(traces, "GET /greeting")); Assertions.assertEquals(0, countSpansByName(traces, "WebController.greeting")); Assertions.assertEquals(1, countSpansByName(traces, "WebController.withSpan")); Assertions.assertEquals(2, countSpansByAttributeValue(traces, "custom", "demo")); diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java index f0e87b7cf89d..bab62143c8cb 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolder.java @@ -28,13 +28,31 @@ public final class HttpRouteHolder { /** * Returns a {@link ContextCustomizer} that initializes a {@link HttpRouteHolder} in the {@link * Context} returned from {@link Instrumenter#start(Context, Object)}. + * + * @deprecated Use {@link #create(HttpServerAttributesGetter)} instead. */ + @Deprecated public static ContextCustomizer get() { return (context, request, startAttributes) -> { if (HttpRouteState.fromContextOrNull(context) != null) { return context; } - return context.with(HttpRouteState.create(0, null)); + return context.with(HttpRouteState.create(null, null, 0)); + }; + } + + /** + * Returns a {@link ContextCustomizer} that initializes a {@link HttpRouteHolder} in the {@link + * Context} returned from {@link Instrumenter#start(Context, Object)}. + */ + public static ContextCustomizer create( + HttpServerAttributesGetter getter) { + return (context, request, startAttributes) -> { + if (HttpRouteState.fromContextOrNull(context) != null) { + return context; + } + String method = getter.getMethod(request); + return context.with(HttpRouteState.create(method, null, 0)); }; } @@ -103,10 +121,10 @@ public static void updateHttpRoute( } HttpRouteState httpRouteState = HttpRouteState.fromContextOrNull(context); if (httpRouteState == null) { + // TODO: remove this branch? String httpRoute = httpRouteGetter.get(context, arg1, arg2); if (httpRoute != null && !httpRoute.isEmpty()) { - // update both span name and attribute, since there's no HttpRouteHolder in the context - serverSpan.updateName(httpRoute); + // update just the attribute - without http.method we can't compute a proper span name here serverSpan.setAttribute(SemanticAttributes.HTTP_ROUTE, httpRoute); } return; @@ -123,7 +141,7 @@ public static void updateHttpRoute( // update just the span name - the attribute will be picked up by the // HttpServerAttributesExtractor at the end of request processing - serverSpan.updateName(route); + updateSpanName(serverSpan, httpRouteState, route); httpRouteState.update(context, source.order, route); } @@ -138,6 +156,15 @@ private static boolean isBetterRoute(HttpRouteState httpRouteState, String name) return name.length() > routeLength; } + private static void updateSpanName(Span serverSpan, HttpRouteState httpRouteState, String route) { + String method = httpRouteState.getMethod(); + // method should never really be null - but in case it for some reason is, we'll rely on the + // span name extractor behavior + if (method != null) { + serverSpan.updateName(method + " " + route); + } + } + /** * Returns the {@code http.route} attribute value that's stored in the {@code context}, or null if * it was not set before. diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java index dfa4a33a9970..83aa8ca749c5 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractor.java @@ -33,15 +33,12 @@ private HttpSpanNameExtractor(HttpCommonAttributesGetter getter) { @Override public String extract(REQUEST request) { - String route = extractRoute(request); - if (route != null) { - return route; - } String method = getter.getMethod(request); + String route = extractRoute(request); if (method != null) { - return "HTTP " + method; + return route == null ? method : method + " " + route; } - return "HTTP request"; + return "HTTP"; } @Nullable diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolderTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolderTest.java index a74ad863ce04..d2a9894a26e5 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolderTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpRouteHolderTest.java @@ -5,34 +5,170 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.Mockito.when; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +@ExtendWith(MockitoExtension.class) class HttpRouteHolderTest { - @RegisterExtension final OpenTelemetryExtension testing = OpenTelemetryExtension.create(); + @RegisterExtension static final OpenTelemetryExtension testing = OpenTelemetryExtension.create(); - @Test - void shouldSetRouteEvenIfSpanIsNotSampled() { - Instrumenter instrumenter = + @Mock HttpServerAttributesGetter getter; + Instrumenter instrumenter; + + @BeforeEach + void setUp() { + instrumenter = Instrumenter.builder(testing.getOpenTelemetry(), "test", s -> s) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(getter)) .buildInstrumenter(); + } - Context context = instrumenter.start(Context.root(), "test"); + @Test + void noLocalRootSpan() { + Span parentSpan = + testing.getOpenTelemetry().getTracer("test").spanBuilder("parent").startSpan(); + parentSpan.end(); + + Context context = instrumenter.start(Context.root().with(parentSpan), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/get/:id"); + + instrumenter.end(context, "test", null, null); + assertNull(HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly( + span -> assertThat(span).hasName("parent"), span -> assertThat(span).hasName("test")); + } + + @Test + void shouldSetRoute() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); assertNull(HttpRouteHolder.getRoute(context)); HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/get/:id"); + instrumenter.end(context, "test", null, null); + assertEquals("/get/:id", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /get/:id")); + } + + @Test + void shouldNotUpdateRoute_sameSource() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/route1"); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/route2"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/route1", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /route1")); + } + + @Test + void shouldNotUpdateRoute_lowerOrderSource() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.CONTROLLER, "/route1"); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/route2"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/route1", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /route1")); + } + + @Test + void shouldUpdateRoute_higherOrderSource() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/route1"); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.CONTROLLER, "/route2"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/route2", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /route2")); + } + + @Test + void shouldUpdateRoute_betterMatch() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.FILTER, "/a/route"); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.FILTER, "/a/much/better/route"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/a/much/better/route", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /a/much/better/route")); + } + + @Test + void shouldNotUpdateRoute_worseMatch() { + when(getter.getMethod("test")).thenReturn("GET"); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.FILTER, "/a/pretty/good/route"); + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.FILTER, "/a"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/a/pretty/good/route", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()) + .satisfiesExactly(span -> assertThat(span).hasName("GET /a/pretty/good/route")); } - // TODO(mateusz): add more unit tests for HttpRouteHolder + @Test + void shouldNotUpdateSpanName_noMethod() { + when(getter.getMethod("test")).thenReturn(null); + + Context context = instrumenter.start(Context.root(), "test"); + assertNull(HttpRouteHolder.getRoute(context)); + + HttpRouteHolder.updateHttpRoute(context, HttpRouteSource.SERVLET, "/get/:id"); + + instrumenter.end(context, "test", null, null); + + assertEquals("/get/:id", HttpRouteHolder.getRoute(context)); + assertThat(testing.getSpans()).satisfiesExactly(span -> assertThat(span).hasName("test")); + } } diff --git a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java index 65d5010f9a79..206fe054f23b 100644 --- a/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java +++ b/instrumentation-api-semconv/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpSpanNameExtractorTest.java @@ -31,19 +31,19 @@ void routeAndMethod() { when(serverGetter.getRoute(anyMap())).thenReturn("/cats/{id}"); when(serverGetter.getMethod(anyMap())).thenReturn("GET"); assertThat(HttpSpanNameExtractor.create(serverGetter).extract(Collections.emptyMap())) - .isEqualTo("/cats/{id}"); + .isEqualTo("GET /cats/{id}"); } @Test void method() { when(clientGetter.getMethod(anyMap())).thenReturn("GET"); assertThat(HttpSpanNameExtractor.create(clientGetter).extract(Collections.emptyMap())) - .isEqualTo("HTTP GET"); + .isEqualTo("GET"); } @Test void nothing() { assertThat(HttpSpanNameExtractor.create(clientGetter).extract(Collections.emptyMap())) - .isEqualTo("HTTP request"); + .isEqualTo("HTTP"); } } diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/HttpRouteState.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/HttpRouteState.java index 3fe1f70ea030..0eda2755da92 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/HttpRouteState.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/HttpRouteState.java @@ -24,14 +24,18 @@ public static HttpRouteState fromContextOrNull(Context context) { return context.get(KEY); } - public static HttpRouteState create(int updatedBySourceOrder, @Nullable String route) { - return new HttpRouteState(updatedBySourceOrder, route); + public static HttpRouteState create( + @Nullable String method, @Nullable String route, int updatedBySourceOrder) { + return new HttpRouteState(method, route, updatedBySourceOrder); } - private volatile int updatedBySourceOrder; + @Nullable private final String method; @Nullable private volatile String route; + private volatile int updatedBySourceOrder; - private HttpRouteState(int updatedBySourceOrder, @Nullable String route) { + private HttpRouteState( + @Nullable String method, @Nullable String route, int updatedBySourceOrder) { + this.method = method; this.updatedBySourceOrder = updatedBySourceOrder; this.route = route; } @@ -41,6 +45,11 @@ public Context storeInContext(Context context) { return context.with(KEY, this); } + @Nullable + public String getMethod() { + return method; + } + public int getUpdatedBySourceOrder() { return updatedBySourceOrder; } 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 5058d6e1cac7..f676fbe503c7 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 @@ -36,7 +36,7 @@ httpAttributesGetter, new AkkaNetServerAttributesGetter()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .build()) .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(AkkaHttpServerHeaders.INSTANCE); } diff --git a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java index bc459b5fcc03..b2c461977e37 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java +++ b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/decorators/HttpSpanDecorator.java @@ -74,11 +74,11 @@ protected static String getHttpMethod(Exchange exchange, Endpoint endpoint) { public String getOperationName( Exchange exchange, Endpoint endpoint, CamelDirection camelDirection) { // Based on HTTP component documentation: - String spanName = null; - if (shouldSetPathAsName(camelDirection)) { - spanName = getPath(exchange, endpoint); + String spanName = getHttpMethod(exchange, endpoint); + if (shouldAppendHttpRoute(camelDirection)) { + spanName = spanName + " " + getPath(exchange, endpoint); } - return (spanName == null ? getHttpMethod(exchange, endpoint) : spanName); + return spanName; } @Override @@ -97,7 +97,7 @@ public void pre( attributes.put(SemanticAttributes.HTTP_METHOD, getHttpMethod(exchange, endpoint)); } - static boolean shouldSetPathAsName(CamelDirection camelDirection) { + private static boolean shouldAppendHttpRoute(CamelDirection camelDirection) { return camelDirection == CamelDirection.INBOUND; } @@ -119,7 +119,7 @@ public void updateServerSpanName( Exchange camelExchange, Endpoint camelEndpoint, CamelDirection camelDirection) { - if (!shouldSetPathAsName(camelDirection)) { + if (!shouldAppendHttpRoute(camelDirection)) { return; } HttpRouteHolder.updateHttpRoute( diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy index e68ed017126a..af4c22671749 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/RestCamelTest.groovy @@ -84,7 +84,7 @@ class RestCamelTest extends AgentInstrumentationSpecification implements RetryOn } } it.span(2) { - name "/api/{module}/unit/{unitId}" + name "GET /api/{module}/unit/{unitId}" kind SERVER parentSpanId(span(1).spanId) attributes { @@ -104,7 +104,7 @@ class RestCamelTest extends AgentInstrumentationSpecification implements RetryOn } } it.span(3) { - name "/api/{module}/unit/{unitId}" + name "GET /api/{module}/unit/{unitId}" kind INTERNAL parentSpanId(span(2).spanId) attributes { diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.groovy index 127cc012c534..7c8f9f1bddc3 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/SingleServiceCamelTest.groovy @@ -61,7 +61,7 @@ class SingleServiceCamelTest extends AgentInstrumentationSpecification implement trace(0, 1) { span(0) { kind SERVER - name "/camelService" + name "POST /camelService" attributes { "$SemanticAttributes.HTTP_METHOD" "POST" "$SemanticAttributes.HTTP_URL" "${address.resolve("/camelService")}" diff --git a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy index 21142d898d99..e310354ff510 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy +++ b/instrumentation/apache-camel-2.20/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/apachecamel/TwoServicesWithDirectClientCamelTest.groovy @@ -97,7 +97,7 @@ class TwoServicesWithDirectClientCamelTest extends AgentInstrumentationSpecifica } } it.span(2) { - name "/serviceOne" + name "POST /serviceOne" kind SERVER parentSpanId(span(1).spanId) attributes { @@ -119,7 +119,7 @@ class TwoServicesWithDirectClientCamelTest extends AgentInstrumentationSpecifica } } it.span(4) { - name "/serviceTwo" + name "POST /serviceTwo" kind SERVER parentSpanId(span(3).spanId) attributes { @@ -139,7 +139,7 @@ class TwoServicesWithDirectClientCamelTest extends AgentInstrumentationSpecifica } } it.span(5) { - name "/serviceTwo" + name "POST /serviceTwo" kind INTERNAL parentSpanId(span(4).spanId) attributes { diff --git a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java index a122d3dd0c9e..9490044d65ed 100644 --- a/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java +++ b/instrumentation/armeria-1.3/library/src/main/java/io/opentelemetry/instrumentation/armeria/v1_3/ArmeriaTelemetryBuilder.java @@ -179,7 +179,7 @@ public ArmeriaTelemetry build() { HttpSpanStatusExtractor.create(serverAttributesGetter))) .addAttributesExtractor(httpServerAttributesExtractorBuilder.build()) .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(HttpRouteHolder.get()); + .addContextCustomizer(HttpRouteHolder.create(serverAttributesGetter)); if (peerService != null) { clientInstrumenterBuilder.addAttributesExtractor( diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java index 99fa10c5c348..6c25f71ed401 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/main/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/internal/AwsLambdaEventsInstrumenterFactory.java @@ -32,11 +32,15 @@ public static AwsLambdaFunctionInstrumenter createInstrumenter(OpenTelemetry ope } private static String spanName(AwsLambdaRequest input) { - String name = null; if (input.getInput() instanceof APIGatewayProxyRequestEvent) { - name = ((APIGatewayProxyRequestEvent) input.getInput()).getResource(); + APIGatewayProxyRequestEvent request = (APIGatewayProxyRequestEvent) input.getInput(); + String method = request.getHttpMethod(); + String route = request.getResource(); + if (method != null && route != null) { + return method + " " + route; + } } - return name == null ? input.getAwsContext().getFunctionName() : name; + return input.getAwsContext().getFunctionName(); } private AwsLambdaEventsInstrumenterFactory() {} diff --git a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java index 157b681f182f..bc90f0957f9b 100644 --- a/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java +++ b/instrumentation/aws-lambda/aws-lambda-events-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/v2_2/AwsLambdaApiGatewayWrapperTest.java @@ -92,7 +92,7 @@ void tracedWithHttpPropagation() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/hello/{param}") + span.hasName("GET /hello/{param}") .hasKind(SpanKind.SERVER) .hasTraceId("4fd0b6131f19f39af59518d127b0cafe") .hasParentSpanId("0000000000000456") diff --git a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy index b9830005044e..7ef9c892deaf 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy @@ -83,7 +83,7 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification { } } span(1) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(0) attributes { @@ -156,7 +156,7 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(1) attributes { diff --git a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy index 522d8ba4218e..5ab11bcadb90 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy @@ -77,7 +77,7 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification { } } span(1) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(0) attributes { @@ -149,7 +149,7 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(1) attributes { diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy index ac32b39275bc..41d8e245d989 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy @@ -76,7 +76,7 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification { } } span(1) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(0) attributes { @@ -148,7 +148,7 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP GET" + name "GET" kind CLIENT childOf span(1) attributes { 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 839272f8e4db..0b8796134b5e 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 @@ -45,7 +45,7 @@ public final class GrizzlySingletons { .init(context)) .addContextCustomizer( (context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context)) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(HttpRequestHeadersGetter.INSTANCE); } diff --git a/instrumentation/gwt-2.0/javaagent/src/test/groovy/GwtTest.groovy b/instrumentation/gwt-2.0/javaagent/src/test/groovy/GwtTest.groovy index 7754172e5aa3..a86eca56d796 100644 --- a/instrumentation/gwt-2.0/javaagent/src/test/groovy/GwtTest.groovy +++ b/instrumentation/gwt-2.0/javaagent/src/test/groovy/GwtTest.groovy @@ -90,23 +90,23 @@ class GwtTest extends AgentInstrumentationSpecification implements HttpServerTes // wait for page to load driver.findElementByClassName("greeting.button") assertTraces(4) { - traces.sort(orderByRootSpanName("/*", "HTTP GET")) + traces.sort(orderByRootSpanName("GET " + getContextPath() + "/*", "GET")) // /xyz/greeting.html trace(0, 1) { - serverSpan(it, 0, getContextPath() + "/*") + serverSpan(it, 0, "GET " + getContextPath() + "/*") } // /xyz/greeting/greeting.nocache.js trace(1, 1) { - serverSpan(it, 0, getContextPath() + "/*") + serverSpan(it, 0, "GET " + getContextPath() + "/*") } // /xyz/greeting/1B105441581A8F41E49D5DF3FB5B55BA.cache.html trace(2, 1) { - serverSpan(it, 0, getContextPath() + "/*") + serverSpan(it, 0, "GET " + getContextPath() + "/*") } // /favicon.ico trace(3, 1) { - serverSpan(it, 0, "HTTP GET") + serverSpan(it, 0, "GET") } } clearExportedData() @@ -120,7 +120,7 @@ class GwtTest extends AgentInstrumentationSpecification implements HttpServerTes "Hello, Otel" == driver.findElementByClassName("message.received").getText() assertTraces(1) { trace(0, 2) { - serverSpan(it, 0, getContextPath() + "/greeting/greet") + serverSpan(it, 0, "POST " + getContextPath() + "/greeting/greet") span(1) { name "test.gwt.shared.MessageService/sendMessage" kind SpanKind.SERVER @@ -144,7 +144,7 @@ class GwtTest extends AgentInstrumentationSpecification implements HttpServerTes "Error" == driver.findElementByClassName("error.received").getText() assertTraces(1) { trace(0, 2) { - serverSpan(it, 0, getContextPath() + "/greeting/greet") + serverSpan(it, 0, "POST " + getContextPath() + "/greeting/greet") span(1) { name "test.gwt.shared.MessageService/sendMessage" kind SpanKind.SERVER diff --git a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java index 19b68488dc5f..7c0574a769f2 100644 --- a/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java +++ b/instrumentation/http-url-connection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpMethodAttributeExtractor.java @@ -42,7 +42,7 @@ public void onEnd( // The getOutputStream() has transformed "GET" into "POST" attributes.put(SemanticAttributes.HTTP_METHOD, requestMethod); Span span = Span.fromContext(context); - span.updateName("HTTP " + requestMethod); + span.updateName(requestMethod); } } } diff --git a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java index bacbda1dabdb..897717cbf3f0 100644 --- a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java +++ b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/HttpUrlConnectionTest.java @@ -131,7 +131,7 @@ public void traceRequest(boolean useCache) throws IOException { trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasNoParent(), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -148,7 +148,7 @@ public void traceRequest(boolean useCache) throws IOException { span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(1)), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -186,7 +186,7 @@ public void testBrokenApiUsage() throws IOException { trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasNoParent(), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -237,7 +237,7 @@ public void testPostRequest() throws IOException { trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasNoParent(), span -> - span.hasName("HTTP POST") + span.hasName("POST") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -293,7 +293,7 @@ public void getOutputStreamShouldTransformGetIntoPost() throws IOException { trace.hasSpansSatisfyingExactly( span -> span.hasName("someTrace").hasNoParent(), span -> - span.hasName("HTTP POST") + span.hasName("POST") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( diff --git a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/UrlConnectionTest.java b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/UrlConnectionTest.java index f3e7de236a06..e53ce4396a22 100644 --- a/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/UrlConnectionTest.java +++ b/instrumentation/http-url-connection/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/httpurlconnection/UrlConnectionTest.java @@ -58,7 +58,7 @@ public void traceRequestWithConnectionFailure(String scheme) { .hasStatus(StatusData.error()) .hasException(thrown), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasStatus(StatusData.error()) diff --git a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy index 974c07c3d588..a28c5b56293b 100644 --- a/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy +++ b/instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/groovy/JaxRsClientTest.groovy @@ -104,7 +104,7 @@ abstract class JaxRsClientTest extends HttpClientTest implem trace(0, 2) { span(0) { hasNoParent() - name "HTTP $method" + name "$method" kind CLIENT status ERROR attributes { diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy index 2c0d2beaba79..145a7ba5e59c 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy @@ -23,7 +23,7 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica @Unroll def "span named '#paramName' from annotations on class '#className' when is not root span"() { setup: - runWithHttpServerSpan("test") { + runWithHttpServerSpan { obj.call() } @@ -31,10 +31,11 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica assertTraces(1) { trace(0, 2) { span(0) { - name paramName + name "GET " + paramName kind SERVER hasNoParent() attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" paramName } } @@ -50,7 +51,7 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica } when: "multiple calls to the same method" - runWithHttpServerSpan("test") { + runWithHttpServerSpan { (1..10).each { obj.call() } @@ -112,7 +113,7 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica def "no annotations has no effect"() { setup: - runWithHttpServerSpan("test") { + runWithHttpServerSpan { obj.call() } @@ -120,9 +121,10 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica assertTraces(1) { trace(0, 1) { span(0) { - name "test" + name "GET" kind SERVER attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" } } } diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy index 6d7b7031cd7d..55c3621f5a67 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JerseyTest.groovy @@ -27,7 +27,7 @@ class JerseyTest extends AgentInstrumentationSpecification { def "test #resource"() { when: // start a trace because the test doesn't go through any servlet or other instrumentation. - def response = runWithHttpServerSpan("test.span") { + def response = runWithHttpServerSpan { resources.client().resource(resource).post(String) } @@ -37,9 +37,10 @@ class JerseyTest extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 2) { span(0) { - name expectedRoute + name "GET " + expectedRoute kind SERVER attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" expectedRoute } } @@ -66,7 +67,7 @@ class JerseyTest extends AgentInstrumentationSpecification { when: // start a trace because the test doesn't go through any servlet or other instrumentation. - def response = runWithHttpServerSpan("test.span") { + def response = runWithHttpServerSpan { resources.client().resource(resource).post(String) } @@ -76,9 +77,10 @@ class JerseyTest extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 2) { span(0) { - name expectedRoute + name "GET " + expectedRoute kind SERVER attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" expectedRoute } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy index a758e78a20bc..d5c4b4d415f1 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-annotations/javaagent/src/test/groovy/JaxrsAnnotationsInstrumentationTest.groovy @@ -23,7 +23,7 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat @Unroll def "span named '#paramName' from annotations on class '#className' when is not root span"() { setup: - runWithHttpServerSpan("test") { + runWithHttpServerSpan { obj.call() } @@ -31,10 +31,11 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat assertTraces(1) { trace(0, 2) { span(0) { - name paramName + name "GET " + paramName kind SERVER hasNoParent() attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" "$SemanticAttributes.HTTP_ROUTE" paramName } } @@ -50,7 +51,7 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat } when: "multiple calls to the same method" - runWithHttpServerSpan("test") { + runWithHttpServerSpan { (1..10).each { obj.call() } @@ -112,7 +113,7 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat def "no annotations has no effect"() { setup: - runWithHttpServerSpan("test") { + runWithHttpServerSpan { obj.call() } @@ -120,9 +121,10 @@ class JaxrsAnnotationsInstrumentationTest extends AgentInstrumentationSpecificat assertTraces(1) { trace(0, 1) { span(0) { - name "test" + name "GET" kind SERVER attributes { + "$SemanticAttributes.HTTP_METHOD" "GET" } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/java/AbstractArquillianRestTest.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/java/AbstractArquillianRestTest.java index df8b547f72c8..88ef6638dde6 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/java/AbstractArquillianRestTest.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/java/AbstractArquillianRestTest.java @@ -73,7 +73,9 @@ private void testHelloRequest(String path, String className) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(getContextRoot() + path).hasKind(SpanKind.SERVER).hasNoParent(), + span.hasName("GET " + getContextRoot() + path) + .hasKind(SpanKind.SERVER) + .hasNoParent(), span -> span.hasName(className + ".hello").hasParent(trace.getSpan(0)))); } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyFilterTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyFilterTest.groovy index e10b459cc0b1..a9486b38bc9e 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyFilterTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/javaagent/src/test/groovy/JerseyFilterTest.groovy @@ -52,7 +52,7 @@ class JerseyFilterTest extends JaxRsFilterTest implements HttpServerTestTrait extends HttpServerTest implemen span(0) { hasNoParent() kind SERVER - name getContextPath() + "/test-resource-super" + name "GET " + getContextPath() + "/test-resource-super" } span(1) { name "controller" @@ -66,7 +66,7 @@ abstract class AbstractJaxRsHttpServerTest extends HttpServerTest implemen span(0) { hasNoParent() kind SERVER - name getContextPath() + "/test-resource-interface/call" + name "GET " + getContextPath() + "/test-resource-interface/call" } span(1) { name "controller" @@ -90,7 +90,7 @@ abstract class AbstractJaxRsHttpServerTest extends HttpServerTest implemen span(0) { hasNoParent() kind SERVER - name getContextPath() + "/test-sub-resource-locator/call/sub" + name "GET " + getContextPath() + "/test-sub-resource-locator/call/sub" } span(1) { name "JaxRsSubResourceLocatorTestResource.call" @@ -256,7 +256,7 @@ abstract class AbstractJaxRsHttpServerTest extends HttpServerTest implemen int statusCode, String query) { trace.span(index) { - name path + name method + " " + path kind SERVER if (statusCode >= 500) { status ERROR diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy index a09acff320d1..fc5b1f345811 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationBasicTests.groovy @@ -87,7 +87,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/$jspFileName" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -146,7 +146,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/getQuery.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -200,7 +200,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/post.jsp" hasNoParent() - name route + name "POST $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -251,7 +251,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/$jspFileName" hasNoParent() - name route + name "GET $route" kind SERVER status ERROR event(0) { @@ -332,7 +332,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/includes/includeHtml.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -381,7 +381,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/includes/includeMulti.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -460,7 +460,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/$jspFileName" hasNoParent() - name route + name "GET $route" kind SERVER status ERROR errorEvent(JasperException, String) @@ -512,7 +512,7 @@ class JspInstrumentationBasicTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/*" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" diff --git a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy index 2249b44bf3dc..c5ad55fa55fb 100644 --- a/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy +++ b/instrumentation/jsp-2.3/javaagent/src/test/groovy/JspInstrumentationForwardTests.groovy @@ -85,7 +85,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/$forwardFromFileName" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -155,7 +155,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/forwards/forwardToHtml.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -204,7 +204,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/forwards/forwardToIncludeMulti.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -301,7 +301,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/forwards/forwardToJspForward.jsp" hasNoParent() - name route + name "GET $route" kind SERVER attributes { "$SemanticAttributes.HTTP_SCHEME" "http" @@ -382,7 +382,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/forwards/forwardToCompileError.jsp" hasNoParent() - name route + name "GET $route" kind SERVER status ERROR errorEvent(JasperException, String) @@ -445,7 +445,7 @@ class JspInstrumentationForwardTests extends AgentInstrumentationSpecification { def route = "/$jspWebappContext/forwards/forwardToNonExistent.jsp" hasNoParent() - name route + name "GET $route" kind SERVER status UNSET attributes { diff --git a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt index 9be3f4126d70..787caf049cc9 100644 --- a/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-1.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/KtorServerTracing.kt @@ -109,7 +109,7 @@ class KtorServerTracing private constructor( setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))) addAttributesExtractor(configuration.httpAttributesExtractorBuilder.build()) addOperationMetrics(HttpServerMetrics.get()) - addContextCustomizer(HttpRouteHolder.get()) + addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) } val instrumenter = instrumenterBuilder.buildServerInstrumenter(ApplicationRequestGetter) diff --git a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTracing.kt b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTracing.kt index b934445ec85d..2ef6b8cd2023 100644 --- a/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTracing.kt +++ b/instrumentation/ktor/ktor-2.0/library/src/main/kotlin/io/opentelemetry/instrumentation/ktor/v2_0/KtorServerTracing.kt @@ -109,7 +109,7 @@ class KtorServerTracing private constructor( setSpanStatusExtractor(configuration.statusExtractor(HttpSpanStatusExtractor.create(httpAttributesGetter))) addAttributesExtractor(configuration.httpAttributesExtractorBuilder.build()) addOperationMetrics(HttpServerMetrics.get()) - addContextCustomizer(HttpRouteHolder.get()) + addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) } val instrumenter = instrumenterBuilder.buildServerInstrumenter(ApplicationRequestGetter) diff --git a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java index 940975f35409..d96eefc1bf83 100644 --- a/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java +++ b/instrumentation/liberty/liberty-dispatcher-20.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/liberty/dispatcher/LibertyDispatcherSingletons.java @@ -36,7 +36,7 @@ public final class LibertyDispatcherSingletons { .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .build()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addOperationMetrics(HttpServerMetrics.get()) .buildServerInstrumenter(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 73bcc241d8ca..cc99eb009d7c 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 @@ -40,7 +40,7 @@ httpServerAttributesGetter, new NettyNetServerAttributesGetter()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer( (context, requestAndChannel, startAttributes) -> NettyErrorHolder.init(context)) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpServerAttributesGetter)) .buildServerInstrumenter(NettyHeadersGetter.INSTANCE); } diff --git a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java index 3655196e3041..2dc9c3446837 100644 --- a/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java +++ b/instrumentation/netty/netty-4-common/library/src/main/java/io/opentelemetry/instrumentation/netty/v4/common/internal/server/NettyServerInstrumenterFactory.java @@ -42,7 +42,7 @@ httpAttributesGetter, new NettyNetServerAttributesGetter()) .build()) .addOperationMetrics(HttpServerMetrics.get()) .addContextCustomizer((context, request, attributes) -> NettyErrorHolder.init(context)) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(HttpRequestHeadersGetter.INSTANCE); } diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy index 48a5a7d51c38..15e3886f6caf 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ClientSslTest.groovy @@ -163,7 +163,7 @@ class Netty40ClientSslTest extends AgentInstrumentationSpecification { } } span(3) { - name "HTTP GET" + name "GET" kind CLIENT childOf(span(0)) } diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy index 2aa830e80324..8f4c8c242c38 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ConnectionSpanTest.groovy @@ -112,7 +112,7 @@ class Netty40ConnectionSpanTest extends InstrumentationSpecification implements } } span(2) { - name "HTTP GET" + name "GET" kind CLIENT childOf(span(0)) } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy index 6a95e8547531..b536281ba0da 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ClientSslTest.groovy @@ -190,7 +190,7 @@ class Netty41ClientSslTest extends AgentInstrumentationSpecification { } } span(4) { - name "HTTP GET" + name "GET" kind CLIENT childOf(span(0)) } diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy index 71e161ce4295..056474b02b6c 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ConnectionSpanTest.groovy @@ -125,7 +125,7 @@ class Netty41ConnectionSpanTest extends InstrumentationSpecification implements } } span(3) { - name "HTTP GET" + name "GET" kind CLIENT childOf(span(0)) } diff --git a/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java b/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java index bfaa43f5626b..41a86f347e47 100644 --- a/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java +++ b/instrumentation/okhttp/okhttp-3.0/testing/src/main/java/io/opentelemetry/instrumentation/okhttp/v3_0/AbstractOkHttp3Test.java @@ -180,7 +180,7 @@ public void onResponse(Call call, Response response) { trace -> { trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(), - span -> span.hasName("HTTP GET").hasKind(SpanKind.CLIENT).hasParent(trace.getSpan(0)), + span -> span.hasName("GET").hasKind(SpanKind.CLIENT).hasParent(trace.getSpan(0)), span -> span.hasName("test-http-server") .hasKind(SpanKind.SERVER) diff --git a/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java b/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java index 70e183364b6b..e4a30c77df9a 100644 --- a/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java +++ b/instrumentation/opensearch/opensearch-rest-1.0/javaagent/src/test/java/OpenSearchRestTest.java @@ -96,7 +96,7 @@ void shouldGetStatusWithTraces() throws IOException { SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -171,7 +171,7 @@ public void onFailure(Exception e) { SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP)), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(1)) .hasAttributesSatisfyingExactly( diff --git a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/InstrumentationApiContextBridging.java b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/InstrumentationApiContextBridging.java index e70b685cebb0..2c1e36124395 100644 --- a/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/InstrumentationApiContextBridging.java +++ b/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/InstrumentationApiContextBridging.java @@ -56,25 +56,29 @@ final class InstrumentationApiContextBridging { private static final Class AGENT_HTTP_ROUTE_STATE; private static final MethodHandle AGENT_CREATE; - private static final MethodHandle AGENT_GET_UPDATED_BY_SOURCE_ORDER; + private static final MethodHandle AGENT_GET_METHOD; private static final MethodHandle AGENT_GET_ROUTE; + private static final MethodHandle AGENT_GET_UPDATED_BY_SOURCE_ORDER; private static final Class APPLICATION_HTTP_ROUTE_STATE; private static final MethodHandle APPLICATION_CREATE; - private static final MethodHandle APPLICATION_GET_UPDATED_BY_SOURCE_ORDER; + private static final MethodHandle APPLICATION_GET_METHOD; private static final MethodHandle APPLICATION_GET_ROUTE; + private static final MethodHandle APPLICATION_GET_UPDATED_BY_SOURCE_ORDER; static { MethodHandles.Lookup lookup = MethodHandles.lookup(); Class agentHttpRouteState = null; MethodHandle agentCreate = null; - MethodHandle agentGetUpdatedBySourceOrder = null; + MethodHandle agentGetMethod = null; MethodHandle agentGetRoute = null; + MethodHandle agentGetUpdatedBySourceOrder = null; Class applicationHttpRouteState = null; MethodHandle applicationCreate = null; - MethodHandle applicationGetUpdatedBySourceOrder = null; + MethodHandle applicationGetMethod = null; MethodHandle applicationGetRoute = null; + MethodHandle applicationGetUpdatedBySourceOrder = null; try { agentHttpRouteState = @@ -83,12 +87,14 @@ final class InstrumentationApiContextBridging { lookup.findStatic( agentHttpRouteState, "create", - MethodType.methodType(agentHttpRouteState, int.class, String.class)); + MethodType.methodType(agentHttpRouteState, String.class, String.class, int.class)); + agentGetMethod = + lookup.findVirtual(agentHttpRouteState, "getMethod", MethodType.methodType(String.class)); + agentGetRoute = + lookup.findVirtual(agentHttpRouteState, "getRoute", MethodType.methodType(String.class)); agentGetUpdatedBySourceOrder = lookup.findVirtual( agentHttpRouteState, "getUpdatedBySourceOrder", MethodType.methodType(int.class)); - agentGetRoute = - lookup.findVirtual(agentHttpRouteState, "getRoute", MethodType.methodType(String.class)); applicationHttpRouteState = Class.forName("application.io.opentelemetry.instrumentation.api.internal.HttpRouteState"); @@ -96,35 +102,42 @@ final class InstrumentationApiContextBridging { lookup.findStatic( applicationHttpRouteState, "create", - MethodType.methodType(applicationHttpRouteState, int.class, String.class)); + MethodType.methodType( + applicationHttpRouteState, String.class, String.class, int.class)); + applicationGetMethod = + lookup.findVirtual( + applicationHttpRouteState, "getMethod", MethodType.methodType(String.class)); + applicationGetRoute = + lookup.findVirtual( + applicationHttpRouteState, "getRoute", MethodType.methodType(String.class)); applicationGetUpdatedBySourceOrder = lookup.findVirtual( applicationHttpRouteState, "getUpdatedBySourceOrder", MethodType.methodType(int.class)); - applicationGetRoute = - lookup.findVirtual( - applicationHttpRouteState, "getRoute", MethodType.methodType(String.class)); } catch (Throwable ignored) { // instrumentation-api may be absent on the classpath, or it might be an older version } AGENT_HTTP_ROUTE_STATE = agentHttpRouteState; AGENT_CREATE = agentCreate; - AGENT_GET_UPDATED_BY_SOURCE_ORDER = agentGetUpdatedBySourceOrder; + AGENT_GET_METHOD = agentGetMethod; AGENT_GET_ROUTE = agentGetRoute; + AGENT_GET_UPDATED_BY_SOURCE_ORDER = agentGetUpdatedBySourceOrder; APPLICATION_HTTP_ROUTE_STATE = applicationHttpRouteState; APPLICATION_CREATE = applicationCreate; - APPLICATION_GET_UPDATED_BY_SOURCE_ORDER = applicationGetUpdatedBySourceOrder; + APPLICATION_GET_METHOD = applicationGetMethod; APPLICATION_GET_ROUTE = applicationGetRoute; + APPLICATION_GET_UPDATED_BY_SOURCE_ORDER = applicationGetUpdatedBySourceOrder; } @Nullable private static ContextKeyBridge httpRouteStateBridge() { if (APPLICATION_HTTP_ROUTE_STATE == null || APPLICATION_CREATE == null - || APPLICATION_GET_UPDATED_BY_SOURCE_ORDER == null - || APPLICATION_GET_ROUTE == null) { + || APPLICATION_GET_METHOD == null + || APPLICATION_GET_ROUTE == null + || APPLICATION_GET_UPDATED_BY_SOURCE_ORDER == null) { // HttpRouteHolder not on application classpath; or an old version of it return null; } @@ -135,21 +148,31 @@ final class InstrumentationApiContextBridging { "KEY", "KEY", httpRouteStateConvert( - APPLICATION_CREATE, AGENT_GET_UPDATED_BY_SOURCE_ORDER, AGENT_GET_ROUTE), + APPLICATION_CREATE, + AGENT_GET_METHOD, + AGENT_GET_ROUTE, + AGENT_GET_UPDATED_BY_SOURCE_ORDER), httpRouteStateConvert( - AGENT_CREATE, APPLICATION_GET_UPDATED_BY_SOURCE_ORDER, APPLICATION_GET_ROUTE)); + AGENT_CREATE, + APPLICATION_GET_METHOD, + APPLICATION_GET_ROUTE, + APPLICATION_GET_UPDATED_BY_SOURCE_ORDER)); } catch (Throwable ignored) { return null; } } private static Function httpRouteStateConvert( - MethodHandle create, MethodHandle getUpdatedBySourceOrder, MethodHandle getRoute) { + MethodHandle create, + MethodHandle getMethod, + MethodHandle getRoute, + MethodHandle getUpdatedBySourceOrder) { return httpRouteHolder -> { try { - int updatedBySourceOrder = (int) getUpdatedBySourceOrder.invoke(httpRouteHolder); + String method = (String) getMethod.invoke(httpRouteHolder); String route = (String) getRoute.invoke(httpRouteHolder); - return create.invoke(updatedBySourceOrder, route); + int updatedBySourceOrder = (int) getUpdatedBySourceOrder.invoke(httpRouteHolder); + return create.invoke(method, route, updatedBySourceOrder); } catch (Throwable e) { return null; } diff --git a/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java b/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java index ae9526014efb..b3de3e53a8ad 100644 --- a/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java +++ b/instrumentation/opentelemetry-instrumentation-api/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/instrumentationapi/ContextBridgeTest.java @@ -87,10 +87,11 @@ void testHttpRouteHolder_SameSourceAsServerInstrumentationDoesNotOverrideRoute() trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/test/server/*") + span.hasName("GET /test/server/*") .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.HTTP_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_ROUTE, "/test/server/*")))); } @@ -106,10 +107,11 @@ void testHttpRouteHolder_SourceWithHigherOrderValueOverridesRoute() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/test/controller/:id") + span.hasName("GET /test/controller/:id") .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.HTTP_METHOD, "GET"), equalTo(SemanticAttributes.HTTP_ROUTE, "/test/controller/:id")))); } } diff --git a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java index 009578fa42db..39a95e5afed7 100644 --- a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java +++ b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/AgentSpanTestingInstrumenter.java @@ -32,7 +32,7 @@ public final class AgentSpanTestingInstrumenter { .addAttributesExtractor( HttpServerAttributesExtractor.create( MockHttpServerAttributesGetter.INSTANCE, MockNetServerAttributesGetter.INSTANCE)) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(MockHttpServerAttributesGetter.INSTANCE)) .addContextCustomizer( (context, request, startAttributes) -> context.with(REQUEST_CONTEXT_KEY, request)) .buildInstrumenter(SpanKindExtractor.alwaysServer()); diff --git a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java index fc789bfd7fc2..537c88c8ec7b 100644 --- a/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java +++ b/instrumentation/opentelemetry-instrumentation-api/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/testing/MockHttpServerAttributesGetter.java @@ -16,10 +16,9 @@ enum MockHttpServerAttributesGetter implements HttpServerAttributesGetter { INSTANCE; - @Nullable @Override public String getMethod(String s) { - return null; + return "GET"; } @Override diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy index 4a4ee2f4c8db..cd4e3dc1fd38 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy @@ -169,7 +169,7 @@ abstract class AbstractRatpackForkedHttpServerTest extends AbstractRatpackHttpSe assertTraces(1) { trace(0, 2 + (hasHandlerSpan(SUCCESS) ? 1 : 0)) { span(0) { - name "/fork_and_yieldAll" + name "GET /fork_and_yieldAll" kind SpanKind.SERVER hasNoParent() } diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy index 32dd53cfeaaa..5c39a02fae08 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackRoutesTest.groovy @@ -91,7 +91,7 @@ abstract class AbstractRatpackRoutesTest extends InstrumentationSpecification { assertTraces(1) { trace(0, 1 + (hasHandlerSpan() ? 1 : 0)) { span(0) { - name "/$route" + name "GET /$route" kind SERVER hasNoParent() attributes { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/OpenTelemetryServerHandler.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/OpenTelemetryServerHandler.java index 8930ad5b2a77..30e4ff9164b4 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/OpenTelemetryServerHandler.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/OpenTelemetryServerHandler.java @@ -5,10 +5,11 @@ package io.opentelemetry.instrumentation.ratpack; -import io.opentelemetry.api.trace.Span; +import static io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteSource.CONTROLLER; + import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import ratpack.error.ServerErrorHandler; import ratpack.handling.Context; import ratpack.handling.Handler; @@ -38,10 +39,8 @@ public void handle(Context context) { context.onClose( outcome -> { // Route not available in beginning of request so handle it manually here. - String route = '/' + context.getPathBinding().getDescription(); - Span span = Span.fromContext(otelCtx); - span.updateName(route); - span.setAttribute(SemanticAttributes.HTTP_ROUTE, route); + HttpRouteHolder.updateHttpRoute( + otelCtx, CONTROLLER, OpenTelemetryServerHandler::getRoute, context); Throwable error = context.getExecution().maybeGet(ErrorHolder.class).map(ErrorHolder::get).orElse(null); @@ -62,6 +61,10 @@ public void handle(Context context) { context.next(); } + private static String getRoute(io.opentelemetry.context.Context otelCtx, Context context) { + return '/' + context.getPathBinding().getDescription(); + } + static final class ErrorHolder { private final Throwable throwable; diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java index bd02f107cc7f..1b1a29244f99 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java +++ b/instrumentation/ratpack/ratpack-1.7/library/src/main/java/io/opentelemetry/instrumentation/ratpack/RatpackTelemetryBuilder.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientAttributesExtractorBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; @@ -123,6 +124,7 @@ public RatpackTelemetry build() { .addAttributesExtractor(httpServerAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpServerMetrics.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributes)) .buildServerInstrumenter(RatpackGetter.INSTANCE); return new RatpackTelemetry(instrumenter, httpClientInstrumenter()); diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/client/InstrumentedHttpClientTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/client/InstrumentedHttpClientTest.groovy index d07fc7959911..366454eebb3f 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/client/InstrumentedHttpClientTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/client/InstrumentedHttpClientTest.groovy @@ -90,9 +90,9 @@ class InstrumentedHttpClientTest extends Specification { } new PollingConditions().eventually { - def spanData = spanExporter.finishedSpanItems.find { it.name == "/foo" } - def spanClientData = spanExporter.finishedSpanItems.find { it.name == "HTTP GET" && it.kind == CLIENT } - def spanDataApi = spanExporter.finishedSpanItems.find { it.name == "/bar" && it.kind == SERVER } + def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" } + def spanClientData = spanExporter.finishedSpanItems.find { it.name == "GET" && it.kind == CLIENT } + def spanDataApi = spanExporter.finishedSpanItems.find { it.name == "GET /bar" && it.kind == SERVER } spanData.traceId == spanClientData.traceId spanData.traceId == spanDataApi.traceId @@ -154,9 +154,9 @@ class InstrumentedHttpClientTest extends Specification { new PollingConditions().eventually { spanExporter.finishedSpanItems.size() == 3 - def spanData = spanExporter.finishedSpanItems.find { spanData -> spanData.name == "/path-name" } - def spanClientData1 = spanExporter.finishedSpanItems.find { s -> s.name == "HTTP GET" && s.attributes.asMap()[HTTP_ROUTE] == "/foo" } - def spanClientData2 = spanExporter.finishedSpanItems.find { s -> s.name == "HTTP GET" && s.attributes.asMap()[HTTP_ROUTE] == "/bar" } + def spanData = spanExporter.finishedSpanItems.find { spanData -> spanData.name == "GET /path-name" } + def spanClientData1 = spanExporter.finishedSpanItems.find { s -> s.name == "GET" && s.attributes.asMap()[HTTP_ROUTE] == "/foo" } + def spanClientData2 = spanExporter.finishedSpanItems.find { s -> s.name == "GET" && s.attributes.asMap()[HTTP_ROUTE] == "/bar" } spanData.traceId == spanClientData1.traceId spanData.traceId == spanClientData2.traceId @@ -217,8 +217,8 @@ class InstrumentedHttpClientTest extends Specification { app.test { httpClient -> "error" == httpClient.get("path-name").body.text } new PollingConditions().eventually { - def spanData = spanExporter.finishedSpanItems.find { it.name == "/path-name" } - def spanClientData = spanExporter.finishedSpanItems.find { it.name == "HTTP GET" } + def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /path-name" } + def spanClientData = spanExporter.finishedSpanItems.find { it.name == "GET" } spanData.traceId == spanClientData.traceId diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerApplicationTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerApplicationTest.groovy index f231af36421e..30c4912eabd1 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerApplicationTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerApplicationTest.groovy @@ -42,7 +42,7 @@ class RatpackServerApplicationTest extends Specification { app.test { httpClient -> "hi-foo" == httpClient.get("foo").body.text } new PollingConditions().eventually { - def spanData = app.spanExporter.finishedSpanItems.find { it.name == "/foo" } + def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /foo" } def attributes = spanData.attributes.asMap() spanData.kind == SpanKind.SERVER @@ -58,8 +58,8 @@ class RatpackServerApplicationTest extends Specification { app.test { httpClient -> "hi-bar" == httpClient.get("bar").body.text } new PollingConditions().eventually { - def spanData = app.spanExporter.finishedSpanItems.find { it.name == "/bar" } - def spanDataClient = app.spanExporter.finishedSpanItems.find { it.name == "HTTP GET" } + def spanData = app.spanExporter.finishedSpanItems.find { it.name == "GET /bar" } + def spanDataClient = app.spanExporter.finishedSpanItems.find { it.name == "GET" } def attributes = spanData.attributes.asMap() spanData.traceId == spanDataClient.traceId @@ -83,7 +83,7 @@ class RatpackServerApplicationTest extends Specification { app.test { httpClient -> "ignored" == httpClient.get("ignore").body.text } new PollingConditions(initialDelay: 0.1, timeout: 0.3).eventually { - !app.spanExporter.finishedSpanItems.any { it.name == "/ignore" } + !app.spanExporter.finishedSpanItems.any { it.name == "GET /ignore" } } } } diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerTest.groovy index 25325edaf9fa..804841ed27d7 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackServerTest.groovy @@ -51,7 +51,7 @@ class RatpackServerTest extends Specification { then: new PollingConditions().eventually { - def spanData = spanExporter.finishedSpanItems.find { it.name == "/foo" } + def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" } def attributes = spanData.attributes.asMap() spanData.kind == SpanKind.SERVER @@ -84,7 +84,7 @@ class RatpackServerTest extends Specification { "hi-foo" == httpClient.get("foo").body.text new PollingConditions().eventually { - def spanData = spanExporter.finishedSpanItems.find { it.name == "/foo" } + def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" } def spanDataChild = spanExporter.finishedSpanItems.find { it.name == "a-span" } spanData.kind == SpanKind.SERVER @@ -133,10 +133,10 @@ class RatpackServerTest extends Specification { "hi-foo" == httpClient.get("foo").body.text "hi-bar" == httpClient.get("bar").body.text new PollingConditions().eventually { - def spanData = spanExporter.finishedSpanItems.find { it.name == "/foo" } + def spanData = spanExporter.finishedSpanItems.find { it.name == "GET /foo" } def spanDataChild = spanExporter.finishedSpanItems.find { it.name == "a-span" } - def spanData2 = spanExporter.finishedSpanItems.find { it.name == "/bar" } + def spanData2 = spanExporter.finishedSpanItems.find { it.name == "GET /bar" } def spanDataChild2 = spanExporter.finishedSpanItems.find { it.name == "another-span" } spanData.kind == SpanKind.SERVER diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java index 36b281894c19..b6e1af63a300 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/AbstractReactorNettyHttpClientTest.java @@ -177,7 +177,7 @@ void shouldExposeContextToHttpClientCallbacks() throws InterruptedException { trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(), - span -> span.hasName("HTTP GET").hasKind(CLIENT).hasParent(parentSpan), + span -> span.hasName("GET").hasKind(CLIENT).hasParent(parentSpan), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(nettyClientSpan)); assertSameSpan(parentSpan, onRequestSpan); diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java index 8149cbf10e77..5be7e5063c4b 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-0.9/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyConnectionSpanTest.java @@ -88,7 +88,7 @@ void testSuccessfulRequest() { equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), equalTo(SemanticAttributes.NET_PEER_PORT, server.httpPort()), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1")), - span -> span.hasName("HTTP GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), + span -> span.hasName("GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(3)))); } diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java index c53a55438550..f1e7430ecf2c 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/AbstractReactorNettyHttpClientTest.java @@ -182,7 +182,7 @@ void shouldExposeContextToHttpClientCallbacks() throws InterruptedException { trace.hasSpansSatisfyingExactly( span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(), - span -> span.hasName("HTTP GET").hasKind(CLIENT).hasParent(parentSpan), + span -> span.hasName("GET").hasKind(CLIENT).hasParent(parentSpan), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(nettyClientSpan)); assertSameSpan(nettyClientSpan, onRequestSpan); @@ -299,7 +299,7 @@ void shouldEndSpanOnMonoTimeout() { .hasStatus(StatusData.error()) .hasException(thrown), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java index 392e0c84f55f..ccfa43b3aeb1 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyBaseUrlOnlyTest.java @@ -103,7 +103,7 @@ void testSuccessfulRequest() { trace.hasSpansSatisfyingExactlyInAnyOrder( span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java index 288f842a033d..98f0a0ff1008 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyClientSslTest.java @@ -82,7 +82,7 @@ void shouldFailSslHandshake() throws SSLException { .hasStatus(StatusData.error()) .hasException(thrown), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasStatus(StatusData.error()) @@ -148,7 +148,7 @@ void shouldSuccessfullyEstablishSslHandshake() throws SSLException { trace.hasSpansSatisfyingExactlyInAnyOrder( span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java index 5d9245e5fb75..1bf36a77c14a 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyConnectionSpanTest.java @@ -74,7 +74,7 @@ void testSuccessfulRequest() { trace.hasSpansSatisfyingExactlyInAnyOrder( span -> span.hasName("parent").hasKind(INTERNAL).hasNoParent(), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( @@ -145,7 +145,7 @@ void testFailingRequest() { .hasStatus(StatusData.error()) .hasException(thrown), span -> - span.hasName("HTTP GET") + span.hasName("GET") .hasKind(CLIENT) .hasParent(trace.getSpan(0)) .hasStatus(StatusData.error()) diff --git a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyWithSpanTest.java b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyWithSpanTest.java index 3f1d60570192..69d6104ad554 100644 --- a/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyWithSpanTest.java +++ b/instrumentation/reactor/reactor-netty/reactor-netty-1.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyWithSpanTest.java @@ -72,7 +72,7 @@ public void testSuccessfulNestedUnderWithSpan() { trace -> trace.hasSpansSatisfyingExactly( span -> span.hasName("TracedWithSpan.mono").hasKind(INTERNAL).hasNoParent(), - span -> span.hasName("HTTP GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), + span -> span.hasName("GET").hasKind(CLIENT).hasParent(trace.getSpan(0)), span -> span.hasName("test-http-server").hasKind(SERVER).hasParent(trace.getSpan(1)))); } diff --git a/instrumentation/restlet/restlet-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletServerTest.groovy b/instrumentation/restlet/restlet-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletServerTest.groovy index 40eb940ce048..503741641cc2 100644 --- a/instrumentation/restlet/restlet-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletServerTest.groovy +++ b/instrumentation/restlet/restlet-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v1_1/RestletServerTest.groovy @@ -7,7 +7,20 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v1_1 import io.opentelemetry.instrumentation.restlet.v1_1.AbstractRestletServerTest import io.opentelemetry.instrumentation.test.AgentTestTrait +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND class RestletServerTest extends AbstractRestletServerTest implements AgentTestTrait { + @Override + String expectedHttpRoute(ServerEndpoint endpoint) { + switch (endpoint) { + case NOT_FOUND: + return getContextPath() + "/" + default: + return super.expectedHttpRoute(endpoint) + } + } + } diff --git a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java index 3305851a7a56..45f34ac8de23 100644 --- a/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java +++ b/instrumentation/restlet/restlet-1.1/library/src/main/java/io/opentelemetry/instrumentation/restlet/v1_1/RestletTelemetryBuilder.java @@ -9,6 +9,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractorBuilder; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; @@ -85,6 +86,7 @@ public RestletTelemetry build() { .addAttributesExtractor(httpAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpServerMetrics.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(RestletHeadersGetter.INSTANCE); return new RestletTelemetry(instrumenter); diff --git a/instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletServerTest.groovy b/instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletServerTest.groovy index cc6b39f94168..fa48bd476f91 100644 --- a/instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletServerTest.groovy +++ b/instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/RestletServerTest.groovy @@ -7,7 +7,20 @@ package io.opentelemetry.javaagent.instrumentation.restlet.v2_0 import io.opentelemetry.instrumentation.restlet.v2_0.AbstractRestletServerTest import io.opentelemetry.instrumentation.test.AgentTestTrait +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND class RestletServerTest extends AbstractRestletServerTest implements AgentTestTrait { + @Override + String expectedHttpRoute(ServerEndpoint endpoint) { + switch (endpoint) { + case NOT_FOUND: + return getContextPath() + "/" + default: + return super.expectedHttpRoute(endpoint) + } + } + } diff --git a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java index f5f6c0f9e2a3..9a67815f71e1 100644 --- a/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java +++ b/instrumentation/restlet/restlet-2.0/library/src/main/java/io/opentelemetry/instrumentation/restlet/v2_0/internal/RestletInstrumenterFactory.java @@ -8,6 +8,7 @@ import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; 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; @@ -36,6 +37,7 @@ public static Instrumenter newServerInstrumenter( .addAttributesExtractor(httpServerAttributesExtractor) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpServerMetrics.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(new RestletHeadersGetter()); } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2SpanNameExtractor.java b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2SpanNameExtractor.java index 34de6c308512..751a4629ee58 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2SpanNameExtractor.java +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2SpanNameExtractor.java @@ -20,19 +20,17 @@ public Servlet2SpanNameExtractor(ServletAccessor accessor) { @Override public String extract(ServletRequestContext requestContext) { REQUEST request = requestContext.request(); + String method = accessor.getRequestMethod(request); String servletPath = accessor.getRequestServletPath(request); - if (!servletPath.isEmpty()) { + if (method != null) { + if (servletPath.isEmpty()) { + return method; + } String contextPath = accessor.getRequestContextPath(request); if (contextPath == null || contextPath.isEmpty() || contextPath.equals("/")) { - return servletPath; + return method + " " + servletPath; } - - return contextPath + servletPath; - } - - String method = accessor.getRequestMethod(request); - if (method != null) { - return "HTTP " + method; + return method + " " + contextPath + servletPath; } return "HTTP request"; } diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy index e3f592ca4175..53ffbe24d9ca 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy @@ -15,6 +15,7 @@ import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.servlet.ServletContextHandler +import javax.annotation.Nullable import javax.servlet.http.HttpServletRequest import static io.opentelemetry.api.trace.SpanKind.INTERNAL @@ -83,14 +84,14 @@ class JettyServlet2Test extends HttpServerTest implements AgentTestTrait } @Override - String expectedServerSpanName(ServerEndpoint endpoint, String method) { + String expectedServerSpanName(ServerEndpoint endpoint, String method, @Nullable String route) { switch (endpoint) { case NOT_FOUND: - return "HTTP $method" + return method case PATH_PARAM: - return getContextPath() + "/path/:id/param" + return method + " " + getContextPath() + "/path/:id/param" default: - return endpoint.resolvePath(address).path + return method + " " + endpoint.resolvePath(address).path } } diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3MappingTest.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3MappingTest.groovy index 033bbf5b497e..0349aefbf742 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3MappingTest.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3MappingTest.groovy @@ -54,7 +54,7 @@ abstract class AbstractServlet3MappingTest extends AgentInstrum assertTraces(1) { trace(0, spanCount) { span(0) { - name getContextPath() + spanName + name "GET " + getContextPath() + route kind SpanKind.SERVER if (!success && response.status().code() >= 500) { status ERROR @@ -68,7 +68,7 @@ abstract class AbstractServlet3MappingTest extends AgentInstrum } where: - path | spanName | success + path | route | success 'prefix' | '/prefix/*' | true 'prefix/' | '/prefix/*' | true 'prefix/a' | '/prefix/*' | true diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5MappingTest.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5MappingTest.groovy index 4273d130319c..2e0d1d7d9eec 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5MappingTest.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5MappingTest.groovy @@ -53,7 +53,7 @@ abstract class AbstractServlet5MappingTest extends AgentInstrum assertTraces(1) { trace(0, spanCount) { span(0) { - name getContextPath() + spanName + name "GET " + getContextPath() + route kind SpanKind.SERVER if (!success && response.status().code() >= 500) { status ERROR @@ -67,7 +67,7 @@ abstract class AbstractServlet5MappingTest extends AgentInstrum } where: - path | spanName | success + path | route | success 'prefix' | '/prefix/*' | true 'prefix/' | '/prefix/*' | true 'prefix/a' | '/prefix/*' | true 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 0da91e124e28..434ad3a6262e 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 @@ -66,7 +66,7 @@ public Instrumenter, ServletResponseContext, ServletResponseContext> requestParametersExtractor = new ServletRequestParametersExtractor<>(accessor); diff --git a/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy b/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy index 837eb59ec8e6..ff597ffb12ac 100644 --- a/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy +++ b/instrumentation/spark-2.3/javaagent/src/test/groovy/SparkJavaBasedTest.groovy @@ -43,7 +43,7 @@ class SparkJavaBasedTest extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 1) { span(0) { - name "/param/:param" + name "GET /param/:param" kind SERVER hasNoParent() attributes { diff --git a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy index a2f78483eeef..c3873074ec63 100644 --- a/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy +++ b/instrumentation/spring/spring-integration-4.1/javaagent/src/test/groovy/SpringIntegrationAndRabbitTest.groovy @@ -9,7 +9,6 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.CONSUMER import static io.opentelemetry.api.trace.SpanKind.PRODUCER -import static io.opentelemetry.api.trace.SpanKind.SERVER class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification implements WithRabbitProducerConsumerTrait { def setupSpec() { @@ -22,8 +21,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i def "should cooperate with existing RabbitMQ instrumentation"() { when: - // simulate the workflow being triggered by HTTP request - runWithHttpServerSpan("HTTP GET") { + runWithSpan("parent") { producerContext.getBean("producer", Runnable).run() } @@ -31,8 +29,7 @@ class SpringIntegrationAndRabbitTest extends AgentInstrumentationSpecification i assertTraces(2) { trace(0, 7) { span(0) { - name "HTTP GET" - kind SERVER + name "parent" attributes {} } span(1) { diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java index aea55fbf4177..10a6b2f9671b 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/spring/webflux/v5_0/server/SpringWebfluxTest.java @@ -109,7 +109,7 @@ void basicGetTest(Parameter parameter) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(parameter.urlPathWithVariables) + span.hasName("GET " + parameter.urlPathWithVariables) .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -233,7 +233,7 @@ void getAsyncResponseTest(Parameter parameter) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(parameter.urlPathWithVariables) + span.hasName("GET " + parameter.urlPathWithVariables) .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -352,7 +352,7 @@ void createSpanDuringHandlerFunctionTest(Parameter parameter) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(parameter.urlPathWithVariables) + span.hasName("GET " + parameter.urlPathWithVariables) .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -435,7 +435,7 @@ void get404Test() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/**") + span.hasName("GET /**") .hasKind(SpanKind.SERVER) .hasNoParent() .hasStatus(StatusData.unset()) @@ -503,7 +503,7 @@ void basicPostTest() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/echo") + span.hasName("POST /echo") .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -554,7 +554,7 @@ void getToBadEndpointTest(Parameter parameter) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(parameter.urlPathWithVariables) + span.hasName("GET " + parameter.urlPathWithVariables) .hasKind(SpanKind.SERVER) .hasNoParent() .hasStatus(StatusData.error()) @@ -646,7 +646,7 @@ void redirectTest() { // TODO: why order of spans is different in these traces? trace.hasSpansSatisfyingExactly( span -> - span.hasName("/double-greet-redirect") + span.hasName("GET /double-greet-redirect") .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -686,7 +686,7 @@ void redirectTest() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/double-greet") + span.hasName("GET /double-greet") .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( @@ -749,7 +749,7 @@ void multipleGetsToDelayingRoute(Parameter parameter) { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName(parameter.urlPathWithVariables) + span.hasName("GET " + parameter.urlPathWithVariables) .hasKind(SpanKind.SERVER) .hasNoParent() .hasAttributesSatisfyingExactly( diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/wildfly-testing/src/test/java/AbstractOpenTelemetryHandlerMappingFilterTest.java b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/wildfly-testing/src/test/java/AbstractOpenTelemetryHandlerMappingFilterTest.java index 28780827e068..aee913f15288 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/wildfly-testing/src/test/java/AbstractOpenTelemetryHandlerMappingFilterTest.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-3.1/wildfly-testing/src/test/java/AbstractOpenTelemetryHandlerMappingFilterTest.java @@ -47,7 +47,7 @@ public void testSuccess() { testing.waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( - span -> span.hasName("/hello/{name}").hasKind(SpanKind.SERVER).hasNoParent(), + span -> span.hasName("GET /hello/{name}").hasKind(SpanKind.SERVER).hasNoParent(), span -> span.hasName("HelloController.hello") .hasKind(SpanKind.INTERNAL) @@ -63,7 +63,7 @@ public void testException() { trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("/hello/{name}") + span.hasName("GET /hello/{name}") .hasKind(SpanKind.SERVER) .hasStatus(StatusData.error()) .hasNoParent() diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java index ddd5cfe4fe02..89b24520eca7 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-5.3/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v5_3/SpringWebMvcTelemetryBuilder.java @@ -87,7 +87,7 @@ public SpringWebMvcTelemetry build() { .addAttributesExtractor(httpAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(JavaxHttpServletRequestGetter.INSTANCE); return new SpringWebMvcTelemetry(instrumenter); diff --git a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java index 2e9188aff1f9..2265c1b02cc2 100644 --- a/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java +++ b/instrumentation/spring/spring-webmvc/spring-webmvc-6.0/library/src/main/java/io/opentelemetry/instrumentation/spring/webmvc/v6_0/SpringWebMvcTelemetryBuilder.java @@ -87,7 +87,7 @@ public SpringWebMvcTelemetry build() { .addAttributesExtractor(httpAttributesExtractorBuilder.build()) .addAttributesExtractors(additionalExtractors) .addOperationMetrics(HttpServerMetrics.get()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .buildServerInstrumenter(JakartaHttpServletRequestGetter.INSTANCE); return new SpringWebMvcTelemetry(instrumenter); diff --git a/instrumentation/spring/spring-ws-2.0/javaagent/src/test/groovy/test/boot/SpringWsTest.groovy b/instrumentation/spring/spring-ws-2.0/javaagent/src/test/groovy/test/boot/SpringWsTest.groovy index 43e49ad20bdb..0e3942a0d2e6 100644 --- a/instrumentation/spring/spring-ws-2.0/javaagent/src/test/groovy/test/boot/SpringWsTest.groovy +++ b/instrumentation/spring/spring-ws-2.0/javaagent/src/test/groovy/test/boot/SpringWsTest.groovy @@ -127,10 +127,10 @@ class SpringWsTest extends AgentInstrumentationSpecification implements HttpServ methodName << ["hello", "helloSoapAction", "helloWsAction"] } - static serverSpan(TraceAssert trace, int index, String operation, Throwable exception = null) { + static serverSpan(TraceAssert trace, int index, String route, Throwable exception = null) { trace.span(index) { hasNoParent() - name operation + name "POST " + route kind SpanKind.SERVER if (exception != null) { status ERROR diff --git a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy index 2446b712afed..c170e84d5cb1 100644 --- a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy +++ b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy @@ -153,7 +153,7 @@ class Struts2ActionSpanTest extends HttpServerTest implements AgentTestT assertTraces(1) { trace(0, 2) { span(0) { - name getContextPath() + "/dispatch" + name "GET " + getContextPath() + "/dispatch" kind SpanKind.SERVER hasNoParent() } diff --git a/instrumentation/tapestry-5.4/javaagent/src/test/groovy/TapestryTest.groovy b/instrumentation/tapestry-5.4/javaagent/src/test/groovy/TapestryTest.groovy index c135ac80cd42..569097807495 100644 --- a/instrumentation/tapestry-5.4/javaagent/src/test/groovy/TapestryTest.groovy +++ b/instrumentation/tapestry-5.4/javaagent/src/test/groovy/TapestryTest.groovy @@ -100,7 +100,7 @@ class TapestryTest extends AgentInstrumentationSpecification implements HttpServ assertTraces(1) { trace(0, 2) { - serverSpan(it, 0, getContextPath() + "/Index") + serverSpan(it, 0, "GET " + getContextPath() + "/Index") span(1) { name "activate/Index" kind SpanKind.INTERNAL @@ -122,7 +122,7 @@ class TapestryTest extends AgentInstrumentationSpecification implements HttpServ assertTraces(2) { trace(0, 4) { - serverSpan(it, 0, getContextPath() + "/Index") + serverSpan(it, 0, "GET " + getContextPath() + "/Index") span(1) { name "activate/Index" kind SpanKind.INTERNAL @@ -140,7 +140,7 @@ class TapestryTest extends AgentInstrumentationSpecification implements HttpServ } } trace(1, 2) { - serverSpan(it, 0, getContextPath() + "/Other") + serverSpan(it, 0, "GET " + getContextPath() + "/Other") span(1) { name "activate/Other" kind SpanKind.INTERNAL @@ -164,7 +164,7 @@ class TapestryTest extends AgentInstrumentationSpecification implements HttpServ span(0) { hasNoParent() kind SpanKind.SERVER - name getContextPath() + "/Index" + name "GET " + getContextPath() + "/Index" status ERROR } span(1) { 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 a9959b5fef5c..30ca39d7e730 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 @@ -39,7 +39,7 @@ public static Instrumenter create( .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .build()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addContextCustomizer( (context, request, attributes) -> new AppServerBridge.Builder() diff --git a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy index 6980fdb9415e..f362f397f0a0 100644 --- a/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy +++ b/instrumentation/twilio-6.6/javaagent/src/test/groovy/test/TwilioClientTest.groovy @@ -244,7 +244,7 @@ class TwilioClientTest extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP POST" + name "POST" kind CLIENT childOf span(1) attributes { @@ -310,7 +310,7 @@ class TwilioClientTest extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP POST" + name "POST" kind CLIENT childOf span(1) status ERROR @@ -324,7 +324,7 @@ class TwilioClientTest extends AgentInstrumentationSpecification { } } span(3) { - name "HTTP POST" + name "POST" kind CLIENT childOf span(1) attributes { @@ -397,7 +397,7 @@ class TwilioClientTest extends AgentInstrumentationSpecification { } } span(2) { - name "HTTP POST" + name "POST" kind CLIENT childOf span(1) status ERROR @@ -411,7 +411,7 @@ class TwilioClientTest extends AgentInstrumentationSpecification { } } span(3) { - name "HTTP POST" + name "POST" kind CLIENT childOf span(1) attributes { 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 06be9d773008..7f2f786b1c37 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 @@ -37,7 +37,7 @@ public final class UndertowSingletons { .setCapturedRequestHeaders(CommonConfig.get().getServerRequestHeaders()) .setCapturedResponseHeaders(CommonConfig.get().getServerResponseHeaders()) .build()) - .addContextCustomizer(HttpRouteHolder.get()) + .addContextCustomizer(HttpRouteHolder.create(httpAttributesGetter)) .addContextCustomizer( (context, request, attributes) -> { // span is ended when counter reaches 0, we start from 2 which accounts for the diff --git a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy index 593b38275a53..e6b213ed7007 100644 --- a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy +++ b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy @@ -127,7 +127,7 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr trace(0, 2) { it.span(0) { hasNoParent() - name "HTTP GET" + name "GET" kind SpanKind.SERVER event(0) { @@ -179,7 +179,7 @@ class UndertowServerTest extends HttpServerTest implements AgentTestTr trace(0, 2) { it.span(0) { hasNoParent() - name "HTTP GET" + name "GET" kind SpanKind.SERVER status StatusCode.ERROR diff --git a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin14Test.java b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin14Test.java index 23d6145d40b8..fff1388fa74f 100644 --- a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin14Test.java +++ b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin14Test.java @@ -24,7 +24,7 @@ void assertFirstRequest() { .satisfies( spans -> { OpenTelemetryAssertions.assertThat(spans.get(0)) - .hasName(getContextPath() + "/main") + .hasName("GET " + getContextPath() + "/main") .hasNoParent() .hasKind(SpanKind.SERVER); OpenTelemetryAssertions.assertThat(spans.get(1)) diff --git a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin16Test.java b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin16Test.java index 4ce41b629ec7..0cc5c19b21a0 100644 --- a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin16Test.java +++ b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadin16Test.java @@ -28,14 +28,14 @@ void assertFirstRequest() { .satisfies( spans -> OpenTelemetryAssertions.assertThat(spans.get(0)) - .hasName("IndexHtmlRequestHandler.handleRequest") + .hasName("GET IndexHtmlRequestHandler.handleRequest") .hasNoParent() .hasKind(SpanKind.SERVER)); assertThat(trace) .anySatisfy( spans -> { OpenTelemetryAssertions.assertThat(spans.get(0)) - .hasName(getContextPath() + "/main") + .hasName("POST " + getContextPath() + "/main") .hasNoParent() .hasKind(SpanKind.SERVER); OpenTelemetryAssertions.assertThat(spans.get(1)) diff --git a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadinTest.java b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadinTest.java index fcf6966e39b6..9fb2c116ebb1 100644 --- a/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadinTest.java +++ b/instrumentation/vaadin-14.2/testing/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/AbstractVaadinTest.java @@ -139,7 +139,7 @@ private void assertButtonClick() { .satisfies( spans -> { OpenTelemetryAssertions.assertThat(spans.get(0)) - .hasName(getContextPath() + "/main") + .hasName("POST " + getContextPath() + "/main") .hasNoParent() .hasKind(SpanKind.SERVER); OpenTelemetryAssertions.assertThat(spans.get(1)) diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy index 9ed5613d20c8..30276a75dc01 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy @@ -59,7 +59,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 4) { span(0) { - name "/listProducts" + name "GET /listProducts" kind SERVER hasNoParent() attributes { @@ -152,7 +152,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { } } span(1) { - name "/listProducts" + name "GET /listProducts" kind SERVER childOf(span(0)) attributes { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy index 9ed5613d20c8..30276a75dc01 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy @@ -59,7 +59,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 4) { span(0) { - name "/listProducts" + name "GET /listProducts" kind SERVER hasNoParent() attributes { @@ -152,7 +152,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { } } span(1) { - name "/listProducts" + name "GET /listProducts" kind SERVER childOf(span(0)) attributes { diff --git a/instrumentation/wicket-8.0/javaagent/src/test/groovy/WicketTest.groovy b/instrumentation/wicket-8.0/javaagent/src/test/groovy/WicketTest.groovy index 87226e0ef204..109576a3ba40 100644 --- a/instrumentation/wicket-8.0/javaagent/src/test/groovy/WicketTest.groovy +++ b/instrumentation/wicket-8.0/javaagent/src/test/groovy/WicketTest.groovy @@ -71,7 +71,7 @@ class WicketTest extends AgentInstrumentationSpecification implements HttpServer assertTraces(1) { trace(0, 1) { span(0) { - name getContextPath() + "/wicket-test/hello.HelloPage" + name "GET " + getContextPath() + "/wicket-test/hello.HelloPage" kind SpanKind.SERVER hasNoParent() } @@ -90,7 +90,7 @@ class WicketTest extends AgentInstrumentationSpecification implements HttpServer assertTraces(1) { trace(0, 1) { span(0) { - name getContextPath() + "/wicket-test/hello.ExceptionPage" + name "GET " + getContextPath() + "/wicket-test/hello.ExceptionPage" kind SpanKind.SERVER hasNoParent() status StatusCode.ERROR diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy index 5f538557703f..0e3e9423fef0 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy @@ -371,12 +371,12 @@ abstract class AppServerTest extends SmokeTest { case "/app/headers": case "/app/exception": case "/app/asyncgreeting": - return path + return "GET " + path case "/app/hello.txt": case "/app/file-that-does-not-exist": - return "/app/*" + return "GET /app/*" } - return "HTTP GET" + return "GET" } protected List> getTestParams() { diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/LibertyServletOnlySmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/LibertyServletOnlySmokeTest.groovy index ccd5dd789dd9..9db4f12ca80b 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/LibertyServletOnlySmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/LibertyServletOnlySmokeTest.groovy @@ -22,7 +22,7 @@ abstract class LibertyServletOnlySmokeTest extends LibertySmokeTest { switch (path) { case "/app/hello.txt": case "/app/file-that-does-not-exist": - return "HTTP GET" + return "GET" } return super.getSpanName(path) } diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy index 77e8d75af2df..7361ed0a0a74 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy @@ -32,7 +32,7 @@ abstract class PayaraSmokeTest extends AppServerTest { protected String getSpanName(String path) { switch (path) { case "/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless": - return "/*" + return "GET /*" } return super.getSpanName(path) } diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/QuarkusSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/QuarkusSmokeTest.groovy index 166198cd9207..d6b380771428 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/QuarkusSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/QuarkusSmokeTest.groovy @@ -40,7 +40,7 @@ class QuarkusSmokeTest extends SmokeTest { Collection traces = waitForTraces() then: - countSpansByName(traces, '/hello') == 1 + countSpansByName(traces, 'GET /hello') == 1 countSpansByName(traces, 'HelloResource.hello') == 1 [currentAgentVersion] as Set == findResourceAttribute(traces, "telemetry.auto.version") diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy index b013a87a0a73..4d651838f92c 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootSmokeTest.groovy @@ -46,7 +46,7 @@ class SpringBootSmokeTest extends SmokeTest { then: "spans are exported" response.contentUtf8() == "Hi!" - countSpansByName(traces, '/greeting') == 1 + countSpansByName(traces, 'GET /greeting') == 1 countSpansByName(traces, 'WebController.greeting') == 1 countSpansByName(traces, 'WebController.withSpan') == 1 diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootWithSamplingSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootWithSamplingSmokeTest.groovy index a99ee0854373..a61d1407fae5 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootWithSamplingSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/SpringBootWithSamplingSmokeTest.groovy @@ -48,7 +48,7 @@ class SpringBootWithSamplingSmokeTest extends SmokeTest { then: // since sampling is enabled, not really expecting to receive NUM_TRIES spans Math.abs(countSpansByName(traces, 'WebController.greeting') - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION - Math.abs(countSpansByName(traces, '/greeting') - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION + Math.abs(countSpansByName(traces, 'GET /greeting') - (SAMPLER_PROBABILITY * NUM_TRIES)) <= ALLOWED_DEVIATION cleanup: stopTarget() diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TomeeSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TomeeSmokeTest.groovy index 73f771a0d820..a20cf1151600 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TomeeSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/TomeeSmokeTest.groovy @@ -22,7 +22,7 @@ abstract class TomeeSmokeTest extends AppServerTest { protected String getSpanName(String path) { switch (path) { case "/this-is-definitely-not-there-but-there-should-be-a-trace-nevertheless": - return "/*" + return "GET /*" } return super.getSpanName(path) } diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WebsphereSmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WebsphereSmokeTest.groovy index b30304f0e58e..cac77ac8392d 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WebsphereSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WebsphereSmokeTest.groovy @@ -23,7 +23,7 @@ abstract class WebsphereSmokeTest extends AppServerTest { switch (path) { case "/app/hello.txt": case "/app/file-that-does-not-exist": - return "HTTP GET" + return "GET" } return super.getSpanName(path) } diff --git a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WildflySmokeTest.groovy b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WildflySmokeTest.groovy index 8620daa4c1fb..89055de819a4 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WildflySmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/WildflySmokeTest.groovy @@ -34,7 +34,7 @@ abstract class WildflySmokeTest extends AppServerTest { traces.countSpansByKind(Span.SpanKind.SPAN_KIND_SERVER) == 1 - traces.countSpansByName('/app/jsp') == 1 + traces.countSpansByName('GET /app/jsp') == 1 where: [appServer, jdk] << getTestParams() diff --git a/testing-common/build.gradle.kts b/testing-common/build.gradle.kts index b0dd96855c26..81482f5f5292 100644 --- a/testing-common/build.gradle.kts +++ b/testing-common/build.gradle.kts @@ -62,6 +62,7 @@ dependencies { implementation("org.slf4j:jcl-over-slf4j") implementation("org.slf4j:jul-to-slf4j") implementation("io.opentelemetry:opentelemetry-exporter-logging") + implementation(project(":instrumentation-api-semconv")) annotationProcessor("com.google.auto.service:auto-service") compileOnly("com.google.auto.service:auto-service") diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/InstrumentationSpecification.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/InstrumentationSpecification.groovy index 7cc16eb6261a..e5ef477fa74d 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/InstrumentationSpecification.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/InstrumentationSpecification.groovy @@ -143,7 +143,7 @@ abstract class InstrumentationSpecification extends Specification { * Runs the provided {@code callback} inside the scope of an HTTP CLIENT span with name {@code * spanName}. */ - def T runWithHttpServerSpan(String spanName, Closure callback) { - return (T) testRunner().runWithHttpServerSpan(spanName, (ThrowingSupplier) callback) + def T runWithHttpServerSpan(Closure callback) { + return (T) testRunner().runWithHttpServerSpan((ThrowingSupplier) callback) } } diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy index c2c5b71e58e7..704465850b53 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy @@ -428,7 +428,7 @@ abstract class HttpClientTest extends InstrumentationSpecification { } protected String expectedClientSpanName(URI uri, String method) { - return method != null ? "HTTP " + method : "HTTP request" + return method } Integer responseCodeOnRedirectError() { diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy index 667c21b2704f..fea1bc7c3bfe 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy @@ -24,6 +24,7 @@ import io.opentelemetry.testing.internal.armeria.common.HttpMethod import spock.lang.Shared import spock.lang.Unroll +import javax.annotation.Nullable import java.util.concurrent.Callable import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION @@ -47,9 +48,8 @@ abstract class HttpServerTest extends InstrumentationSpecification imple cleanupServer() } - String expectedServerSpanName(ServerEndpoint endpoint, String method) { - def route = expectedHttpRoute(endpoint) - return route == null ? "HTTP $method" : route + String expectedServerSpanName(ServerEndpoint endpoint, String method, @Nullable String route) { + return route == null ? method : method + " " + route } String expectedHttpRoute(ServerEndpoint endpoint) { @@ -185,8 +185,8 @@ abstract class HttpServerTest extends InstrumentationSpecification imple @Override protected void configure(HttpServerTestOptions options) { - options.expectedServerSpanNameMapper = { endpoint, method -> - HttpServerTest.this.expectedServerSpanName(endpoint, method) + options.expectedServerSpanNameMapper = { endpoint, method, route -> + HttpServerTest.this.expectedServerSpanName(endpoint, method, route) } options.expectedHttpRoute = { endpoint -> HttpServerTest.this.expectedHttpRoute(endpoint) diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java index 00d0195ad419..65e7d016b1b0 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/InstrumentationTestRunner.java @@ -183,10 +183,9 @@ public final T runWithHttpClientSpan( * Runs the provided {@code callback} inside the scope of an HTTP SERVER span with name {@code * spanName}. */ - public final void runWithHttpServerSpan( - String spanName, ThrowingRunnable callback) throws E { + public final void runWithHttpServerSpan(ThrowingRunnable callback) + throws E { runWithHttpServerSpan( - spanName, () -> { callback.run(); return null; @@ -197,9 +196,9 @@ public final void runWithHttpServerSpan( * Runs the provided {@code callback} inside the scope of an HTTP SERVER span with name {@code * spanName}. */ - public final T runWithHttpServerSpan( - String spanName, ThrowingSupplier callback) throws E { - return testInstrumenters.runWithHttpServerSpan(spanName, callback); + public final T runWithHttpServerSpan(ThrowingSupplier callback) + throws E { + return testInstrumenters.runWithHttpServerSpan(callback); } /** Runs the provided {@code callback} inside the scope of a non-recording span. */ diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java index 203ae7b2e64f..f3cd7ea1bf4f 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/TestInstrumenters.java @@ -5,6 +5,8 @@ package io.opentelemetry.instrumentation.testing; +import static java.util.Collections.emptyList; + import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.api.trace.Span; @@ -16,9 +18,15 @@ import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpRouteHolder; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesGetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesGetter; import io.opentelemetry.instrumentation.api.internal.SpanKey; import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; import io.opentelemetry.instrumentation.testing.util.ThrowingSupplier; +import java.util.List; import javax.annotation.Nullable; /** {@link Instrumenter}s to use when executing test code. */ @@ -39,10 +47,14 @@ final class TestInstrumenters { .addAttributesExtractor(new SpanKeyAttributesExtractor(SpanKey.KIND_CLIENT)) .buildInstrumenter(SpanKindExtractor.alwaysClient()); httpServerInstrumenter = - Instrumenter.builder(openTelemetry, "test", name -> name) + Instrumenter.builder( + openTelemetry, "test", HttpSpanNameExtractor.create(HttpServerGetter.INSTANCE)) // cover both semconv and span-kind strategies - .addAttributesExtractor(new SpanKeyAttributesExtractor(SpanKey.HTTP_SERVER)) + .addAttributesExtractor( + HttpServerAttributesExtractor.create( + HttpServerGetter.INSTANCE, NetServerGetter.INSTANCE)) .addAttributesExtractor(new SpanKeyAttributesExtractor(SpanKey.KIND_SERVER)) + .addContextCustomizer(HttpRouteHolder.create(HttpServerGetter.INSTANCE)) .buildInstrumenter(SpanKindExtractor.alwaysServer()); } @@ -68,9 +80,8 @@ T runWithHttpClientSpan(String spanName, ThrowingSuppli * Runs the provided {@code callback} inside the scope of an CLIENT span with name {@code * spanName}. */ - T runWithHttpServerSpan(String spanName, ThrowingSupplier callback) - throws E { - return runWithInstrumenter(spanName, httpServerInstrumenter, callback); + T runWithHttpServerSpan(ThrowingSupplier callback) throws E { + return runWithInstrumenter("ignored", httpServerInstrumenter, callback); } /** Runs the provided {@code callback} inside the scope of a non-recording span. */ @@ -126,4 +137,75 @@ public SpanKey internalGetSpanKey() { return spanKey; } } + + private enum HttpServerGetter implements HttpServerAttributesGetter { + INSTANCE; + + @Override + public String getMethod(String unused) { + return "GET"; + } + + @Override + public List getRequestHeader(String unused, String name) { + return emptyList(); + } + + @Nullable + @Override + public Integer getStatusCode(String unused, Void unused2, @Nullable Throwable error) { + return null; + } + + @Override + public List getResponseHeader(String unused, Void unused2, String name) { + return emptyList(); + } + + @Nullable + @Override + public String getFlavor(String unused) { + return null; + } + + @Nullable + @Override + public String getTarget(String unused) { + return null; + } + + @Nullable + @Override + public String getRoute(String unused) { + return null; + } + + @Nullable + @Override + public String getScheme(String unused) { + return null; + } + } + + private enum NetServerGetter implements NetServerAttributesGetter { + INSTANCE; + + @Nullable + @Override + public String getTransport(String unused) { + return null; + } + + @Nullable + @Override + public String getHostName(String unused) { + return null; + } + + @Nullable + @Override + public Integer getHostPort(String unused) { + return null; + } + } } diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java index ab9cb95b2fb2..5900b842397f 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/InstrumentationExtension.java @@ -196,18 +196,17 @@ public T runWithHttpClientSpan( * Runs the provided {@code callback} inside the scope of an CLIENT span with name {@code * spanName}. */ - public void runWithHttpServerSpan( - String spanName, ThrowingRunnable callback) throws E { - testRunner.runWithHttpServerSpan(spanName, callback); + public void runWithHttpServerSpan(ThrowingRunnable callback) throws E { + testRunner.runWithHttpServerSpan(callback); } /** * Runs the provided {@code callback} inside the scope of an CLIENT span with name {@code * spanName}. */ - public T runWithHttpServerSpan( - String spanName, ThrowingSupplier callback) throws E { - return testRunner.runWithHttpServerSpan(spanName, callback); + public T runWithHttpServerSpan(ThrowingSupplier callback) + throws E { + return testRunner.runWithHttpServerSpan(callback); } /** Returns whether forceFlush was called. */ diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index a66db66cb609..8755f19da7e6 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -959,7 +959,7 @@ protected Set> httpAttributes(URI uri) { } protected String expectedClientSpanName(URI uri, String method) { - return method != null ? "HTTP " + method : "HTTP request"; + return HttpClientTestOptions.DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER.apply(uri, method); } @Nullable diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java index f86e8acc9b2d..9028e4032d2c 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -47,6 +47,7 @@ import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; import java.util.function.Supplier; +import javax.annotation.Nullable; import org.awaitility.Awaitility; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; @@ -463,13 +464,10 @@ protected List> errorPageSpanAssertions( protected SpanDataAssert assertServerSpan( SpanDataAssert span, String method, ServerEndpoint endpoint) { - Set> httpAttributes = options.httpAttributes.apply(endpoint); + Set> httpAttributes = options.httpAttributes.apply(endpoint); String expectedRoute = options.expectedHttpRoute.apply(endpoint); - String name = - expectedRoute != null - ? expectedRoute - : options.expectedServerSpanNameMapper.apply(endpoint, method); + String name = getString(method, endpoint, expectedRoute); span.hasName(name).hasKind(SpanKind.SERVER); if (endpoint.status >= 500) { @@ -569,6 +567,11 @@ protected SpanDataAssert assertServerSpan( return span; } + private String getString(String method, ServerEndpoint endpoint, String expectedRoute) { + String name = options.expectedServerSpanNameMapper.apply(endpoint, method, expectedRoute); + return name; + } + protected SpanDataAssert assertIndexedServerSpan(SpanDataAssert span, int requestId) { ServerEndpoint endpoint = INDEXED_CHILD; String method = "GET"; @@ -592,9 +595,10 @@ protected SpanDataAssert assertIndexedControllerSpan(SpanDataAssert span, int re return span; } - public String expectedServerSpanName(ServerEndpoint endpoint, String method) { - String route = expectedHttpRoute(endpoint); - return route == null ? "HTTP " + method : route; + public String expectedServerSpanName( + ServerEndpoint endpoint, String method, @Nullable String route) { + return HttpServerTestOptions.DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER.apply( + endpoint, method, route); } public String expectedHttpRoute(ServerEndpoint endpoint) { diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java index 2e594ed681e3..c182cd859ada 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java @@ -32,7 +32,7 @@ public abstract class HttpClientTestOptions { SemanticAttributes.HTTP_USER_AGENT))); public static final BiFunction DEFAULT_EXPECTED_CLIENT_SPAN_NAME_MAPPER = - (uri, method) -> method != null ? "HTTP " + method : "HTTP request"; + (uri, method) -> method; public abstract Function>> getHttpAttributes(); diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java index 838bd4943770..7f6768773fcf 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java @@ -12,9 +12,9 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; +import javax.annotation.Nullable; public final class HttpServerTestOptions { @@ -26,12 +26,11 @@ public final class HttpServerTestOptions { SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NET_PEER_PORT))); - public static final BiFunction - DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = (uri, method) -> "HTTP " + method; + public static final SpanNameMapper DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = + (uri, method, route) -> route == null ? method : method + " " + route; Function>> httpAttributes = unused -> DEFAULT_HTTP_ATTRIBUTES; - BiFunction expectedServerSpanNameMapper = - DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER; + SpanNameMapper expectedServerSpanNameMapper = DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER; Function expectedHttpRoute = unused -> null; Function sockPeerAddr = unused -> "127.0.0.1"; String contextPath = ""; @@ -63,7 +62,7 @@ public HttpServerTestOptions setHttpAttributes( @CanIgnoreReturnValue public HttpServerTestOptions setExpectedServerSpanNameMapper( - BiFunction expectedServerSpanNameMapper) { + SpanNameMapper expectedServerSpanNameMapper) { this.expectedServerSpanNameMapper = expectedServerSpanNameMapper; return this; } @@ -166,4 +165,10 @@ public HttpServerTestOptions setTestCaptureRequestParameters( this.testCaptureRequestParameters = testCaptureRequestParameters; return this; } + + @FunctionalInterface + public interface SpanNameMapper { + + String apply(ServerEndpoint endpoint, String method, @Nullable String route); + } }