Skip to content

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

@linux-foundation-easycla
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.

@lucianoVideam
Copy link

Hello, we are experiencing the same issue with psycopg using psycopg.sql.SQL format for the statement.

async def check_db_working(conn: psycopg.AsyncConnection) -> bool:
    async with conn.cursor() as cursor:
        query_str = sql.SQL('SELECT 1')
        await cursor.execute(query_str)
        [...]

it would be possible to avoit getting the warngin and parse the sb.statement also in psycopg.sql.SQL format? we are using the opentelemetry-instrumentation-psycopg module.

Thanks.

Current warning: Invalid type SQL for attribute 'db.statement' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

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.

3 participants