JDBC spans report the whole host list as the host for multi-host connection URLs

未关闭 适合新手
#4,616 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@RaphaelFakhri 已经在做这个了。

开始于 2026年11月3日。

  • #4617 来自 @RaphaelFakhri —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
70/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
observability

调研方向

Issue 提到了 ConnectionMetaData.parse,并展示了包含多个主机的 PostgreSQL 和 H2 URL,但没有指出源文件或测试文件。先定位 URL 解析代码以及现有的 MySQL 和 MariaDB 多主机测试,然后检查 PostgreSQL 和 H2 的主机与端口是如何解析的。完成标准是:为 issue 中的示例报告第一个主机及其端口,并且测试覆盖两种 URL 格式。

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

描述

agent-java community triage

The JDBC plugin parses the connection URL that DatabaseMetaData.getURL() returns to fill the destination and database fields of JDBC spans. When the URL lists more than one host, as in PostgreSQL failover/load balancing URLs or H2 cluster URLs, the parser treats the full comma-separated host list as a single host.

For example, jdbc:postgresql://myhost1:666,myhost2:777/database produces:

  • host: myhost1:666,myhost2:777 (expected myhost1)
  • port: 5432, the default (expected 666)

jdbc:h2:tcp://server1:9101,server2:9102/~/sample produces host server1:9101,server2:9102 and port -1.

The PostgreSQL driver returns the original connection URL from getURL(), so every span on such a connection reports this host and port in destination.address, destination.port and the service target. The MySQL and MariaDB parsers already use the first host of a multi-host URL.

Steps to reproduce

  1. Connect to PostgreSQL with a multi-host URL, for example jdbc:postgresql://host1:5432,host2:5432/db?targetServerType=primary.
  2. Run a query while a transaction is active.
  3. Inspect the JDBC span: destination.address is host1:5432,host2:5432.

The same result is visible in a unit test:

ConnectionMetaData metadata = ConnectionMetaData.parse("jdbc:postgresql://myhost1:666,myhost2:777/database").build();
metadata.getHost(); // "myhost1:666,myhost2:777"
metadata.getPort(); // 5432

Expected behavior

The agent uses the first host and its port, as it already does for MySQL and MariaDB multi-host URLs.

Environment

  • Agent version: current main (1.57.2-SNAPSHOT)
  • Drivers: PostgreSQL JDBC (multi-host URLs), H2 (cluster URLs)
主要语言
Java
星标
592
派生
340
平均合并
2 天 17 小时
30 天内合并 PR
17

环境准备

从这里开始

  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 摘要。