-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update log4j instrumentation docs (#4915)
* Update log4j instrumentation docs for 1.10.0 release * More log4j doc changes for 0.10.0 * Updates for #4937 * Fix log4j documentation * Update instrumentation/log4j/log4j-2.16/library/README.md Co-authored-by: jack-berg <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
instrumentation/log4j/log4j-appender-2.16/library/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Log4j2 Appender | ||
|
||
This module provides a Log4j2 [appender](https://logging.apache.org/log4j/2.x/manual/appenders.html) | ||
which forwards Log4j2 log events to | ||
the [OpenTelemetry Log SDK](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/logs). | ||
|
||
To use it, add the following modules to your application's classpath. | ||
|
||
Replace `OPENTELEMETRY_VERSION` with the latest | ||
stable [release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation). | ||
|
||
**Maven** | ||
|
||
```xml | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.opentelemetry.instrumentation</groupId> | ||
<artifactId>opentelemetry-log4j-2.16</artifactId> | ||
<version>OPENTELEMETRY_VERSION</version> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<!-- The SDK appender is required to configure the appender with the OpenTelemetry Log SDK --> | ||
<groupId>io.opentelemetry.instrumentation</groupId> | ||
<artifactId>opentelemetry-instrumentation-sdk-appender</artifactId> | ||
<version>OPENTELEMETRY_VERSION</version> | ||
</dependency> | ||
</dependencies> | ||
``` | ||
|
||
**Gradle** | ||
|
||
```kotlin | ||
dependencies { | ||
runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-2.16:OPENTELEMETRY_VERSION") | ||
// The SDK appender is required to configure the appender with the OpenTelemetry Log SDK | ||
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-sdk-appender:OPENTELEMETRY_VERSION") | ||
} | ||
``` | ||
|
||
The following demonstrates how you might configure the appender in your `log4j.xml` configuration: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.v2_16"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout | ||
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} traceId: %X{trace_id} spanId: %X{span_id} flags: %X{trace_flags} - %msg%n"/> | ||
</Console> | ||
<OpenTelemetry name="OpenTelemetryAppender"/> | ||
</Appenders> | ||
<Loggers> | ||
<Root> | ||
<AppenderRef ref="OpenTelemetryAppender" level="All"/> | ||
<AppenderRef ref="Console" level="All"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> | ||
``` | ||
|
||
Next, associate the `OpenTelemetryAppender` configured via `log4j2.xml` with | ||
a `SdkLogEmitterProvider` in your application: | ||
|
||
``` | ||
SdkLogEmitterProvider logEmitterProvider = | ||
SdkLogEmitterProvider.builder() | ||
.setResource(Resource.create(...)) | ||
.addLogProcessor(...) | ||
.build(); | ||
GlobalLogEmitterProvider.set(DelegatingLogEmitterProvider.from(logEmitterProvider)); | ||
``` | ||
|
||
In this example Log4j2 log events will be sent to both the console appender and | ||
the `OpenTelemetryAppender`, which will drop the logs until `GlobalLogEmitterProvider.set(..)` is | ||
called. Once initialized, logs will be emitted to a `LogEmitter` obtained from | ||
the `SdkLogEmitterProvider`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters