-
-
Notifications
You must be signed in to change notification settings - Fork 9
ref(o11y): Support SDK configured with the streaming trace lifecycle #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexander-alderman-webb
merged 38 commits into
main
from
webb/streaming-trace-lifecycle
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
87dcf25
ref(o11y): Support SDK configured with the streaming trace lifecycle
alexander-alderman-webb 99ff2de
python lint
alexander-alderman-webb 6c06b23
make mypy happy
alexander-alderman-webb 43bd7ee
add missing declaration
alexander-alderman-webb 1e90734
test: Initialize SDK in relevant tests
alexander-alderman-webb 5de3e0d
remove dead code
alexander-alderman-webb d570be1
ref(o11y): Remove redundant span status assignment
alexander-alderman-webb a78e920
merge
alexander-alderman-webb 283096b
add pytest parametrization
alexander-alderman-webb 49883c8
move fixtures after mocks
alexander-alderman-webb d6ea809
remove sentry_init from frequency test
alexander-alderman-webb 9c64fa8
configure sdk to avoid sleeps
alexander-alderman-webb 0268df0
Merge branch 'webb/add-init-to-tests' into webb/remove-explicit-status
alexander-alderman-webb ea6dba3
fix import ordering problem
alexander-alderman-webb 32fd19d
cleanup in fixture
alexander-alderman-webb 43ec0e3
Merge branch 'webb/add-init-to-tests' into webb/remove-explicit-status
alexander-alderman-webb cb29166
merge
alexander-alderman-webb 265e126
remove unused parameter
alexander-alderman-webb 2b52bbc
simplify transport
alexander-alderman-webb 6f7f6a4
Merge branch 'webb/add-init-to-tests' into webb/remove-explicit-status
alexander-alderman-webb 9c4f63f
Merge branch 'webb/remove-explicit-status' into webb/streaming-trace-…
alexander-alderman-webb 71deb34
add attributes in streaming path
alexander-alderman-webb bf93e3c
use consistent argument style
alexander-alderman-webb 084b3a1
create span only in isolation scope
alexander-alderman-webb aad2d46
add namespace to attributes
alexander-alderman-webb 530308a
Equivalent changes in taskbroker_client
alexander-alderman-webb ce10118
update tests
alexander-alderman-webb 35831f8
revert test changes
alexander-alderman-webb 3c0b840
remove test additions
alexander-alderman-webb d2cae9c
create shim in sdk.py
alexander-alderman-webb aca4959
address bots
alexander-alderman-webb 8272c9f
remove stray argument
alexander-alderman-webb cd8c9d4
early return in start_span
alexander-alderman-webb fd46b19
move attributes into shim
alexander-alderman-webb 106634c
bump sentry-sdk to when span streaming is fully available
alexander-alderman-webb 6b478e6
use greater than or equal
alexander-alderman-webb 213edcd
Merge branch 'main' into webb/streaming-trace-lifecycle
alexander-alderman-webb 7770df5
do not add args and kwargs attributes to StreamedSpan
alexander-alderman-webb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from contextlib import nullcontext | ||
| from typing import Any, ContextManager | ||
|
|
||
| import sentry_sdk | ||
| from sentry_sdk.scope import Scope | ||
| from sentry_sdk.traces import StreamedSpan | ||
| from sentry_sdk.tracing import NoOpSpan, Span, Transaction | ||
| from sentry_sdk.tracing_utils import has_span_streaming_enabled | ||
|
|
||
|
|
||
| def start_transaction( | ||
| name: str, | ||
| op: str, | ||
| origin: str, | ||
| attributes: dict[str, Any], | ||
| headers: dict[str, Any], | ||
| sampling_context: dict[str, Any], | ||
| ) -> Transaction | NoOpSpan | StreamedSpan | ContextManager[Any]: | ||
| """Start a transaction, or a span if span streaming is enabled.""" | ||
| span = None | ||
| try: | ||
| is_span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options) | ||
| if is_span_streaming: | ||
| sentry_sdk.traces.continue_trace(headers) | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| Scope.set_custom_sampling_context(sampling_context) | ||
|
|
||
| return sentry_sdk.traces.start_span( | ||
| name=name, | ||
| attributes={ | ||
| "sentry.op": op, | ||
| "sentry.origin": origin, | ||
| **attributes, | ||
| }, | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| transaction = sentry_sdk.continue_trace( | ||
| environ_or_headers=headers, | ||
| op=op, | ||
| name=name, | ||
| origin=origin, | ||
| ) | ||
|
|
||
| span = sentry_sdk.start_transaction(transaction, custom_sampling_context=sampling_context) | ||
| for key, value in attributes.items(): | ||
| span.set_data(key, value) | ||
| except Exception: | ||
| pass | ||
|
|
||
| if span is None: | ||
| return nullcontext() | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
| return span | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def start_span( | ||
| name: str, op: str, origin: str, attributes: dict[str, Any] | ||
| ) -> Span | StreamedSpan | ContextManager[Any]: | ||
| """Start a span in the currently active trace lifecycle.""" | ||
| try: | ||
| is_span_streaming = has_span_streaming_enabled(sentry_sdk.get_client().options) | ||
| if is_span_streaming: | ||
| return sentry_sdk.traces.start_span( | ||
| name=name, | ||
| attributes={ | ||
| "sentry.op": op, | ||
| "sentry.origin": origin, | ||
| **attributes, | ||
| }, | ||
| ) | ||
|
alexander-alderman-webb marked this conversation as resolved.
|
||
|
|
||
| span = sentry_sdk.start_span( | ||
| op=op, | ||
| name=name, | ||
| origin=origin, | ||
| ) | ||
| for key, value in attributes.items(): | ||
| span.set_data(key, value) | ||
|
|
||
| return span | ||
| except Exception: | ||
| pass | ||
|
|
||
| return nullcontext() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should bump the minimum to the latest, so Span Streaming is fully available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a library, we should not arbitrarily restrict its version ranges unless actually required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is required, hence I raised it 😄
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumped 106634c / 6b478e6