1414 set_data_normalized ,
1515)
1616from sentry_sdk .consts import SPANDATA
17- from sentry_sdk .integrations import DidNotEnable
1817from sentry_sdk .traces import Span
1918from sentry_sdk .utils import (
2019 event_from_exception ,
2120 safe_serialize ,
2221)
2322
2423if TYPE_CHECKING :
25- from typing import Any , Optional
24+ from typing import Any
2625
2726 from agents import TResponseInputItem , Usage
2827
2928 from sentry_sdk ._types import TextPart
3029
31- try :
32- import agents
33- from agents import Model
34- except ImportError :
35- raise DidNotEnable ("OpenAI Agents not installed" )
36-
3730
3831def _capture_exception (exc : "Any" ) -> None :
3932 event , hint = event_from_exception (
@@ -44,25 +37,6 @@ def _capture_exception(exc: "Any") -> None:
4437 sentry_sdk .capture_event (event , hint = hint )
4538
4639
47- def _set_agent_data (span : "Span" , agent : "agents.Agent" ) -> None :
48- span .set_attribute (
49- SPANDATA .GEN_AI_PROVIDER_NAME , "openai"
50- ) # See footnote for https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-system for explanation why.
51-
52- span .set_attribute (SPANDATA .GEN_AI_AGENT_NAME , agent .name )
53-
54- model_name : "Optional[str]" = None
55- if isinstance (agent .model , Model ) and hasattr (agent .model , "model" ):
56- model_name = agent .model .model
57- elif isinstance (agent .model , str ):
58- model_name = agent .model
59- elif hasattr (agent , "_sentry_request_model" ):
60- model_name = agent ._sentry_request_model
61-
62- if model_name :
63- span .set_attribute (SPANDATA .GEN_AI_REQUEST_MODEL , model_name )
64-
65-
6640def _set_usage_data (span : "Span" , usage : "Usage" ) -> None :
6741 span .set_attribute (SPANDATA .GEN_AI_USAGE_INPUT_TOKENS , usage .input_tokens )
6842 span .set_attribute (
0 commit comments