Skip to content

Implement db.query.parameter.<key> in the dbapi base#4798

Open
ocelotl wants to merge 1 commit into
open-telemetry:mainfrom
ocelotl:issue_4788_db_query_parameter
Open

Implement db.query.parameter.<key> in the dbapi base#4798
ocelotl wants to merge 1 commit into
open-telemetry:mainfrom
ocelotl:issue_4788_db_query_parameter

Conversation

@ocelotl

@ocelotl ocelotl commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a shared _set_db_query_parameters helper and wires it into the DB-API CursorTracer so that, when capture_parameters is enabled, prepared statement parameters are recorded as db.query.parameter.<key> (keyed by name for named params, 0-based index for positional). The legacy db.statement.parameters blob is now emitted only under the old semconv; the standard attribute is emitted under the new database semconv. Parameters are not captured on batch operations (executemany). This is the foundation every DB-API-based instrumentation inherits.

Part of #4787. Fixes #4788.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests: dbapi suite 62 passed; _semconv suite 67 passed.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Add a shared _set_db_query_parameters helper that emits one
db.query.parameter.<key> attribute per prepared-statement parameter,
keyed by name for named parameters and by 0-based index for positional
parameters, with values stringified.

Wire it into the dbapi CursorTracer so that, when capture_parameters is
enabled, the legacy db.statement.parameters attribute is reported only in
the old semconv while db.query.parameter.<key> is reported in the new
(stable) database semconv. Parameters are not captured on batch
operations (executemany), per the semantic conventions.
@ocelotl ocelotl marked this pull request as ready for review July 13, 2026 01:19
@ocelotl ocelotl requested a review from a team as a code owner July 13, 2026 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

opentelemetry-instrumentation-dbapi: capture db.query.parameter.<key>

1 participant