Skip to content

Commit ec6b8fa

Browse files
committed
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.
1 parent b40a708 commit ec6b8fa

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

javaagent-log-appender/build.gradle.kts

+10
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,15 @@ application {
4949
tasks.named<JavaExec>("run") {
5050
doFirst {
5151
jvmArgs("-javaagent:${agent.singleFile}")
52+
// log4j-appender properties
53+
jvmArgs(
54+
"-Dotel.instrumentation.log4j-appender.experimental.capture-map-message-attributes=true",
55+
"-Dotel.instrumentation.log4j-appender.experimental-log-attributes=true"
56+
)
57+
// logback-appender properties
58+
jvmArgs(
59+
"-Dotel.instrumentation.logback-appender.experimental-log-attributes=true",
60+
"-Dotel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes=true"
61+
)
5262
}
5363
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.appender.v2_17">
2+
<Configuration status="WARN">
33
<Appenders>
44
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
55
<PatternLayout pattern="log4j2: %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
66
</Console>
7-
<OpenTelemetry name="OpenTelemetryAppender" captureMapMessageAttributes="true" captureExperimentalAttributes="true"/>
87
</Appenders>
98
<Loggers>
109
<Root level="info">
11-
<AppenderRef ref="OpenTelemetryAppender" />
1210
<AppenderRef ref="ConsoleAppender" />
1311
</Root>
1412
</Loggers>
15-
</Configuration>
13+
</Configuration>

javaagent-log-appender/src/main/resources/logback.xml

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
</pattern>
88
</encoder>
99
</appender>
10-
<appender name="OpenTelemetry"
11-
class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
12-
<captureExperimentalAttributes>true</captureExperimentalAttributes>
13-
<captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
14-
</appender>
1510
<root level="INFO">
1611
<appender-ref ref="console"/>
17-
<appender-ref ref="OpenTelemetry"/>
1812
</root>
19-
</configuration>
13+
</configuration>

0 commit comments

Comments
 (0)