Skip to content

Commit 55f3ea8

Browse files
committed
Cleanup
1 parent 5ce67e7 commit 55f3ea8

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

sentry_sdk/integrations/openai_agents.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,21 @@ def _capture_exception(exc):
2828

2929

3030
class SentryRunHooks(RunHooks):
31-
def __init__(self):
32-
self.event_counter = 0
33-
3431
def _usage_to_str(self, usage: Usage) -> str:
3532
return f"{usage.requests} requests, {usage.input_tokens} input tokens, {usage.output_tokens} output tokens, {usage.total_tokens} total tokens"
3633

3734
async def on_agent_start(self, context: RunContextWrapper, agent: Agent) -> None:
38-
self.event_counter += 1
3935
print(
40-
f"### {self.event_counter}: Agent {agent.name} started. Usage: {self._usage_to_str(context.usage)}"
36+
f"### Agent {agent.name} started. Usage: {self._usage_to_str(context.usage)}"
4137
)
4238
span = sentry_sdk.start_span(op="gen_ai.agent_start", description=agent.name)
4339
span.__enter__()
4440

4541
async def on_agent_end(
4642
self, context: RunContextWrapper, agent: Agent, output: Any
4743
) -> None:
48-
self.event_counter += 1
4944
print(
50-
f"### {self.event_counter}: Agent '{agent.name}' ended with output {output}. Usage: {self._usage_to_str(context.usage)}"
45+
f"### Agent '{agent.name}' ended with output {output}. Usage: {self._usage_to_str(context.usage)}"
5146
)
5247
current_span = sentry_sdk.get_current_span()
5348
if current_span:
@@ -56,19 +51,17 @@ async def on_agent_end(
5651
async def on_tool_start(
5752
self, context: RunContextWrapper, agent: Agent, tool: Tool
5853
) -> None:
59-
self.event_counter += 1
6054
print(
61-
f"### {self.event_counter}: Tool {tool.name} started. Usage: {self._usage_to_str(context.usage)}"
55+
f"### Tool {tool.name} started. Usage: {self._usage_to_str(context.usage)}"
6256
)
6357
span = sentry_sdk.start_span(op="gen_ai.tool_start", description=tool.name)
6458
span.__enter__()
6559

6660
async def on_tool_end(
6761
self, context: RunContextWrapper, agent: Agent, tool: Tool, result: str
6862
) -> None:
69-
self.event_counter += 1
7063
print(
71-
f"### {self.event_counter}: Tool {tool.name} ended with result {result}. Usage: {self._usage_to_str(context.usage)}"
64+
f"### Tool {tool.name} ended with result {result}. Usage: {self._usage_to_str(context.usage)}"
7265
)
7366
current_span = sentry_sdk.get_current_span()
7467
if current_span:
@@ -77,9 +70,8 @@ async def on_tool_end(
7770
async def on_handoff(
7871
self, context: RunContextWrapper, from_agent: Agent, to_agent: Agent
7972
) -> None:
80-
self.event_counter += 1
8173
print(
82-
f"### {self.event_counter}: Handoff from '{from_agent.name}' to '{to_agent.name}'. Usage: {self._usage_to_str(context.usage)}"
74+
f"### Handoff from '{from_agent.name}' to '{to_agent.name}'. Usage: {self._usage_to_str(context.usage)}"
8375
)
8476
current_span = sentry_sdk.get_current_span()
8577
if current_span:

0 commit comments

Comments
 (0)