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

Offen Anfängerfreundlich
#4,616 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@RaphaelFakhri arbeitet bereits daran.

Seit 03.11.2026.

  • #4617 von @RaphaelFakhri — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
70/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
observability

Rechercherichtung

Das Issue nennt ConnectionMetaData.parse und zeigt PostgreSQL- und H2-URLs mit mehreren Hosts, nennt aber keine Quell- oder Testdateien. Suche zunächst den Code für das Parsen von URLs und die vorhandenen Tests für MySQL und MariaDB mit mehreren Hosts. Prüfe anschließend, wie Hosts und Ports in PostgreSQL und H2 geparst werden. Als abgeschlossen gilt die Arbeit, wenn für die Beispiele im Issue der erste Host und sein Port angegeben werden und Tests beide URL-Formate abdecken.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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)
Vorherrschende Sprache
Java
Sterne
592
Forks
340
Ø Merge
2 T. 17 Std.
Gemergte PRs (30 T.)
17

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus elastic/apm-agent-java

Alle Issues in elastic/apm-agent-java

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.