Skip to content

'Span' object has no attribute '_context_manager_state' #4718

@Afstkla

Description

@Afstkla

How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.35.0

Steps to Reproduce

Run

import asyncio

import sentry_sdk
from agents import Agent, Runner
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration

sentry_sdk.init(
    dsn="...",
    send_default_pii=True,
    traces_sample_rate=1.0,
    integrations=[
        OpenAIAgentsIntegration(),
    ],
)


main_agent = Agent(
    name="main_agent",
    model="gpt-5",
)


async def run_agent() -> None:
    runner = await Runner.run(
        starting_agent=main_agent,
        input="How are you?",
    )
    print(runner.final_output)


async def main() -> None:
    await asyncio.gather(*[run_agent() for _ in range(2)])


if __name__ == "__main__":
    asyncio.run(main())

Then, the agent that finishes 2nd will fail with:

{
  "error": "'Span' object has no attribute '_context_manager_state'",
  "tool_name": "<agentname>_agent"
}

Expected Result

  1. This error not to happen
  2. That most (if not all) parts of the Sentry SDK are wrapped in try catch blocks, so that if for some reason like now a Span cannot be closed, it doesn't interfere with the normal flow

Actual Result

The agent crashes, and instead of the result that was generated by the nested agent being available to the main agent, the main agent only sees the error message and cannot continue.

Metadata

Metadata

Assignees

Projects

Status

Waiting for: Product Owner

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions