Skip to content

Commit

Permalink
Update MDC docs to reflect log spec naming (open-telemetry#2303)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 17, 2021
1 parent 427bd5f commit 54e9cd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions docs/logger-mdc-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ event's MDC copy:
(same as `Span.current().getSpanContext().isSampled()`).

Those three pieces of information can be included in log statements produced by the logging library
by specifying them in the pattern/format. Example for Spring Boot configuration (which uses logback):
by specifying them in the pattern/format. Example for Spring Boot configuration (which uses
logback):

```properties
logging.pattern.console = %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg t:%X{traceId} s:%X{spanId} %n
logging.pattern.console = %d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg trace_id=%X{traceId} span_id=%X{spanId} %n
```

This way any services or tools that parse the application logs can correlate traces/spans with log statements.
This way any services or tools that parse the application logs can correlate traces/spans with log
statements.

## Supported logging libraries

Expand Down
9 changes: 6 additions & 3 deletions instrumentation/log4j/log4j-2.13.2/library/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# 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](https://logging.apache.org/log4j/2.x/manual/thread-context.html).
mounted span into
Log4j's [context data](https://logging.apache.org/log4j/2.x/manual/thread-context.html).

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

**Maven**

```xml

<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
Expand Down Expand Up @@ -40,12 +42,13 @@ You can use these keys when defining an appender in your `log4j.xml` configurati
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{traceId} spanId: %X{spanId} - %msg%n" />
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} trace_id=%X{traceId} span_id=%X{spanId} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root>
<AppenderRef ref="Console" level="All" />
<AppenderRef ref="Console" level="All"/>
</Root>
</Loggers>
</Configuration>
Expand Down
5 changes: 3 additions & 2 deletions instrumentation/logback/logback-1.0/library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ To use it, add the module to your application's runtime classpath and add the ap
**Maven**

```xml

<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
Expand All @@ -34,13 +35,13 @@ dependencies {
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %X{traceId} %X{spanId} %msg%n</pattern>
<pattern>%d{HH:mm:ss.SSS} trace_id=%X{traceId} span_id=%X{spanId} %msg%n</pattern>
</encoder>
</appender>

<!-- Just wrap your logging appender, for example ConsoleAppender, with OpenTelemetryAppender -->
<appender name="OTEL" class="io.opentelemetry.instrumentation.logback.v1_0.OpenTelemetryAppender">
<appender-ref ref="CONSOLE" />
<appender-ref ref="CONSOLE"/>
</appender>
...
</configuration>
Expand Down

0 comments on commit 54e9cd5

Please sign in to comment.