Skip to content

AsyncPGInstrumentor does not instrument prepared statements #4528

@aleksul

Description

@aleksul

Describe your environment

OS: macos 26
Python version: Python 3.12
Package version: 0.62b1

What happened?

opentelemetry-instrumentation-asyncpg patches Connection.execute(),
Connection.fetch(), Connection.fetchrow(), and Connection.fetchval().
It does not patch the equivalent methods on PreparedStatement
(PreparedStatement.execute(), .fetch(), .fetchrow(), .fetchval(),
.executemany()).

Any query that is executed through a PreparedStatement object is completely
invisible to the instrumentation - no span is emitted.

Steps to Reproduce

Use prepared statements, either directly or simply by using SQLAlchemy.

Here is a repository with MRE:
https://github.com/aleksul/asyncpg-opentelemetry-prepared-statments-mre

Expected Result

Expected that spans are emitted for prepared statements, similarly to how they are emitted for regular executions.

Actual Result

Spans are not emitted for prepared statements.

Additional context

No response

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions