---
id: traceid-spanid-injection-into-logs-configuration
title: Java TraceId and SpanId Injection into Logs Configuration
sidebar_label: TraceId and SpanId Injection into Logs Configuration
description: Correlate traces with logs by injecting trace IDs and span IDs into Java applications using OpenTelemetry instrumentation in Sumo Logic.
slug: /help/docs/apm/traces/get-started-transaction-tracing/opentelemetry-instrumentation/java/traceid-spanid-injection-into-logs-configuration/
canonical: https://www.sumologic.com/help/docs/apm/traces/get-started-transaction-tracing/opentelemetry-instrumentation/java/traceid-spanid-injection-into-logs-configuration/
---
This page describes how to configure **spanId** and **traceId** data injection into user logs in Java applications.
## Log4j instrumentation
1. Add instrumented **Log4j2** and **OpenTelemetry-api** libraries into the project dependencies:
* Maven projects
```xml
io.opentelemetry.instrumentation
opentelemetry-log4j-context-data-2.17-autoconfigure
2.6.0-alpha
runtime
```
* Gradle projects
```gradle
dependencies {
runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-log4j-context-data-2.17-autoconfigure:2.6.0-alpha")
}
```
1. Update the **log4j2.xml** configuration file, typically stored in **resources** directory, with `traceId`, `spanId`, and `sampled` keys. The following is an example configuration.
```xml
```
## Logback instrumentation
1. Add instrumented **logback** library into the project dependencies:
* Maven projects
```xml
io.opentelemetry.instrumentation
opentelemetry-logback-mdc-1.0
2.6.0-alpha
runtime
```
* Gradle projects
```gradle
dependencies {
runtimeOnly("io.opentelemetry.instrumentation:opentelemetry-logback-mdc-1.0:2.6.0-alpha")
}
```
1. Update the **logback.xml** configuration file, typically stored in the **resources** directory, with `traceId`, `spanId`, and `sampled` keys. The following is an example configuration.
```xml
```
:::note
For more details, refer to the [Logger MDC auto-instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/release/v2.6.x/docs/logger-mdc-instrumentation.md).
:::