Skip to content

Comments

feat: add support for capture_parameters to Psycopg2Instrumentor#4212

Open
gregoiredx wants to merge 3 commits intoopen-telemetry:mainfrom
gregoiredx:pyscopg2-capture-parameters
Open

feat: add support for capture_parameters to Psycopg2Instrumentor#4212
gregoiredx wants to merge 3 commits intoopen-telemetry:mainfrom
gregoiredx:pyscopg2-capture-parameters

Conversation

@gregoiredx
Copy link

@gregoiredx gregoiredx commented Feb 17, 2026

Description

Add support for dbapi capture_parameters param to Psycopg2Instrumentor.

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

I used a similar change on our stack, here is the result as seen in Grafana
image

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@gregoiredx gregoiredx force-pushed the pyscopg2-capture-parameters branch from dcf0111 to b63472b Compare February 18, 2026 10:51
@gregoiredx gregoiredx marked this pull request as ready for review February 18, 2026 11:17
@gregoiredx gregoiredx requested a review from a team as a code owner February 18, 2026 11:17
Copy link
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @gregoiredx 🚀

capture_parameters is already exposed in psycopg, aiopg, asyncpg, and tortoiseorm using the same underlying db.statement.parameters attribute, so this is consistent with the existing pattern in the repo.

However, it's worth noting the current attribute name (db.statement.parameters) and format (stringified tuple) diverges from the latest OTel semconv, which defines db.query.parameter.<key>] as individual per-parameter attributes (e.g. db.query.parameter.0, db.query.parameter.1, etc), with db.statement deprecated in favour of db.query. This PR doesn't introduce that problem though — it's pre-existing across all dbapi-based instrumentations.

Related issues:

@tammy-baylis-swi
Copy link
Contributor

Thanks for this! A few suggestions:

Please do tox -e lint-instrumentation-psycopg2 and commit format/style changes, since we're still using both pylint and ruff.

Please also update test_psycopg2_integration.py to assert span attributes with the memory exporter, similar to the psycopg(3) PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

3 participants