elastic / elastic/apm-agent-java
APM agent breaks log.error when using StructuredLogEncoder with ecs format
- Lingua principale
- Java
- Stelle
- 593
- Fork
- 337
- Merge medio
- 1g 13h
- PR unite (30g)
- 25
Descrizione
## Describe the bug
We are using the version 1.55.5 with experimental Spring Boot 4 support. Since the update we have problems with `log.error` in SLF4J. This is the logback-spring.xml configuration:
```xml
ecs
```
When using the apm agent we are seeing this in the logs instead of the real error log:
07:18:54,651 |-ERROR in ch.qos.logback.core.ConsoleAppender[CONSOLE] - Appender [CONSOLE] failed to append. java.lang.IllegalStateException: The name 'error' has already been written
According to my research, this happens if the JSON log already contains a field with the same name, in this case `error`. Logback uses the field `error` for a complex object that contains `error.message` and `error.stack_trace`. This is also documented in the [Elastic Common Schema](https://www.elastic.co/docs/reference/ecs/ecs-error).
## Steps to reproduce
Use the org.springframework.boot.logging.logback.StructuredLogEncoder with ecs format as described and call `org.slf4j.Logger#error(java.lang.String, java.lang.Throwable)`.
## Expected behavior
No exception during logging, but a well-formed JSON log containing the error.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo il problema con lo StructuredLogEncoder di logback-spring.xml configurato per ecs e una chiamata a Logger#error(String, Throwable). Esamina l’interazione tra l’APM agent, StructuredLogEncoder e il campo error descritta nel report. Il lavoro è completo quando il logging produce JSON ben formato senza un’eccezione dell’appender.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, spring-boot
- Ambito
- backend, observability-sre
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 58/100