diff --git a/instrumentation/log4j/log4j-appender-2.16/library/README.md b/instrumentation/log4j/log4j-appender-2.16/library/README.md new file mode 100644 index 000000000000..13fd638fb9d1 --- /dev/null +++ b/instrumentation/log4j/log4j-appender-2.16/library/README.md @@ -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 + + + io.opentelemetry.instrumentation + opentelemetry-log4j-appender-2.16 + OPENTELEMETRY_VERSION + runtime + + + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-sdk-appender + OPENTELEMETRY_VERSION + + +``` + +**Gradle** + +```kotlin +dependencies { + runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-appender-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 `log4j2.xml` configuration: + +```xml + + + + + + + + + + + + + + + +``` + +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`. diff --git a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.16/library-autoconfigure/README.md b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.16/library-autoconfigure/README.md index 968ef07e5140..43f6ea4e13da 100644 --- a/instrumentation/log4j/log4j-context-data/log4j-context-data-2.16/library-autoconfigure/README.md +++ b/instrumentation/log4j/log4j-context-data/log4j-context-data-2.16/library-autoconfigure/README.md @@ -1,9 +1,15 @@ -# Log4j 2 Integration +# Log4j2 Autoconfigure Integration -This module provides Log4j2 extensions related to OpenTelemetry. +This module provides a Log4j2 `ContextDataProvider` that injects trace context from active spans +into log context. + +## Usage To use it, add the module to your application's runtime classpath. +Replace `OPENTELEMETRY_VERSION` with the latest +stable [release](https://search.maven.org/search?q=g:io.opentelemetry.instrumentation). + **Maven** ```xml @@ -11,8 +17,8 @@ To use it, add the module to your application's runtime classpath. io.opentelemetry.instrumentation - opentelemetry-log4j-2.13.2 - 0.17.0-alpha + opentelemetry-log4j-context-data-2.16-autoconfigure + OPENTELEMETRY_VERSION runtime @@ -22,12 +28,10 @@ To use it, add the module to your application's runtime classpath. ```kotlin dependencies { - runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-2.13.2:0.17.0-alpha") + runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-context-data-2.16-autoconfigure:OPENTELEMETRY_VERSION") } ``` -## OpenTelemetry Context Data Provider - `OpenTelemetryContextDataProvider` implements the Log4j2 `ContextDataProvider` SPI, and injects the trace ID and span ID from an active span into Log4j's [context data](https://logging.apache.org/log4j/2.x/manual/thread-context.html). @@ -63,51 +67,3 @@ You can use these keys when defining an appender in your `log4j.xml` configurati ``` - -## OpenTelemetry Appender - -`OpenTelemetryAppender` is a -Log4j2 [appender](https://logging.apache.org/log4j/2.x/manual/appenders.html) that can be used to -forward log events to -the [OpenTelemetry Log SDK](https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/logs) -. - -The following demonstrates how you might configure the appender in your `log4j.xml` configuration: - -```xml - - - - - - - - - - - - - - - -``` - -Next, associate the `OpenTelemetryAppender` with a `SdkLogEmitterProvider` in your application: - -``` -SdkLogEmitterProvider logEmitterProvider = - SdkLogEmitterProvider.builder() - .setResource(Resource.create(...)) - .addLogProcessor(...) - .build(); -OpenTelemetryLog4j.initialize(logEmitterProvider); -``` - -**Note:** In order to initialize the `OpenTelemetryAppender` your application must depend on the -OpenTelemetry log sdk (`io.opentelemetry:opentelemetry-sdk-logs`). - -In this example Log4j2 logs will be sent to both the console appender and -the `OpenTelemetryAppender`, which will drop the logs until `OpenTelemetryLog4j.initialize(..)` is -called. Once initialized, logs will be emitted to a `LogEmitter` obtained from -the `SdkLogEmitterProvider`.