Skip to content

Commit 2872675

Browse files
fix(openai-agents): Move _set_agent_data call to ai_client_span function (#4876)
### Description We can set the agent data early, so that we get input model and other data, even if there's an exception while running the agent #### Issues Resolves: TET-1205 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Move `_set_agent_data` to `ai_client_span` so agent/model metadata is recorded when the span is created. > > - **Tracing (`sentry_sdk/integrations/openai_agents/spans/ai_client.py`)**: > - Set agent metadata in `ai_client_span` via `_set_agent_data` at span creation. > - Remove `_set_agent_data` from `update_ai_client_span` to avoid duplication. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 27e94cc. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9b58d31 commit 2872675

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sentry_sdk/integrations/openai_agents/spans/ai_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ def ai_client_span(agent, get_response_kwargs):
2828
# TODO-anton: remove hardcoded stuff and replace something that also works for embedding and so on
2929
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
3030

31+
_set_agent_data(span, agent)
32+
3133
return span
3234

3335

3436
def update_ai_client_span(span, agent, get_response_kwargs, result):
3537
# type: (sentry_sdk.tracing.Span, Agent, dict[str, Any], Any) -> None
36-
_set_agent_data(span, agent)
3738
_set_usage_data(span, result.usage)
3839
_set_input_data(span, get_response_kwargs)
3940
_set_output_data(span, result)

0 commit comments

Comments
 (0)