Skip to content

feat(sqlalchemy): Support span streaming#6132

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

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

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

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

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
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

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)
File Patch % Lines
tracing_utils.py 42.95% ⚠️ 449 Missing and 42 partials
sqlalchemy.py 10.00% ⚠️ 90 Missing

Generated by Codecov Action

Comment thread tests/integrations/threading/test_threading.py
Comment thread tests/conftest.py
Comment thread tests/integrations/sqlalchemy/test_sqlalchemy.py
Comment thread sentry_sdk/integrations/sqlalchemy.py
Comment thread sentry_sdk/tracing_utils.py
Comment thread tests/integrations/sqlalchemy/test_sqlalchemy.py
Comment thread sentry_sdk/integrations/asyncpg.py Outdated
Comment thread tests/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 owner April 24, 2026 10:13
Comment thread sentry_sdk/integrations/asyncpg.py Outdated
Comment thread sentry_sdk/integrations/sqlalchemy.py
Comment thread tests/conftest.py Outdated
Comment thread tests/integrations/sqlalchemy/test_sqlalchemy.py
Comment thread tests/conftest.py
Comment thread sentry_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 thread tests/integrations/sqlalchemy/test_sqlalchemy.py
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

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 thread sentry_sdk/integrations/sqlalchemy.py Outdated
Comment thread sentry_sdk/integrations/sqlalchemy.py Outdated
Comment thread sentry_sdk/tracing_utils.py
Comment thread sentry_sdk/tracing_utils.py
Comment thread sentry_sdk/tracing_utils.py Outdated
@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft April 28, 2026 07:16
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 thread tests/integrations/sqlalchemy/test_sqlalchemy.py Outdated
Comment thread sentry_sdk/tracing_utils.py Outdated
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review April 28, 2026 13:02
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

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 master Apr 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
Sign up for free to 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