Skip to content

Commit f9f37d5

Browse files
ref(openai-agents): Remove error attributes (#5986)
Remove `span.status`, `error.type` and `error.message` attributes.
1 parent af3a297 commit f9f37d5

File tree

4 files changed

+11
-32
lines changed

4 files changed

+11
-32
lines changed

sentry_sdk/integrations/openai_agents/patches/agent_run.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end_invoke_agent_span,
99
handoff_span,
1010
)
11-
from ..utils import _record_exception_on_span
11+
from sentry_sdk.tracing_utils import set_span_errored
1212

1313
from typing import TYPE_CHECKING
1414

@@ -99,9 +99,9 @@ async def _run_single_turn(
9999

100100
try:
101101
result = await original_run_single_turn(*args, **kwargs)
102-
except Exception as exc:
102+
except Exception:
103103
if span is not None and span.timestamp is None:
104-
_record_exception_on_span(span, exc)
104+
set_span_errored(span)
105105
end_invoke_agent_span(context_wrapper, agent)
106106
reraise(*sys.exc_info())
107107

@@ -153,11 +153,11 @@ async def _run_single_turn_streamed(
153153

154154
try:
155155
result = await original_run_single_turn_streamed(*args, **kwargs)
156-
except Exception as exc:
156+
except Exception:
157157
exc_info = sys.exc_info()
158158
with capture_internal_exceptions():
159159
if span is not None and span.timestamp is None:
160-
_record_exception_on_span(span, exc)
160+
set_span_errored(span)
161161
end_invoke_agent_span(context_wrapper, agent)
162162
_close_streaming_workflow_span(agent)
163163
reraise(*exc_info)

sentry_sdk/integrations/openai_agents/patches/error_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from functools import wraps
22

33
import sentry_sdk
4-
from ..utils import _record_exception_on_span
4+
from sentry_sdk.tracing_utils import set_span_errored
55

66
from typing import TYPE_CHECKING
77

@@ -57,7 +57,7 @@ def sentry_attach_error_to_current_span(
5757
# Set the current Sentry span to errored
5858
current_span = sentry_sdk.get_current_span()
5959
if current_span is not None:
60-
_record_exception_on_span(current_span, error)
60+
set_span_errored(current_span)
6161

6262
# Call the original function
6363
return original_attach_error(error, *args, **kwargs)

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from sentry_sdk.consts import SPANDATA
66
from sentry_sdk.integrations import DidNotEnable
77
from sentry_sdk.utils import capture_internal_exceptions, reraise
8+
from sentry_sdk.tracing_utils import set_span_errored
89

910
from ..spans import agent_workflow_span, end_invoke_agent_span
10-
from ..utils import _capture_exception, _record_exception_on_span
11+
from ..utils import _capture_exception
1112

1213
try:
1314
from agents.exceptions import AgentsException
@@ -65,7 +66,7 @@ async def wrapper(*args: "Any", **kwargs: "Any") -> "Any":
6566
invoke_agent_span is not None
6667
and invoke_agent_span.timestamp is None
6768
):
68-
_record_exception_on_span(invoke_agent_span, exc)
69+
set_span_errored(invoke_agent_span)
6970
end_invoke_agent_span(context_wrapper, agent)
7071
reraise(*exc_info)
7172
except Exception as exc:

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from sentry_sdk.consts import SPANDATA, SPANSTATUS, OP
1212
from sentry_sdk.integrations import DidNotEnable
1313
from sentry_sdk.scope import should_send_default_pii
14-
from sentry_sdk.tracing import Span
1514
from sentry_sdk.tracing_utils import set_span_errored
1615
from sentry_sdk.utils import event_from_exception, safe_serialize
1716
from sentry_sdk.ai._openai_completions_api import _transform_system_instructions
@@ -23,10 +22,9 @@
2322
from typing import TYPE_CHECKING
2423

2524
if TYPE_CHECKING:
26-
from typing import Any, Union
25+
from typing import Any
2726
from agents import Usage, TResponseInputItem
2827

29-
from sentry_sdk.traces import StreamedSpan
3028
from sentry_sdk._types import TextPart
3129

3230
try:
@@ -47,26 +45,6 @@ def _capture_exception(exc: "Any") -> None:
4745
sentry_sdk.capture_event(event, hint=hint)
4846

4947

50-
def _record_exception_on_span(
51-
span: "Union[Span, StreamedSpan]", error: Exception
52-
) -> "Any":
53-
set_span_errored(span)
54-
55-
if not isinstance(span, Span):
56-
# TODO[span-first]: make this work with streamedspans
57-
return
58-
59-
span.set_data("span.status", "error")
60-
61-
# Optionally capture the error details if we have them
62-
if hasattr(error, "__class__"):
63-
span.set_data("error.type", error.__class__.__name__)
64-
if hasattr(error, "__str__"):
65-
error_message = str(error)
66-
if error_message:
67-
span.set_data("error.message", error_message)
68-
69-
7048
def _set_agent_data(span: "sentry_sdk.tracing.Span", agent: "agents.Agent") -> None:
7149
span.set_data(
7250
SPANDATA.GEN_AI_SYSTEM, "openai"

0 commit comments

Comments
 (0)