diff --git a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyHttpServerAttributesExtractor.java b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyHttpServerAttributesExtractor.java index ab0c4c6644f3..7063cbeb7d12 100644 --- a/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyHttpServerAttributesExtractor.java +++ b/instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyHttpServerAttributesExtractor.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.netty.common.server; +import io.netty.channel.ChannelHandler; import io.netty.handler.codec.http.HttpResponse; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor; import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel; @@ -14,6 +15,21 @@ final class NettyHttpServerAttributesExtractor extends HttpServerAttributesExtractor { + private static final Class sslHandlerClass = getSslHandlerClass(); + + @SuppressWarnings("unchecked") + private static Class getSslHandlerClass() { + try { + return (Class) + Class.forName( + "io.netty.handler.ssl.SslHandler", + false, + NettyHttpServerAttributesExtractor.class.getClassLoader()); + } catch (ClassNotFoundException exception) { + return null; + } + } + @Override protected String method(HttpRequestAndChannel requestAndChannel) { return requestAndChannel.request().getMethod().name(); @@ -86,7 +102,8 @@ protected String route(HttpRequestAndChannel requestAndChannel) { @Override @Nullable protected String scheme(HttpRequestAndChannel requestAndChannel) { - return null; + boolean isHttps = requestAndChannel.channel().pipeline().get(sslHandlerClass) != null; + return isHttps ? "https" : "http"; } @Override diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/SpringWebfluxTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/SpringWebfluxTest.groovy index 21717d8c581e..8f6cff7ea7b0 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/SpringWebfluxTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/SpringWebfluxTest.groovy @@ -86,6 +86,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" urlPath "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -150,6 +151,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" urlPath "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -234,6 +236,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" urlPath "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -296,6 +299,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" "/notfoundgreet" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 404 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -337,6 +341,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" "/echo" "${SemanticAttributes.HTTP_METHOD.key}" "POST" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 202 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -383,6 +388,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" urlPath "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 500 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -444,6 +450,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" "/double-greet-redirect" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 307 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -473,6 +480,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" "/double-greet" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -517,6 +525,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET}" urlPath "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } diff --git a/instrumentation/vertx-reactive-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx-reactive-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy index 1332d15227ad..9878f15f93e7 100644 --- a/instrumentation/vertx-reactive-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx-reactive-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy @@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET.key}" "/listProducts" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -157,6 +158,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET.key}" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String "${TEST_REQUEST_ID_ATTRIBUTE}" requestId diff --git a/instrumentation/vertx-reactive-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx-reactive-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy index 1332d15227ad..9878f15f93e7 100644 --- a/instrumentation/vertx-reactive-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx-reactive-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy @@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET.key}" "/listProducts" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String } @@ -157,6 +158,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification { "${SemanticAttributes.HTTP_TARGET.key}" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId" "${SemanticAttributes.HTTP_METHOD.key}" "GET" "${SemanticAttributes.HTTP_STATUS_CODE.key}" 200 + "${SemanticAttributes.HTTP_SCHEME.key}" "http" "${SemanticAttributes.HTTP_FLAVOR.key}" "1.1" "${SemanticAttributes.HTTP_USER_AGENT.key}" String "${TEST_REQUEST_ID_ATTRIBUTE}" requestId