From b4beac8796bd37504e801f5e5fc941e4bf9b29ac Mon Sep 17 00:00:00 2001 From: Radoslav Kirilov Date: Fri, 11 Oct 2024 10:56:38 +0300 Subject: [PATCH] feat(javaagent-log-appender): transfer appender settings to system properties JavaAgent instrumentation of Log Appenders does not respect logger configs like `log4j2.xml` or `logback.xml` as it uses direct patching of loggers to do the same and no appenders set in the loggers. --- javaagent-log-appender/build.gradle.kts | 16 +++++++++++----- .../src/main/resources/log4j2.xml | 6 ++---- .../src/main/resources/logback.xml | 8 +------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/javaagent-log-appender/build.gradle.kts b/javaagent-log-appender/build.gradle.kts index b4f347e0a..052e191ff 100644 --- a/javaagent-log-appender/build.gradle.kts +++ b/javaagent-log-appender/build.gradle.kts @@ -33,11 +33,7 @@ dependencies { implementation("io.opentelemetry:opentelemetry-api") implementation("io.opentelemetry.semconv:opentelemetry-semconv") - // OpenTelemetry log4j / logback appenders - implementation("io.opentelemetry.instrumentation:opentelemetry-log4j-appender-2.17") - implementation("io.opentelemetry.instrumentation:opentelemetry-logback-appender-1.0") - - // OpenTelemetry JavaAgent + // OpenTelemetry JavaAgent, this brings its own standalone log4j / logback appenders agent("io.opentelemetry.javaagent:opentelemetry-javaagent:2.8.0") } @@ -49,5 +45,15 @@ application { tasks.named("run") { doFirst { jvmArgs("-javaagent:${agent.singleFile}") + // log4j-appender properties + jvmArgs( + "-Dotel.instrumentation.log4j-appender.experimental.capture-map-message-attributes=true", + "-Dotel.instrumentation.log4j-appender.experimental-log-attributes=true" + ) + // logback-appender properties + jvmArgs( + "-Dotel.instrumentation.logback-appender.experimental-log-attributes=true", + "-Dotel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes=true" + ) } } diff --git a/javaagent-log-appender/src/main/resources/log4j2.xml b/javaagent-log-appender/src/main/resources/log4j2.xml index 3601b9844..8c91e02f0 100644 --- a/javaagent-log-appender/src/main/resources/log4j2.xml +++ b/javaagent-log-appender/src/main/resources/log4j2.xml @@ -1,15 +1,13 @@ - + - - - \ No newline at end of file + diff --git a/javaagent-log-appender/src/main/resources/logback.xml b/javaagent-log-appender/src/main/resources/logback.xml index a14aeb7fa..348cb1f1a 100644 --- a/javaagent-log-appender/src/main/resources/logback.xml +++ b/javaagent-log-appender/src/main/resources/logback.xml @@ -7,13 +7,7 @@ - - true - true - - - \ No newline at end of file +