Repository navigation
feat(test-openai): Migrate start_transaction to streamed spans - #106
Merged
Merged
Conversation
Under trace_lifecycle="stream", sentry_sdk.start_transaction() returns a NoOpSpan, so convert the 8 live calls to sentry_sdk.traces.start_span() across main.py, main_async.py, main_custom.py, main_streamed.py, main_truncation.py, main_conversation.py, and main_conversation_async.py.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Converts the 8 live
sentry_sdk.start_transaction(...)calls intest-openaitosentry_sdk.traces.start_span(...).test-openaialready usestrace_lifecycle="stream". Under streaming,sentry_sdk.start_transaction(...)(and the top-levelsentry_sdk.start_span(...)) both return aNoOpSpan— onlysentry_sdk.traces.start_span(...)creates a real span. This PR updates every project entrypoint to use the real streamed span API.Files changed:
main.pymain_async.pymain_custom.pymain_streamed.pymain_truncation.pymain_conversation.py(2 calls)main_conversation_async.pyEach conversion:
import sentry_sdk.traces(not re-exported fromsentry_sdk/__init__.py)sentry_sdk.start_transaction(name=X)withsentry_sdk.traces.start_span(name=X)All 8 calls were simple
with sentry_sdk.start_transaction(name=...):blocks — noop=, no bound span variable, and noset_data/set_tag/set_statususage, so no further attribute conversion was needed.Left untouched, on purpose: the 3
@sentry_sdk.trace(...)decorators inmain_custom.py(lines 11, 19, 24) usetemplate=SPANTEMPLATE.AI_TOOL/AI_CHAT/AI_AGENT. The streaming decorator (sentry_sdk.traces.trace) only acceptsname/attributes/active— there is no streaming equivalent fortemplate/opyet, so converting these would silently drop the AI span templates. This is left as a follow-up pending SDK support.The
before_send_spancallbacks inmain_streamed.py,main_conversation.py, andmain_conversation_async.pyare unchanged.Test plan
python -m py_compileon all 7 edited filesgrep -rn "start_transaction" test-openaireturns no matchesgit diffconfirms no@sentry_sdk.tracedecorator line changed