22from typing import Any , Callable , List , Optional
33
44import sentry_sdk
5- from sentry_sdk .ai .monitoring import set_ai_pipeline_name
65from sentry_sdk .ai .utils import set_data_normalized
76from sentry_sdk .consts import OP , SPANDATA
87from sentry_sdk .integrations import DidNotEnable , Integration
@@ -141,52 +140,32 @@ def new_invoke(self, *args, **kwargs):
141140
142141 with sentry_sdk .start_span (
143142 op = OP .GEN_AI_INVOKE_AGENT ,
144- name = (
145- f"invoke_agent invoke { graph_name } " .strip ()
146- if graph_name
147- else "invoke_agent"
148- ),
143+ name = "invoke_agent" ,
149144 origin = LanggraphIntegration .origin ,
150145 ) as span :
151- # Set agent metadata
152146 if graph_name :
153- set_ai_pipeline_name (graph_name )
154147 span .set_data (SPANDATA .GEN_AI_PIPELINE_NAME , graph_name )
155148 span .set_data (SPANDATA .GEN_AI_AGENT_NAME , graph_name )
156149
157150 span .set_data (SPANDATA .GEN_AI_OPERATION_NAME , "invoke_agent" )
158151 span .set_data (SPANDATA .GEN_AI_RESPONSE_STREAMING , False )
159152
160- # Capture input messages if PII is allowed
161153 if (
162154 len (args ) > 0
163155 and should_send_default_pii ()
164156 and integration .include_prompts
165157 ):
166- # import ipdb; ipdb.set_trace()
167158 parsed_messages = _parse_langgraph_messages (args [0 ])
168159 if parsed_messages :
169160 span .set_data (
170161 SPANDATA .GEN_AI_REQUEST_MESSAGES ,
171162 safe_serialize (parsed_messages ),
172163 )
173164
174- # Execute the graph
175- try :
176- result = f (self , * args , ** kwargs )
177-
178- # Capture output state if PII is allowed
179- if should_send_default_pii () and integration .include_prompts :
180- set_data_normalized (span , SPANDATA .GEN_AI_RESPONSE_TEXT , result )
181-
182- return result
183-
184- except Exception :
185- span .set_status ("internal_error" )
186- raise
187- finally :
188- if graph_name :
189- set_ai_pipeline_name (None )
165+ result = f (self , * args , ** kwargs )
166+ if should_send_default_pii () and integration .include_prompts :
167+ set_data_normalized (span , SPANDATA .GEN_AI_RESPONSE_TEXT , result )
168+ return result
190169
191170 return new_invoke
192171
@@ -209,7 +188,6 @@ async def new_ainvoke(self, *args, **kwargs):
209188 origin = LanggraphIntegration .origin ,
210189 ) as span :
211190 if graph_name :
212- set_ai_pipeline_name (graph_name )
213191 span .set_data (SPANDATA .GEN_AI_PIPELINE_NAME , graph_name )
214192 span .set_data (SPANDATA .GEN_AI_AGENT_NAME , graph_name )
215193
@@ -227,23 +205,10 @@ async def new_ainvoke(self, *args, **kwargs):
227205 SPANDATA .GEN_AI_REQUEST_MESSAGES ,
228206 safe_serialize (parsed_messages ),
229207 )
230-
231- # Execute the graph
232- try :
233208 result = await f (self , * args , ** kwargs )
234-
235- # Capture output state if PII is allowed
236209 if should_send_default_pii () and integration .include_prompts :
237210 set_data_normalized (span , SPANDATA .GEN_AI_RESPONSE_TEXT , result )
238-
239211 return result
240212
241- except Exception :
242- span .set_status ("internal_error" )
243- raise
244- finally :
245- if graph_name :
246- set_ai_pipeline_name (None )
247-
248213 new_ainvoke .__wrapped__ = True
249214 return new_ainvoke
0 commit comments