Skip to content

Commit

Permalink
feat(javaagent-log-appender): transfer appender settings to system pr…
Browse files Browse the repository at this point in the history
…operties

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.
  • Loading branch information
smoke committed Oct 11, 2024
1 parent b40a708 commit b4beac8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
16 changes: 11 additions & 5 deletions javaagent-log-appender/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -49,5 +45,15 @@ application {
tasks.named<JavaExec>("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"
)
}
}
6 changes: 2 additions & 4 deletions javaagent-log-appender/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.appender.v2_17">
<Configuration status="WARN">
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="log4j2: %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<OpenTelemetry name="OpenTelemetryAppender" captureMapMessageAttributes="true" captureExperimentalAttributes="true"/>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="OpenTelemetryAppender" />
<AppenderRef ref="ConsoleAppender" />
</Root>
</Loggers>
</Configuration>
</Configuration>
8 changes: 1 addition & 7 deletions javaagent-log-appender/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
</pattern>
</encoder>
</appender>
<appender name="OpenTelemetry"
class="io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender">
<captureExperimentalAttributes>true</captureExperimentalAttributes>
<captureKeyValuePairAttributes>true</captureKeyValuePairAttributes>
</appender>
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="OpenTelemetry"/>
</root>
</configuration>
</configuration>

0 comments on commit b4beac8

Please sign in to comment.