Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

APM agent breaks log.error when using StructuredLogEncoder with ecs format

未关闭
#4,470 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
java, spring-boot

调研方向

首先,使用为 ecs 配置的 logback-spring.xml 中的 StructuredLogEncoder,以及对 Logger#error(String, Throwable) 的调用来复现该问题。检查报告中描述的 APM agent、StructuredLogEncoder 和 error 字段之间的交互。完成的标准是日志记录能够生成格式良好的 JSON,且不会出现 appender 异常。

由索引模型根据 Issue 内容生成。

描述

agent-java community

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:

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  <encoder class="org.springframework.boot.logging.logback.StructuredLogEncoder">
    <format>ecs</format>
  </encoder>
</appender>

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.

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.

主要语言
Java
星标
593
派生
337
平均合并
1 天 3 小时
30 天内合并 PR
9

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

elastic/apm-agent-java 的其他 Issue

查看 elastic/apm-agent-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。