Capture logback formatted message
MODIFY
instrumentation/java-util-logging/javaagent/src/test/groovy/JavaUtilLoggingTest.groovy
instrumentation/java-util-logging/javaagent/src/test/groovy/JavaUtilLoggingTest.groovy
@@ -19,19 +19,23 @@ class JavaUtilLoggingTest extends AgentInstrumentationSpecification {
private static final Logger logger = Logger.getLogger("abc")
@Unroll
- def "test method=#testMethod with exception=#exception and parent=#parent"() {
+ def "test method=#testMethod with testArgs=#testArgs and parent=#parent"() {
when:
if (parent) {
runWithSpan("parent") {
- if (exception) {
+ 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 (exception) {
+ 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")
}
@@ -49,11 +53,15 @@ class JavaUtilLoggingTest extends AgentInstrumentationSpecification {
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 (exception) {
+ 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")
@@ -77,14 +85,14 @@ class JavaUtilLoggingTest extends AgentInstrumentationSpecification {
}
where:
- [args, exception, parent] << [
+ [args, testArgs, parent] << [
[
["fine", null, null],
["info", Severity.INFO, "INFO"],
["warning", Severity.WARN, "WARNING"],
["severe", Severity.ERROR, "SEVERE"]
],
- [true, false],
+ ["none", "exception", "param"],
[true, false]
].combinations()

MODIFY
instrumentation/log4j/log4j-appender-2.16/javaagent/src/test/groovy/Log4j2Test.groovy
instrumentation/log4j/log4j-appender-2.16/javaagent/src/test/groovy/Log4j2Test.groovy
@@ -27,16 +27,16 @@ class Log4j2Test extends AgentInstrumentationSpecification {
if (parent) {
runWithSpan("parent") {
if (exception) {
- logger."$testMethod"("xyz", new IllegalStateException("hello"))
+ logger."$testMethod"("xyz: {}", 123, new IllegalStateException("hello"))
} else {
- logger."$testMethod"("xyz")
+ logger."$testMethod"("xyz: {}", 123)
}
}
} else {
if (exception) {
- logger."$testMethod"("xyz", new IllegalStateException("hello"))
+ logger."$testMethod"("xyz: {}", 123, new IllegalStateException("hello"))
} else {
- logger."$testMethod"("xyz")
+ logger."$testMethod"("xyz: {}", 123)
}
}
@@ -52,7 +52,7 @@ class Log4j2Test extends AgentInstrumentationSpecification {
assertThat(logs).hasSize(1)
})
def log = logs.get(0)
- assertThat(log.getBody().asString()).isEqualTo("xyz")
+ assertThat(log.getBody().asString()).isEqualTo("xyz: 123")
assertThat(log.getInstrumentationLibraryInfo().getName()).isEqualTo("abc")
assertThat(log.getSeverity()).isEqualTo(severity)
assertThat(log.getSeverityText()).isEqualTo(severityText)
@@ -101,7 +101,7 @@ class Log4j2Test extends AgentInstrumentationSpecification {
ThreadContext.put("key1", "val1")
ThreadContext.put("key2", "val2")
try {
- logger.info("xyz")
+ logger.info("xyz: {}", 123)
} finally {
ThreadContext.clearMap()
}
@@ -114,7 +114,7 @@ class Log4j2Test extends AgentInstrumentationSpecification {
assertThat(logs).hasSize(1)
})
def log = logs.get(0)
- assertThat(log.getBody().asString()).isEqualTo("xyz")
+ assertThat(log.getBody().asString()).isEqualTo("xyz: 123")
assertThat(log.getInstrumentationLibraryInfo().getName()).isEqualTo("abc")
assertThat(log.getSeverity()).isEqualTo(Severity.INFO)
assertThat(log.getSeverityText()).isEqualTo("INFO")

MODIFY
instrumentation/logback/logback-appender-1.0/javaagent/src/test/groovy/LogbackTest.groovy
instrumentation/logback/logback-appender-1.0/javaagent/src/test/groovy/LogbackTest.groovy
@@ -26,16 +26,16 @@ class LogbackTest extends AgentInstrumentationSpecification {
if (parent) {
runWithSpan("parent") {
if (exception) {
- logger."$testMethod"("xyz", new IllegalStateException("hello"))
+ logger."$testMethod"("xyz: {}", 123, new IllegalStateException("hello"))
} else {
- logger."$testMethod"("xyz")
+ logger."$testMethod"("xyz: {}", 123)
}
}
} else {
if (exception) {
- logger."$testMethod"("xyz", new IllegalStateException("hello"))
+ logger."$testMethod"("xyz: {}", 123, new IllegalStateException("hello"))
} else {
- logger."$testMethod"("xyz")
+ logger."$testMethod"("xyz: {}", 123)
}
}
@@ -51,7 +51,7 @@ class LogbackTest extends AgentInstrumentationSpecification {
assertThat(logs).hasSize(1)
})
def log = logs.get(0)
- assertThat(log.getBody().asString()).isEqualTo("xyz")
+ assertThat(log.getBody().asString()).isEqualTo("xyz: 123")
assertThat(log.getInstrumentationLibraryInfo().getName()).isEqualTo(loggerName)
assertThat(log.getSeverity()).isEqualTo(severity)
assertThat(log.getSeverityText()).isEqualTo(severityText)
@@ -106,7 +106,7 @@ class LogbackTest extends AgentInstrumentationSpecification {
MDC.put("key1", "val1")
MDC.put("key2", "val2")
try {
- abcLogger.info("xyz")
+ abcLogger.info("xyz: {}", 123)
} finally {
MDC.clear()
}
@@ -119,7 +119,7 @@ class LogbackTest extends AgentInstrumentationSpecification {
assertThat(logs).hasSize(1)
})
def log = logs.get(0)
- assertThat(log.getBody().asString()).isEqualTo("xyz")
+ assertThat(log.getBody().asString()).isEqualTo("xyz: 123")
assertThat(log.getInstrumentationLibraryInfo().getName()).isEqualTo("abc")
assertThat(log.getSeverity()).isEqualTo(Severity.INFO)
assertThat(log.getSeverityText()).isEqualTo("INFO")

MODIFY
instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal/LoggingEventMapper.java
instrumentation/logback/logback-appender-1.0/library/src/main/java/io/opentelemetry/instrumentation/logback/appender/v1_0/internal/LoggingEventMapper.java
@@ -82,7 +82,7 @@ public final class LoggingEventMapper {
*/
private void mapLoggingEvent(LogBuilder builder, ILoggingEvent loggingEvent) {
// message
- String message = loggingEvent.getMessage();
+ String message = loggingEvent.getFormattedMessage();
if (message != null) {
builder.setBody(message);
}

Capture logback formatted message (#5497)