Fix jboss-logmanager testLatestDeps
MODIFY
instrumentation/java-util-logging/javaagent/build.gradle.kts
instrumentation/java-util-logging/javaagent/build.gradle.kts
@@ -7,10 +7,6 @@ dependencies {
compileOnly(project(":instrumentation-appender-api-internal"))
- // the JBoss instrumentation in this artifact is needed
- // for jboss-logmanager versions 1.1.0.GA through latest 2.x
- testLibrary("org.jboss.logmanager:jboss-logmanager:1.1.0.GA")
-
testImplementation("org.awaitility:awaitility")
}

DELETE
instrumentation/java-util-logging/javaagent/src/test/groovy/JBossJavaUtilLoggingTest.groovy
-/*
- * Copyright The OpenTelemetry Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-
-import org.jboss.logmanager.LogContext
-
-class JBossJavaUtilLoggingTest extends JavaUtilLoggingTest {
-
- @Override
- Object createLogger(String name) {
- LogContext.create().getLogger(name)
- }
-}

ADD
instrumentation/java-util-logging/jboss-testing/build.gradle.kts
+plugins {
+ id("otel.javaagent-testing")
+}
+
+// separate testing module is needed, because presence of jboss-logmanager 2.1.6 or later
+// on the classpath causes the normal java.util.logging test to use it
+
+dependencies {
+ compileOnly(project(":instrumentation:java-util-logging:shaded-stub-for-instrumenting"))
+
+ compileOnly(project(":instrumentation-appender-api-internal"))
+
+ testInstrumentation(project(":instrumentation:java-util-logging:javaagent"))
+
+ // the JBoss instrumentation in this artifact is needed
+ // for jboss-logmanager versions 1.1.0.GA through latest 2.x
+ testLibrary("org.jboss.logmanager:jboss-logmanager:1.1.0.GA")
+
+ testImplementation("org.awaitility:awaitility")
+}
+
+tasks.withType<Test>().configureEach {
+ // TODO run tests both with and without experimental log attributes
+ jvmArgs("-Dotel.instrumentation.java-util-logging.experimental-log-attributes=true")
+}

ADD
instrumentation/java-util-logging/jboss-testing/src/test/groovy/JavaUtilLoggingJBossTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
+import io.opentelemetry.sdk.logs.data.Severity
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
+import org.jboss.logmanager.LogContext
+import spock.lang.Shared
+import spock.lang.Unroll
+
+import java.util.logging.Level
+
+import static org.assertj.core.api.Assertions.assertThat
+import static org.awaitility.Awaitility.await
+
+class JavaUtilLoggingJBossTest extends AgentInstrumentationSpecification {
+
+ @Shared
+ private final Object logger = LogContext.create().getLogger("abc")
+
+ @Unroll
+ def "test method=#testMethod with testArgs=#testArgs and parent=#parent"() {
+ when:
+ if (parent) {
+ runWithSpan("parent") {
+ if (testArgs == "exception") {
+ logger.log(Level."${testMethod.toUpperCase()}", "xyz", new IllegalStateException("hello"))
+ } else if (testArgs == "params") {
+ logger.log(Level."${testMethod.toUpperCase()}", "xyz: {0}", 123)
+ } else {
+ logger."$testMethod"("xyz")
+ }
+ }
+ } else {
+ if (testArgs == "exception") {
+ logger.log(Level."${testMethod.toUpperCase()}", "xyz", new IllegalStateException("hello"))
+ } else if (testArgs == "params") {
+ logger.log(Level."${testMethod.toUpperCase()}", "xyz: {0}", 123)
+ } else {
+ logger."$testMethod"("xyz")
+ }
+ }
+
+ then:
+ if (parent) {
+ waitForTraces(1)
+ }
+
+ if (severity != null) {
+ await()
+ .untilAsserted(
+ () -> {
+ assertThat(logs).hasSize(1)
+ })
+ def log = logs.get(0)
+ if (testArgs == "params") {
+ assertThat(log.getBody().asString()).isEqualTo("xyz: 123")
+ } else {
+ assertThat(log.getBody().asString()).isEqualTo("xyz")
+ }
+ assertThat(log.getInstrumentationLibraryInfo().getName()).isEqualTo("abc")
+ assertThat(log.getSeverity()).isEqualTo(severity)
+ assertThat(log.getSeverityText()).isEqualTo(severityText)
+ if (testArgs == "exception") {
+ assertThat(log.getAttributes().size()).isEqualTo(5)
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE)).isEqualTo(IllegalStateException.getName())
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE)).isEqualTo("hello")
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE)).contains(JavaUtilLoggingJBossTest.name)
+ } else {
+ assertThat(log.getAttributes().size()).isEqualTo(2)
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE)).isNull()
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE)).isNull()
+ assertThat(log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE)).isNull()
+ }
+ assertThat(log.getAttributes().get(SemanticAttributes.THREAD_NAME)).isEqualTo(Thread.currentThread().getName())
+ assertThat(log.getAttributes().get(SemanticAttributes.THREAD_ID)).isEqualTo(Thread.currentThread().getId())
+ if (parent) {
+ assertThat(log.getSpanContext()).isEqualTo(traces.get(0).get(0).getSpanContext())
+ } else {
+ assertThat(log.getSpanContext().isValid()).isFalse()
+ }
+ } else {
+ Thread.sleep(500) // sleep a bit just to make sure no log is captured
+ logs.size() == 0
+ }
+
+ where:
+ [args, testArgs, parent] << [
+ [
+ ["fine", null, null],
+ ["info", Severity.INFO, "INFO"],
+ ["warning", Severity.WARN, "WARNING"],
+ ["severe", Severity.ERROR, "SEVERE"]
+ ],
+ ["none", "exception", "param"],
+ [true, false]
+ ].combinations()
+
+ testMethod = args[0]
+ severity = args[1]
+ severityText = args[2]
+ }
+}

MODIFY
settings.gradle.kts
settings.gradle.kts
@@ -209,6 +209,7 @@ include(":instrumentation:http-url-connection:javaagent")
include(":instrumentation:hystrix-1.4:javaagent")
include(":instrumentation:java-http-client:javaagent")
include(":instrumentation:java-util-logging:javaagent")
+include(":instrumentation:java-util-logging:jboss-testing")
include(":instrumentation:java-util-logging:shaded-stub-for-instrumenting")
include(":instrumentation:jaxrs:jaxrs-common:bootstrap")
include(":instrumentation:jaxrs:jaxrs-1.0:javaagent")

Fix jboss-logmanager testLatestDeps (#5503)