Skip to content

Commit d538ae2

Browse files
simplify context stack
1 parent 57268a9 commit d538ae2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sentry_sdk/integrations/pydantic_ai/patches/agent_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def __aenter__(self) -> "Any":
5858

5959
# Push agent to contextvar stack after span is successfully created and entered
6060
# This ensures proper pairing with pop_agent() in __aexit__ even if exceptions occur
61-
push_agent(self.agent, self.is_streaming)
61+
push_agent(self.agent)
6262

6363
# Enter the original context manager
6464
result = await self.original_ctx_manager.__aenter__()
@@ -113,7 +113,7 @@ async def wrapper(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
113113
) as span:
114114
# Push agent to contextvar stack after span is successfully created and entered
115115
# This ensures proper pairing with pop_agent() in finally even if exceptions occur
116-
push_agent(self, is_streaming)
116+
push_agent(self)
117117

118118
try:
119119
result = await original_func(self, *args, **kwargs)

sentry_sdk/integrations/pydantic_ai/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
)
1919

2020

21-
def push_agent(agent: "Any", is_streaming: bool = False) -> None:
22-
"""Push an agent context onto the stack along with its streaming flag."""
21+
def push_agent(agent: "Any") -> None:
22+
"""Push an agent context onto the stack."""
2323
stack = _agent_context_stack.get().copy()
24-
stack.append({"agent": agent, "is_streaming": is_streaming})
24+
stack.append(agent)
2525
_agent_context_stack.set(stack)
2626

2727

@@ -37,7 +37,7 @@ def get_current_agent() -> "Any":
3737
"""Get the current agent from the contextvar stack."""
3838
stack = _agent_context_stack.get()
3939
if stack:
40-
return stack[-1]["agent"]
40+
return stack[-1]
4141
return None
4242

4343

0 commit comments

Comments
 (0)