@@ -214,27 +214,26 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
214214 input_messages = None
215215 if len (args ) > 0 :
216216 input_messages = _parse_langgraph_messages (args [0 ])
217- if input_messages :
217+ if input_messages and _should_record_inputs ( integration ) :
218218 normalized_input_messages = normalize_message_roles (
219219 input_messages
220220 )
221221
222- if _should_record_inputs (integration ):
223- scope = sentry_sdk .get_current_scope ()
224- messages_data = (
225- truncate_and_annotate_messages (
226- normalized_input_messages , span , scope
227- )
228- if should_truncate_gen_ai_input (client .options )
229- else normalized_input_messages
222+ scope = sentry_sdk .get_current_scope ()
223+ messages_data = (
224+ truncate_and_annotate_messages (
225+ normalized_input_messages , span , scope
226+ )
227+ if should_truncate_gen_ai_input (client .options )
228+ else normalized_input_messages
229+ )
230+ if messages_data is not None :
231+ set_data_normalized (
232+ span ,
233+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
234+ messages_data ,
235+ unpack = False ,
230236 )
231- if messages_data is not None :
232- set_data_normalized (
233- span ,
234- SPANDATA .GEN_AI_REQUEST_MESSAGES ,
235- messages_data ,
236- unpack = False ,
237- )
238237
239238 result = f (self , * args , ** kwargs )
240239
@@ -257,27 +256,26 @@ def new_invoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
257256 input_messages = None
258257 if len (args ) > 0 :
259258 input_messages = _parse_langgraph_messages (args [0 ])
260- if input_messages :
259+ if input_messages and _should_record_inputs ( integration ) :
261260 normalized_input_messages = normalize_message_roles (
262261 input_messages
263262 )
264263
265- if _should_record_inputs (integration ):
266- scope = sentry_sdk .get_current_scope ()
267- messages_data = (
268- truncate_and_annotate_messages (
269- normalized_input_messages , span , scope
270- )
271- if should_truncate_gen_ai_input (client .options )
272- else normalized_input_messages
264+ scope = sentry_sdk .get_current_scope ()
265+ messages_data = (
266+ truncate_and_annotate_messages (
267+ normalized_input_messages , span , scope
268+ )
269+ if should_truncate_gen_ai_input (client .options )
270+ else normalized_input_messages
271+ )
272+ if messages_data is not None :
273+ set_data_normalized (
274+ span ,
275+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
276+ messages_data ,
277+ unpack = False ,
273278 )
274- if messages_data is not None :
275- set_data_normalized (
276- span ,
277- SPANDATA .GEN_AI_REQUEST_MESSAGES ,
278- messages_data ,
279- unpack = False ,
280- )
281279
282280 result = f (self , * args , ** kwargs )
283281
@@ -317,27 +315,26 @@ async def new_ainvoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
317315 input_messages = None
318316 if len (args ) > 0 :
319317 input_messages = _parse_langgraph_messages (args [0 ])
320- if input_messages :
318+ if input_messages and _should_record_inputs ( integration ) :
321319 normalized_input_messages = normalize_message_roles (
322320 input_messages
323321 )
324322
325- if _should_record_inputs (integration ):
326- scope = sentry_sdk .get_current_scope ()
327- messages_data = (
328- truncate_and_annotate_messages (
329- normalized_input_messages , span , scope
330- )
331- if should_truncate_gen_ai_input (client .options )
332- else normalized_input_messages
323+ scope = sentry_sdk .get_current_scope ()
324+ messages_data = (
325+ truncate_and_annotate_messages (
326+ normalized_input_messages , span , scope
327+ )
328+ if should_truncate_gen_ai_input (client .options )
329+ else normalized_input_messages
330+ )
331+ if messages_data is not None :
332+ set_data_normalized (
333+ span ,
334+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
335+ messages_data ,
336+ unpack = False ,
333337 )
334- if messages_data is not None :
335- set_data_normalized (
336- span ,
337- SPANDATA .GEN_AI_REQUEST_MESSAGES ,
338- messages_data ,
339- unpack = False ,
340- )
341338
342339 result = await f (self , * args , ** kwargs )
343340
@@ -359,25 +356,24 @@ async def new_ainvoke(self: "Any", *args: "Any", **kwargs: "Any") -> "Any":
359356 input_messages = None
360357 if len (args ) > 0 :
361358 input_messages = _parse_langgraph_messages (args [0 ])
362- if input_messages :
359+ if input_messages and _should_record_inputs ( integration ) :
363360 normalized_input_messages = normalize_message_roles (input_messages )
364361
365- if _should_record_inputs (integration ):
366- scope = sentry_sdk .get_current_scope ()
367- messages_data = (
368- truncate_and_annotate_messages (
369- normalized_input_messages , span , scope
370- )
371- if should_truncate_gen_ai_input (client .options )
372- else normalized_input_messages
362+ scope = sentry_sdk .get_current_scope ()
363+ messages_data = (
364+ truncate_and_annotate_messages (
365+ normalized_input_messages , span , scope
366+ )
367+ if should_truncate_gen_ai_input (client .options )
368+ else normalized_input_messages
369+ )
370+ if messages_data is not None :
371+ set_data_normalized (
372+ span ,
373+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
374+ messages_data ,
375+ unpack = False ,
373376 )
374- if messages_data is not None :
375- set_data_normalized (
376- span ,
377- SPANDATA .GEN_AI_REQUEST_MESSAGES ,
378- messages_data ,
379- unpack = False ,
380- )
381377
382378 result = await f (self , * args , ** kwargs )
383379
0 commit comments