Anuraag Agrawal fe41885ee6 Switch to colon notation for dependencies. (#2994) 3 年之前
..
src f127a972dc Add 'trace_flags' to logging MDC (#2312) 4 年之前
README.md 0f32ed42a4 Instrument log4j to include bugfix of contextdataprovider mechanism. (#2407) 4 年之前
log4j-2.13.2-library.gradle fe41885ee6 Switch to colon notation for dependencies. (#2994) 3 年之前

README.md

Log4j 2 Integration

This module integrates instrumentation with Log4j 2 by injecting the trace ID and span ID from a mounted span into Log4j's context data.

Note: Depending on your application, you may run into a critical bug with Log4j 2.13.2. If log messages show a NullPointerException when adding this instrumentation, please update to 2.13.3 or higher. The only change between 2.13.2 and 2.13.3 is the fix to this issue.

To use it, just add the module to your application's runtime classpath.

Maven


<dependencies>
  <dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-log4j-2.13.2</artifactId>
    <version>0.17.0-alpha</version>
    <scope>runtime</scope>
  </dependency>
</dependencies>

Gradle

dependencies {
  runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-2.13.2:0.17.0-alpha")
}

Log4j will automatically pick up our integration and will have these keys added to the context when a log statement is made when a span is active.

  • trace_id
  • span_id
  • trace_flags

You can use these keys when defining an appender in your log4j.xml configuration, for example

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout
          pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root>
      <AppenderRef ref="Console" level="All"/>
    </Root>
  </Loggers>
</Configuration>