open-telemetry / open-telemetry/opentelemetry-java-instrumentation
Structured logging in Slf4J not honoured in log entry Body
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1.2k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 214
Description
Hi all,
I apologize in advance if this is a known issue, but I could not find any entry clearly describing this issue.
Describe the bug
When a Java application using Slf4j is instrumented, the logs are sent to the OpenTelemetry Collector.
Slf4j provides support for structured logging:
logger.atInfo()
.addKeyValue("a_key", "a_value)
.addKeyValue("another_key", "another_value)
.log();
This should result in a log entry with the following Body:
{
"a_key": "a_value",
"another_key": "another_value"
}
While the log entry is sent to the OpenTelemetry Collector and all the attributes are correctly attached, the Body in the log entry is empty.
Steps to reproduce
Java App dependencies
dependencies {
implementation("org.slf4j:slf4j-api:2.0.13")
runtimeOnly("ch.qos.logback:logback-classic:1.5.6")
}
Java App code
Logger logger = LoggerFactory.getLogger(App.class);
logger.atInfo()
.addKeyValue("a_key", "a_value)
.addKeyValue("another_key", "another_value)
.log();
Auto Instrumentation
Image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:1.33.5
Inspecting Logs
Log entries sent by the application are intercepted at the level of the Collector and printed using a debug exporter.
What did you expect to see?
Log entries streamed from the app should contain a body consisting of a json object containing the logged fields:
{
"a_key": "a_value",
"another_key": "another_value"
}
What did you see instead?
The Body field for the log entry is empty.
The fields to not appear anywhere in the logs.
What version and what artifacts are you using?
Auto instrumentation Image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:1.33.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided SLF4J 2.0.13 and Logback dependencies and the Java auto-instrumentation image. Inspect the logs at the Collector's debug exporter and trace how the structured fields are handled; done means the log entry Body contains the key-value pairs as a JSON object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100