Skip to content

Capture TortoiseORM query parameters with new DB semconv attributes - #4907

Open
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-4795-opentelemetry-instrumentation-tortoiseor
Open

Capture TortoiseORM query parameters with new DB semconv attributes#4907
saisharan0103 wants to merge 1 commit into
open-telemetry:mainfrom
saisharan0103:mergepath/issue-4795-opentelemetry-instrumentation-tortoiseor

Conversation

@saisharan0103

Copy link
Copy Markdown

Fixes #4795.

TortoiseORM instrumentation already resolves the database semantic convention opt-in mode for core DB attributes, but parameter capture still always wrote the legacy db.statement.parameters blob when capture_parameters=True. _hydrate_span_from_args received all arguments after the SQL query as a tuple and stringified that tuple without checking semconv mode, without converting positional parameters to db.query.parameter.<index> attributes for the new semconv, and without suppressing parameter capture for execute_many batch operations.

This change imports _set_db_query_parameters and _report_old, gates legacy db.statement.parameters on old semconv reporting, and calls _set_db_query_parameters for new semconv reporting. Non-batch Tortoise parameters are normalized into a mapping before calling the helper: named mappings keep their keys, and positional sequences use zero-based string indexes. The legacy blob value remains unchanged in old/default and database/dup modes.

_do_execute now passes an is_batch flag based on the wrapped function name so execute_many spans skip both legacy and new parameter attributes.

Modified files:

  • instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py
  • instrumentation/opentelemetry-instrumentation-tortoiseorm/tests/test_tortoiseorm_instrumentation.py

ruff check instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py instrumentation/opentelemetry-instrumentation-tortoiseorm/tests/test_tortoiseorm_instrumentation.py reports no new findings on the changed files.
Ran pytest -x locally with no new failures.

…toiseorm`: capture `db.query.parameter.<key>`

Closes open-telemetry#4795
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (17c8f9d) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

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-tortoiseorm: capture db.query.parameter.<key>

1 participant