Skip to content

feat(stdlib): Support span streaming#6154

Merged
alexander-alderman-webb merged 31 commits intomasterfrom
webb/stdlib/span-first
Apr 29, 2026
Merged

feat(stdlib): Support span streaming#6154
alexander-alderman-webb merged 31 commits intomasterfrom
webb/stdlib/span-first

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

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

Description

Port patches for both http and subprocess packages.

Spans for some subprocess operations did not have a description. The value of the sentry.op attribute is also used as the name in the streaming path in these cases.

In the streaming path, use

  • http.request.method instead of http.method
  • ur.full instead of url
  • url.query instead of http.query
  • url.fragment instead of http.fragment

Dropped attributes:

  • reason
  • subprocess.cwd

Tests for adding breadcrumbs based on spans have not been parametrized as breadcrumbs are not automatically created from spans with the new streaming lifecycle.


Adapting Tests

sed commands used for converting transaction context managers:

  • sed -i '' 's/start_transaction(name="foo")/sentry_sdk.traces.start_span(name="custom parent")/g'
  • sed -i '' 's/start_transaction(name="foo") as transaction:/sentry_sdk.traces.start_span(name="custom parent"):/g'

sed commands used for converting specific attributes:

sed -i '' 's/CODE_LINENO/CODE_LINE_NUMBER/g'
sed -i '' 's/CODE_FILEPATH/CODE_FILE_PATH/g'
sed -i '' 's/["tags"]["subprocess.pid"]/["attributes"][SPANDATA.PROCESS_PID]/g'

sed commands used for converting event capture:

  • sed -i '' '/(event,) = events/d'
  • sed -i '' 's/capture_events,/capture_items,/g'
  • sed -i '' 's/capture_events)/capture_items)/g'
  • sed -i '' 's/events = capture_events()/items = capture_items("event", "transaction", "span")/g'
  • sed -i '' 's/request_span = event["spans"][-1]/request_span = next(item.payload for item in items if item.type == "span")/g'
  • sed -i '' 's/span = event["spans"][-1]/span = next(item.payload for item in items if item.type == "span")/g'

sed commands used for converting op:

  • sed -i '' 's/["op"]/["attributes"]["sentry.op"]/g'

sed commands used for converting origin:

  • sed -i '' 's/["origin"]/["attributes"]["sentry.origin"]/g'

sed commands used for converting description:

  • sed -i '' 's/description/name/g'

sed commands used for converting data to attributes:

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

sed commands used for converting trace-related expressions:

  • sed -i '' 's/event["contexts"]["trace"]["trace_id"]/request_span["trace_id"]/g'
  • sed -i '' 's/transaction = continue_trace(headers)/sentry_sdk.traces.continue_trace(headers)/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

Closes #6066

Reminders

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Codecov Results 📊

2165 passed | ⏭️ 154 skipped | Total: 2319 | Pass Rate: 93.36% | Execution Time: 5m 2s

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 12633 uncovered lines.

Files with missing lines (2)
File Patch % Lines
stdlib.py 99.41% ⚠️ 1 Missing and 4 partials
consts.py 99.48% ⚠️ 2 Missing

Generated by Codecov Action

Comment thread tests/integrations/stdlib/test_httplib.py Outdated
Comment thread sentry_sdk/integrations/stdlib.py Outdated
Comment thread sentry_sdk/integrations/stdlib.py
@alexander-alderman-webb alexander-alderman-webb changed the base branch from master to webb/stdlib/tests April 28, 2026 08:48
@alexander-alderman-webb alexander-alderman-webb changed the base branch from webb/stdlib/tests to webb/stdlib/code-source-tests April 28, 2026 11:37
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review April 29, 2026 06:16
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner April 29, 2026 06:16
Comment thread sentry_sdk/integrations/stdlib.py
Comment thread sentry_sdk/integrations/stdlib.py
Comment thread sentry_sdk/integrations/stdlib.py Outdated
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 1106fe4. Configure here.

Comment thread sentry_sdk/integrations/stdlib.py
Comment thread tests/integrations/stdlib/test_httplib.py Outdated
Comment thread sentry_sdk/integrations/stdlib.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.

LGTM!

Base automatically changed from webb/stdlib/code-source-tests to master April 29, 2026 10:26
@alexander-alderman-webb alexander-alderman-webb merged commit 5f02ee8 into master Apr 29, 2026
165 of 167 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/stdlib/span-first branch April 29, 2026 10:59
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.

Migrate stdlib to span first

2 participants