Skip to content

feat: add support for capture_parameters to Psycopg2Instrumentor#4212

Open
gregoiredx wants to merge 1 commit intoopen-telemetry:mainfrom
gregoiredx:pyscopg2-capture-parameters
Open

feat: add support for capture_parameters to Psycopg2Instrumentor#4212
gregoiredx wants to merge 1 commit 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.

@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Feb 26, 2026
@gregoiredx gregoiredx force-pushed the pyscopg2-capture-parameters branch 4 times, most recently from 0a49404 to 70c5c82 Compare March 3, 2026 17:32
@gregoiredx
Copy link
Author

gregoiredx commented Mar 3, 2026

@tammy-baylis-swi, thanks for your review.

I finally found time to get back on this PR.
I applied the linting and added the tests you suggested.

Can you relaunch the CI and potentially merge after that, please?

Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi 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 fixes! Lgtm as a feature that matches current psycopg (3) instrumentor.

@tammy-baylis-swi tammy-baylis-swi moved this from Reviewed PRs that need fixes to Approved PRs in Python PR digest Mar 4, 2026
@gregoiredx gregoiredx force-pushed the pyscopg2-capture-parameters branch from 70c5c82 to 56fccc4 Compare March 6, 2026 15:02
@gregoiredx
Copy link
Author

@tammy-baylis-swi I just rebased to resolve the conflicts in the CHANGELOG.md following the release (which I sadly missed 😅)

Can we try and merge this, please?

@tammy-baylis-swi
Copy link
Contributor

Thanks again @gregoiredx !

I've approved but this requires @open-telemetry/opentelemetry-python-contrib-maintainers to also review then merge.

@gregoiredx
Copy link
Author

Thanks again @gregoiredx !

I've approved but this requires @open-telemetry/opentelemetry-python-contrib-maintainers to also review then merge.

I thought you were one, sorry. I'll wait

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

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

3 participants