sentry-python icon indicating copy to clipboard operation
sentry-python copied to clipboard

[do not merge] Span first

Open sentrivana opened this issue 2 months ago • 1 comments

Description

WIP: Draft implementation of span first/span streaming in the Python SDK. Uses the existing start_span API, but batches spans and sends them independently of the transaction/segment span.

Enables to run the SDK in two modes: static and streaming. Static mode is the current status quo where spans are sent together with their transaction (segment) as the transaction finishes. Streaming mode makes two major changes to the behavior of the start_span API:

  • Spans are added to the streaming buffer on finish and they may be sent in an envelope without their segment.
  • [Later] start_span without a running segment will be promoted to a segment span. (For the POC, this is not the case; we just use the existing start_transaction.)

TODOs:

  • ignore_spans
  • start_span should start a segment span if there is no active segment span

Issues

  • Project: https://linear.app/getsentry/project/span-first-sdk-python-727da28dd037/overview

Reminders

sentrivana avatar Nov 19 '25 15:11 sentrivana

Codecov Report

:x: Patch coverage is 26.42487% with 142 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 83.36%. Comparing base (71afdf9) to head (7c9de72). :warning: Report is 1 commits behind head on master. :white_check_mark: All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/_span_batcher.py 25.84% 66 Missing :warning:
sentry_sdk/utils.py 6.52% 43 Missing :warning:
sentry_sdk/tracing.py 50.00% 12 Missing and 4 partials :warning:
sentry_sdk/client.py 29.41% 11 Missing and 1 partial :warning:
sentry_sdk/envelope.py 0.00% 1 Missing and 1 partial :warning:
sentry_sdk/tracing_utils.py 50.00% 1 Missing and 1 partial :warning:
sentry_sdk/scope.py 66.66% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5119      +/-   ##
==========================================
- Coverage   83.94%   83.36%   -0.59%     
==========================================
  Files         181      182       +1     
  Lines       18343    18526     +183     
  Branches     3261     3307      +46     
==========================================
+ Hits        15398    15444      +46     
- Misses       1938     2070     +132     
- Partials     1007     1012       +5     
Files with missing lines Coverage Δ
sentry_sdk/consts.py 99.41% <ø> (ø)
sentry_sdk/scope.py 88.28% <66.66%> (-0.12%) :arrow_down:
sentry_sdk/envelope.py 87.37% <0.00%> (-0.90%) :arrow_down:
sentry_sdk/tracing_utils.py 86.51% <50.00%> (+0.27%) :arrow_up:
sentry_sdk/client.py 82.03% <29.41%> (-1.68%) :arrow_down:
sentry_sdk/tracing.py 82.66% <50.00%> (-2.42%) :arrow_down:
sentry_sdk/utils.py 82.41% <6.52%> (-3.97%) :arrow_down:
sentry_sdk/_span_batcher.py 25.84% <25.84%> (ø)

... and 1 file with indirect coverage changes

codecov[bot] avatar Nov 19 '25 15:11 codecov[bot]