Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate db.statement when Composable passed to cursor.execute #3117

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

oparaskos
Copy link

Description

We were getting warnings such as

[...] WARNING: opentelemetry.attributes: Invalid type Composed for attribute 'db.statement' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

We're using aiopg and its autoinstrumentor db.statement isn't being populated because we're passing in the SQL() object
the psycopg2 cursor wrapper supports this but the aiopg only seems to support string and bytes.

This adds support for psycopg.sql.Composable objects, by calling as_string() which is similar to the solution in the psycopg autoinstrumentors.

Fixes # (issue not created)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • tox -e py312-test-instrumentation-aiopg

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

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

Copy link

linux-foundation-easycla bot commented Dec 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@oparaskos oparaskos force-pushed the feat-aiopg-composable-db-statement branch from f26017b to 9dc41cb Compare December 18, 2024 17:17
@oparaskos oparaskos force-pushed the feat-aiopg-composable-db-statement branch from 9dc41cb to b51d9fc Compare December 18, 2024 17:20
@oparaskos oparaskos marked this pull request as draft December 20, 2024 11:08
@xrmx
Copy link
Contributor

xrmx commented Dec 23, 2024

@oparaskos Hello, thanks for the PR, any reason it's in draft?

@oparaskos
Copy link
Author

@oparaskos Hello, thanks for the PR, any reason it's in draft?

In the GitHub app it looked like there was a failing pipeline stage, so I marked it as draft til I could look at it. Though now it looks like there isn't a failing step so I don't know what happened there.
I also still haven't had a chance to test it in a real scenario beyond the unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants