Skip to content

Commit

Permalink
Netty server instrumentation now captures http.scheme (#4446)
Browse files Browse the repository at this point in the history
* Netty server instrumentation now captures http.scheme

* Fixed Spring Netty related tests

* Fixed Spring Netty related tests
  • Loading branch information
osherv authored Oct 21, 2021
1 parent c490b29 commit 7998c84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,21 @@
final class NettyHttpServerAttributesExtractor
extends HttpServerAttributesExtractor<HttpRequestAndChannel, HttpResponse> {

private static final Class<? extends ChannelHandler> sslHandlerClass = getSslHandlerClass();

@SuppressWarnings("unchecked")
private static Class<? extends ChannelHandler> getSslHandlerClass() {
try {
return (Class<? extends ChannelHandler>)
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();
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7998c84

Please sign in to comment.