Skip to content

The Java agent did not detect the database name #19024

Description

@hwxy233

Describe the bug

Hi, I find when a Java application connects to Microsoft SQL Server using the database= property in the JDBC URL, the OpenTelemetry Java agent fails to populate the db.name span attribute. The agent only appears to recognize the databaseName= property.

Both forms are valid and equivalent according to the Microsoft JDBC Driver for SQL Server documentation, which explicitly shows database=Adventure Works in its connection URL examples doc.

For example:
jdbc:sqlserver://xxx:1433;databaseName=xxx;db.name is correctly set to xxx
jdbc:sqlserver://xxx:1433;database=xxx;db.name is missing/empty

This means any application that uses the shorter database= form (which is perfectly functional for the driver and commonly seen in the wild) will lose the database name from its JDBC spans, reducing the usefulness of the telemetry.

It would be great if the agent could treat database as a fallback alias for databaseName when parsing SQL Server connection URLs — i.e., when databaseName is not present, try database as the source of db.name.

Steps to reproduce

  1. Start any Java application that connects to MSSQL via JDBC with the OpenTelemetry Java agent attached, using the database= form of the connection URL:
    java -javaagent:/path/to/opentelemetry-javaagent.jar \
         -Dotel.traces.exporter=console \
         -jar your-app.jar
    Application code (or datasource config):
    String url = "jdbc:sqlserver://xxx:1433;database=xxx;user=xxx;password=xxx;";
    Connection conn = DriverManager.getConnection(url);
    // execute any query, e.g. SELECT 1
  2. Trigger a JDBC query so that a DB client span is produced.
  3. Inspect the exported span for the JDBC call.
    For comparison, repeat the same steps with databaseName=xxx in the URL — in that case db.name is populated correctly.
  • Agent version: 2.27.0
  • Driver: com.microsoft.sqlserver:mssql-jdbc (reproducible across recent 12.x versions)
  • Database: Microsoft SQL Server
    A minimal reproducer is straightforward to assemble from the snippet above; I can provide a ready-to-run repo if needed.

Expected behavior

For the URL jdbc:sqlserver://xxx:1433;database=xxx;, the JDBC client span should carry db.name = xxx, the same value produced when using databaseName=xxx. Since database is a documented, valid property of the Microsoft SQL Server JDBC driver, the agent's URL parser should honor it (at least as a fallback when databaseName is absent).

Actual behavior

For the URL jdbc:sqlserver://xxx:1433;database=xxx;, the JDBC client span has no db.name attribute (it is empty/missing), while other attributes such as db.system=sqlserver, server.address, and server.port are set correctly. Switching the same connection string to databaseName=xxx immediately produces the expected db.name = xxx, confirming the parser only recognizes the databaseName form.

Javaagent or library instrumentation version

Agent version: 2.27.0

Environment

{
  "resource_attr:os.description": "Linux 4.18.0-553.129.1.el8_10.x86_64",
  "resource_attr:process.runtime.description": "Red Hat, Inc. OpenJDK 64-Bit Server VM 17.0.18+8-LTS",
  "resource_attr:telemetry.distro.version": "2.27.0",
  "resource_attr:telemetry.sdk.language": "java",
  "resource_attr:telemetry.sdk.name": "opentelemetry",
  "resource_attr:telemetry.sdk.version": "1.61.0",
  "scope_name": "io.opentelemetry.lettuce-5.1",
  "scope_version": "2.27.0-alpha"
}

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageNew issue that requires triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions