Skip to content

Set database operation attribute in asyncpg #4961

Open

Description

Problem Statement

Attach attributes to spans for SQL statements according to getsentry/sentry-docs#15194.

Solution Brainstorm

Filter on the operation and add the attribute value.

Activity

  1. linear commented on Oct 20, 2025

    @linear
  2. added and removed on Mar 24, 2026
  3. kbj804 commented on Nov 24, 2026

    @kbj804

    Hi! I'd like to work on this if it's still open. I use the asyncpg integration at work.

    I looked into how asyncpg sends transaction statements. Transaction.start(), commit() and rollback() call Connection.execute, which _wrap_execute already records as a span. The statements are:

    • BEGIN; / BEGIN ISOLATION LEVEL SERIALIZABLE READ ONLY; (with modifiers)
    • COMMIT;, ROLLBACK;
    • SAVEPOINT <id>;, RELEASE SAVEPOINT <id>;, ROLLBACK TO <id>;

    My plan is to set db.operation.name on these spans in _wrap_execute, following the spec in getsentry/sentry-docs#15194 (statement name without arguments, BEGIN for BEGIN with modifiers), similar to what the Django integration does for commit/rollback spans. I'll add tests for each statement.

    Two questions before I start:

    1. Should this cover only transaction statements, or every query (SELECT, INSERT, ...)?
    2. asyncpg sends ROLLBACK TO <id> without the SAVEPOINT keyword. Should the operation name be ROLLBACK TO SAVEPOINT to match the spec, or ROLLBACK TO as sent?

    (I use a translator for English, so sorry if anything reads awkwardly.)

  4. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions