From 6c44340f1c3c0812e0fe2cbde007858e9b822042 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 18 May 2022 00:18:29 +0300 Subject: [PATCH] Enable grizzly instrumentation by default (#6049) --- docs/supported-libraries.md | 11 ----------- .../grizzly-2.0/javaagent/build.gradle.kts | 2 ++ .../grizzly/DefaultFilterChainInstrumentation.java | 4 ++++ .../grizzly/GrizzlyInstrumentationModule.java | 5 ----- .../instrumentation/grizzly/GrizzlySingletons.java | 4 ++++ .../grizzly/HttpServerFilterInstrumentation.java | 4 ++++ .../io/opentelemetry/smoketest/AppServerTest.groovy | 4 ++-- .../io/opentelemetry/smoketest/PayaraSmokeTest.groovy | 5 ----- 8 files changed, 16 insertions(+), 23 deletions(-) diff --git a/docs/supported-libraries.md b/docs/supported-libraries.md index 189c60b583ed..cef24281a43c 100644 --- a/docs/supported-libraries.md +++ b/docs/supported-libraries.md @@ -12,7 +12,6 @@ or [contributing](../CONTRIBUTING.md). * [Application Servers](#application-servers) * [JVMs and Operating Systems](#jvms-and-operating-systems) * [Disabled instrumentations](#disabled-instrumentations) - + [Grizzly instrumentation](#grizzly-instrumentation) ## Libraries / Frameworks @@ -152,13 +151,3 @@ For this reason, the following instrumentations are disabled by default: To enable them, add the `otel.instrumentation..enabled` system property: `-Dotel.instrumentation.jdbc-datasource.enabled=true` - -### Grizzly instrumentation - -When you use -[Grizzly](https://javaee.github.io/grizzly/httpserverframework.html) for -Servlet-based applications, you get better experience from Servlet-specific -support. As these two instrumentations conflict with each other, more generic -instrumentation for Grizzly HTTP server is disabled by default. If needed, -you can enable it by adding the following system property: -`-Dotel.instrumentation.grizzly.enabled=true` diff --git a/instrumentation/grizzly-2.0/javaagent/build.gradle.kts b/instrumentation/grizzly-2.0/javaagent/build.gradle.kts index 69349cbb4fb8..90c528bf4208 100644 --- a/instrumentation/grizzly-2.0/javaagent/build.gradle.kts +++ b/instrumentation/grizzly-2.0/javaagent/build.gradle.kts @@ -14,6 +14,8 @@ muzzle { dependencies { compileOnly("org.glassfish.grizzly:grizzly-http:2.0") + bootstrap(project(":instrumentation:servlet:servlet-common:bootstrap")) + testImplementation("javax.xml.bind:jaxb-api:2.2.3") testImplementation("javax.ws.rs:javax.ws.rs-api:2.0") testLibrary("org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.0") diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/DefaultFilterChainInstrumentation.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/DefaultFilterChainInstrumentation.java index 5b2edabb9c45..308d1eb92a4a 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/DefaultFilterChainInstrumentation.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/DefaultFilterChainInstrumentation.java @@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.opentelemetry.context.Context; +import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -48,6 +49,9 @@ public static void onFail( HttpRequestPacket request = GrizzlyStateStorage.removeRequest(ctx); if (context != null && request != null) { Throwable error = GrizzlyErrorHolder.getOrDefault(context, throwable); + if (error == null) { + error = AppServerBridge.getException(context); + } instrumenter().end(context, request, null, error); } } diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyInstrumentationModule.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyInstrumentationModule.java index 042a0f5f465b..540057559647 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyInstrumentationModule.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/GrizzlyInstrumentationModule.java @@ -27,9 +27,4 @@ public List typeInstrumentations() { new HttpServerFilterInstrumentation(), new HttpHandlerInstrumentation()); } - - @Override - public boolean defaultEnabled() { - return false; - } } 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 497bdbea4784..08ade2d0f943 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 @@ -13,6 +13,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor; import io.opentelemetry.instrumentation.api.instrumenter.net.NetServerAttributesExtractor; +import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; @@ -33,6 +34,9 @@ public final class GrizzlySingletons { .addAttributesExtractor(HttpServerAttributesExtractor.create(httpAttributesGetter)) .addAttributesExtractor(NetServerAttributesExtractor.create(netAttributesGetter)) .addOperationMetrics(HttpServerMetrics.get()) + .addContextCustomizer( + (context, request, attributes) -> + new AppServerBridge.Builder().recordException().init(context)) .addContextCustomizer( (context, httpRequestPacket, startAttributes) -> GrizzlyErrorHolder.init(context)) .addContextCustomizer(HttpRouteHolder.get()) diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpServerFilterInstrumentation.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpServerFilterInstrumentation.java index 3042b40adc67..fcc5d0c9e1da 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpServerFilterInstrumentation.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpServerFilterInstrumentation.java @@ -11,6 +11,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import io.opentelemetry.context.Context; +import io.opentelemetry.javaagent.bootstrap.servlet.AppServerBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import net.bytebuddy.asm.Advice; @@ -50,6 +51,9 @@ public static void onExit( HttpRequestPacket request = GrizzlyStateStorage.removeRequest(ctx); if (context != null && request != null) { Throwable error = GrizzlyErrorHolder.getOrDefault(context, null); + if (error == null) { + error = AppServerBridge.getException(context); + } instrumenter().end(context, request, response, 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 66cb21a6f46a..e9dd23dace75 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/AppServerTest.groovy @@ -265,10 +265,10 @@ abstract class AppServerTest extends SmokeTest { traces.countFilteredAttributes("http.target", "/app/exception") == 1 and: "Number of spans tagged with current otel library version" - traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == 1 + traces.countFilteredResourceAttributes("telemetry.auto.version", currentAgentVersion) == traces.countSpans() and: "Number of spans tagged with expected OS type" - traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == 1 + traces.countFilteredResourceAttributes(OS_TYPE.key, isWindows ? WINDOWS : LINUX) == traces.countSpans() where: [appServer, jdk, isWindows] << getTestParams() 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 9eb613ecde6b..3479ff61bce4 100644 --- a/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy +++ b/smoke-tests/src/test/groovy/io/opentelemetry/smoketest/PayaraSmokeTest.groovy @@ -36,11 +36,6 @@ abstract class PayaraSmokeTest extends AppServerTest { } return super.getSpanName(path) } - - @Override - boolean testRequestWebInfWebXml() { - false - } } @AppServer(version = "5.2020.6", jdk = "8")