Skip to content

feat(test-anthropic): Migrate start_transaction to streamed spans - #104

Merged
ericapisani merged 2 commits into
mainfrom
py-2758/test-anthropic-span-api
Sep 1, 2026
Merged

ericapisani merged 2 commits into
mainfrom
py-2758/test-anthropic-span-api

Conversation

@ericapisani

Copy link
Copy Markdown
Member

Summary

Converts the 2 live sentry_sdk.start_transaction(...) calls in test-anthropic to sentry_sdk.traces.start_span(...), since this project already runs with trace_lifecycle="stream" and start_transaction now returns a NoOpSpan under that mode.

  • main_async.py: start_transaction(name="anthropic-async") → sentry_sdk.traces.start_span(name="anthropic-async", attributes={"sentry.op": "anthropic-async"})
  • main_tool.py: start_transaction(name="anthropic-sync-tool") → sentry_sdk.traces.start_span(name="anthropic-sync-tool", attributes={"sentry.op": "anthropic-sync-tool"})

Both files now also import sentry_sdk.traces explicitly, since it is not re-exported from sentry_sdk/__init__.py.

main.py's start_transaction call is commented out and was left untouched.

Intentionally out of scope

The 4 @sentry_sdk.trace(...) decorators (main.py:10, main_async.py:11, main_tool.py:10, main_tool.py:31) were not converted. They use template=SPANTEMPLATE.AI_AGENT / AI_TOOL, but the streaming decorator (sentry_sdk.traces.trace) only accepts name/attributes/active — no template or op parameter — so converting them now would silently drop the AI span templates. This needs SDK support for a streaming-compatible span template before it can be migrated, and is left as a follow-up.

Test plan

  • python -m py_compile on main.py, main_async.py, main_tool.py
  • git diff confirms no @sentry_sdk.trace line was touched

@linear-code

linear-code Bot commented Sep 1, 2026

Copy link
Copy Markdown

PY-2758

Neither start_transaction call passed op=, so setting sentry.op to the span
name fabricates data that was not there before. Drop the attributes dict and
let the spans carry only their name.
@ericapisani
ericapisani merged commit b2befcb into main Sep 1, 2026
8 of 9 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