Skip to content

Commit 7998c84

Browse files
authored
Netty server instrumentation now captures http.scheme (#4446)
* Netty server instrumentation now captures http.scheme * Fixed Spring Netty related tests * Fixed Spring Netty related tests
1 parent c490b29 commit 7998c84

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

instrumentation/netty/netty-4-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/netty/common/server/NettyHttpServerAttributesExtractor.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.javaagent.instrumentation.netty.common.server;
77

8+
import io.netty.channel.ChannelHandler;
89
import io.netty.handler.codec.http.HttpResponse;
910
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerAttributesExtractor;
1011
import io.opentelemetry.javaagent.instrumentation.netty.common.HttpRequestAndChannel;
@@ -14,6 +15,21 @@
1415
final class NettyHttpServerAttributesExtractor
1516
extends HttpServerAttributesExtractor<HttpRequestAndChannel, HttpResponse> {
1617

18+
private static final Class<? extends ChannelHandler> sslHandlerClass = getSslHandlerClass();
19+
20+
@SuppressWarnings("unchecked")
21+
private static Class<? extends ChannelHandler> getSslHandlerClass() {
22+
try {
23+
return (Class<? extends ChannelHandler>)
24+
Class.forName(
25+
"io.netty.handler.ssl.SslHandler",
26+
false,
27+
NettyHttpServerAttributesExtractor.class.getClassLoader());
28+
} catch (ClassNotFoundException exception) {
29+
return null;
30+
}
31+
}
32+
1733
@Override
1834
protected String method(HttpRequestAndChannel requestAndChannel) {
1935
return requestAndChannel.request().getMethod().name();
@@ -86,7 +102,8 @@ protected String route(HttpRequestAndChannel requestAndChannel) {
86102
@Override
87103
@Nullable
88104
protected String scheme(HttpRequestAndChannel requestAndChannel) {
89-
return null;
105+
boolean isHttps = requestAndChannel.channel().pipeline().get(sslHandlerClass) != null;
106+
return isHttps ? "https" : "http";
90107
}
91108

92109
@Override

instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/SpringWebfluxTest.groovy

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
8686
"${SemanticAttributes.HTTP_TARGET}" urlPath
8787
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
8888
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
89+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
8990
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
9091
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
9192
}
@@ -150,6 +151,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
150151
"${SemanticAttributes.HTTP_TARGET}" urlPath
151152
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
152153
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
154+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
153155
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
154156
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
155157
}
@@ -234,6 +236,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
234236
"${SemanticAttributes.HTTP_TARGET}" urlPath
235237
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
236238
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
239+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
237240
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
238241
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
239242
}
@@ -296,6 +299,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
296299
"${SemanticAttributes.HTTP_TARGET}" "/notfoundgreet"
297300
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
298301
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 404
302+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
299303
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
300304
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
301305
}
@@ -337,6 +341,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
337341
"${SemanticAttributes.HTTP_TARGET}" "/echo"
338342
"${SemanticAttributes.HTTP_METHOD.key}" "POST"
339343
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 202
344+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
340345
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
341346
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
342347
}
@@ -383,6 +388,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
383388
"${SemanticAttributes.HTTP_TARGET}" urlPath
384389
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
385390
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 500
391+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
386392
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
387393
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
388394
}
@@ -444,6 +450,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
444450
"${SemanticAttributes.HTTP_TARGET}" "/double-greet-redirect"
445451
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
446452
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 307
453+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
447454
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
448455
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
449456
}
@@ -473,6 +480,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
473480
"${SemanticAttributes.HTTP_TARGET}" "/double-greet"
474481
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
475482
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
483+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
476484
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
477485
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
478486
}
@@ -517,6 +525,7 @@ class SpringWebfluxTest extends AgentInstrumentationSpecification {
517525
"${SemanticAttributes.HTTP_TARGET}" urlPath
518526
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
519527
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
528+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
520529
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
521530
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
522531
}

instrumentation/vertx-reactive-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
6969
"${SemanticAttributes.HTTP_TARGET.key}" "/listProducts"
7070
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
7171
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
72+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
7273
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
7374
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
7475
}
@@ -157,6 +158,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
157158
"${SemanticAttributes.HTTP_TARGET.key}" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId"
158159
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
159160
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
161+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
160162
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
161163
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
162164
"${TEST_REQUEST_ID_ATTRIBUTE}" requestId

instrumentation/vertx-reactive-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
6969
"${SemanticAttributes.HTTP_TARGET.key}" "/listProducts"
7070
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
7171
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
72+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
7273
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
7374
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
7475
}
@@ -157,6 +158,7 @@ class VertxReactivePropagationTest extends AgentInstrumentationSpecification {
157158
"${SemanticAttributes.HTTP_TARGET.key}" "$baseUrl?$TEST_REQUEST_ID_PARAMETER=$requestId"
158159
"${SemanticAttributes.HTTP_METHOD.key}" "GET"
159160
"${SemanticAttributes.HTTP_STATUS_CODE.key}" 200
161+
"${SemanticAttributes.HTTP_SCHEME.key}" "http"
160162
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
161163
"${SemanticAttributes.HTTP_USER_AGENT.key}" String
162164
"${TEST_REQUEST_ID_ATTRIBUTE}" requestId

0 commit comments

Comments
 (0)