Skip to content

feat(test-openai): Migrate start_transaction to streamed spans - #106

Merged
ericapisani merged 1 commit into
mainfrom
py-2758/test-openai-span-api
Sep 1, 2026
Merged

ericapisani merged 1 commit into
mainfrom
py-2758/test-openai-span-api

Conversation

@ericapisani

Copy link
Copy Markdown
Member

Summary

Converts the 8 live sentry_sdk.start_transaction(...) calls in test-openai to sentry_sdk.traces.start_span(...).

test-openai already uses trace_lifecycle="stream". Under streaming, sentry_sdk.start_transaction(...) (and the top-level sentry_sdk.start_span(...)) both return a NoOpSpan — only sentry_sdk.traces.start_span(...) creates a real span. This PR updates every project entrypoint to use the real streamed span API.

Files changed:

  • main.py
  • main_async.py
  • main_custom.py
  • main_streamed.py
  • main_truncation.py
  • main_conversation.py (2 calls)
  • main_conversation_async.py

Each conversion:

  • Adds import sentry_sdk.traces (not re-exported from sentry_sdk/__init__.py)
  • Replaces sentry_sdk.start_transaction(name=X) with sentry_sdk.traces.start_span(name=X)

All 8 calls were simple with sentry_sdk.start_transaction(name=...): blocks — no op=, no bound span variable, and no set_data/set_tag/set_status usage, so no further attribute conversion was needed.

Left untouched, on purpose: the 3 @sentry_sdk.trace(...) decorators in main_custom.py (lines 11, 19, 24) use template=SPANTEMPLATE.AI_TOOL / AI_CHAT / AI_AGENT. The streaming decorator (sentry_sdk.traces.trace) only accepts name/attributes/active — there is no streaming equivalent for template/op yet, so converting these would silently drop the AI span templates. This is left as a follow-up pending SDK support.

The before_send_span callbacks in main_streamed.py, main_conversation.py, and main_conversation_async.py are unchanged.

Test plan

  • python -m py_compile on all 7 edited files
  • grep -rn "start_transaction" test-openai returns no matches
  • git diff confirms no @sentry_sdk.trace decorator line changed

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.
@linear-code

linear-code Bot commented Sep 1, 2026

Copy link
Copy Markdown

PY-2758

@ericapisani
ericapisani merged commit 2ba5e99 into main Sep 1, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant