Skip to content

feat(sqlalchemy): Support span streaming - #6132

Merged
alexander-alderman-webb merged 25 commits into
masterfrom
webb/sqlalchemy/span-first
Apr 29, 2026
Merged

feat(sqlalchemy): Support span streaming#6132
alexander-alderman-webb merged 25 commits into
masterfrom
webb/sqlalchemy/span-first

Conversation

@alexander-alderman-webb

@alexander-alderman-webbalexander-alderman-webb commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Description

Adapt add_query_source() analogously to changes to add_http_request_source() in #6084.

Add record_sql_queries_supporting_streaming() based on record_sql_queries() so that the streaming path is not triggered for other ORM integrations until they support the streaming trace lifecycle. Once the last ORM integration supports span-streaming the functions can be de-duplicated.

Set <unknown SQL query> as the name when the description was previously None.

Adapting Tests

sed commands used for converting transaction context managers:

  • sed -i '' 's/start_transaction(name="test_transaction", sampled=True)/sentry_sdk.tracing.start_span(name="custom parent")/g'
  • sed -i '' 's/start_transaction(name="test_transaction", sampled=True)/sentry_sdk.traces.start_span(name="custom parent")/g'
  • sed -i '' 's/with start_transaction(name="foo")/sentry_sdk.traces.start_span(name="custom parent")/g'
  • sed -i '' 's/start_transaction(name="foo")/sentry_sdk.traces.start_span(name="custom parent")/g'
  • sed -i '' 's/start_transaction(name="test")/sentry_sdk.traces.start_span(name="custom parent")/g'

sed commands used for converting code source attributes:

  • sed -i '' 's/CODE_LINENO/CODE_LINE_NUMBER/g'
  • sed -i '' 's/CODE_FILEPATH/CODE_FILE_PATH/g'

sed commands used for converting event capture:

  • sed -i '' 's/events = capture_events()/items = capture_items("event", "transaction", "span")/g'
  • sed -i '' 's/capture_events,/capture_items,/g'
  • sed -i '' 's/capture_events)/capture_items)/g'
  • sed -i '' '/(event,) = events/d'

sed commands used for converting op:

  • sed -i '' 's/- op/- sentry.op/g'
  • sed -i '' 's/span.get("op")/span["attributes"].get("sentry.op")/g'

sed commands used for converting description:

  • sed -i '' 's/span.get("description")/span["name"]/g'
  • sed -i '' 's/description = spans[0]["description"]/name = spans[0]["name"]/g'
  • sed -i '' 's/description/name/g'

sed commands used for converting data to attributes:

  • sed -i '' 's/data = span.get("data", {})/attributes = span["attributes"]/g'
  • sed -i '' 's/in data/in attributes/g'
  • sed -i '' 's/data.get/attributes.get/g'
  • sed -i '' 's/event["spans"]/spans/g'
  • sed -i '' 's/span["data"]/span["attributes"]/g'

sed commands used for converting timestamps:

  • sed -i '' 's/span.start_timestamp/span._start_timestamp/g'
  • sed -i '' 's/span.timestamp/span._timestamp/g'

Issues

Reminders

@github-actions

github-actionsBot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.43s

All tests are passing successfully.

❌ Patch coverage is 9.23%. Project has 14865 uncovered lines.

Files with missing lines (2)
FilePatch %Lines
tracing_utils.py42.95%⚠️ 449 Missing and 42 partials
sqlalchemy.py10.00%⚠️ 90 Missing

Generated by Codecov Action

Comment threadtests/integrations/threading/test_threading.py
Comment threadtests/conftest.py
Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py
Comment threadsentry_sdk/integrations/sqlalchemy.py
Comment threadsentry_sdk/tracing_utils.py
Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py
Comment threadsentry_sdk/integrations/asyncpg.py Outdated
Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review April 24, 2026 10:13
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code ownerApril 24, 2026 10:13
Comment threadsentry_sdk/integrations/asyncpg.py Outdated
Comment threadsentry_sdk/integrations/sqlalchemy.py
Comment threadtests/conftest.py Outdated
Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py
Comment threadtests/conftest.py
Comment threadsentry_sdk/tracing_utils.py
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as draft April 27, 2026 08:13
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review April 27, 2026 12:27
Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py

@sentrivanasentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great overall! Just not sure about a handful of attributes.

Comment threadsentry_sdk/integrations/sqlalchemy.py Outdated
Comment threadsentry_sdk/integrations/sqlalchemy.py Outdated
Comment threadsentry_sdk/tracing_utils.py
Comment threadsentry_sdk/tracing_utils.py
Comment threadsentry_sdk/tracing_utils.py Outdated
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as draft April 28, 2026 07:16

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5efa060. Configure here.

Comment threadtests/integrations/sqlalchemy/test_sqlalchemy.py Outdated
Comment threadsentry_sdk/tracing_utils.py Outdated
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review April 28, 2026 13:02

@sentrivanasentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-alderman-webb
alexander-alderman-webb merged commit a8a4992 into masterApr 29, 2026
154 of 156 checks passed
@alexander-alderman-webb
alexander-alderman-webb deleted the webb/sqlalchemy/span-first branch April 29, 2026 07:03
mgaligniana pushed a commit to mgaligniana/sentry-python that referenced this pull request Aug 9, 2026
Adapt `add_query_source()` to mirror changes to `add_http_request_source()` in getsentry#6084.
Add `record_sql_queries_supporting_streaming()` based on `record_sql_queries()` so that the streaming path is not triggered for ORM integrations that have not yet been ported to the streaming trace lifecycle.
Drop the `db.params`, `db.paramstyle`, `db.executemany`, and `db.cursor` attributes in streaming lifecycle mode. Replace deprecated `db.system` and `db.name` attributes with `db.system.name` and `db.namespace` attributes in the streaming lifecycle mode.
Set `<unknown SQL query>` as the name when the description was previously `None`.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@alexander-alderman-webb@sentrivana