@@ -210,6 +210,8 @@ class LangchainIntegration(Integration):
210210 identifier = "langchain"
211211 origin = f"auto.ai.{ identifier } "
212212
213+ _ignored_exceptions : "set[type[Exception]]" = set ()
214+
213215 def __init__ (
214216 self : "LangchainIntegration" ,
215217 include_prompts : bool = True ,
@@ -262,17 +264,22 @@ def gc_span_map(self) -> None:
262264 self ._exit_span (span , run_id )
263265
264266 def _handle_error (self , run_id : "UUID" , error : "Any" ) -> None :
267+ is_ignored = isinstance (error , tuple (LangchainIntegration ._ignored_exceptions ))
268+
265269 with capture_internal_exceptions ():
266270 if not run_id or run_id not in self .span_map :
267271 return
268272
269273 span = self .span_map [run_id ]
270274
271- sentry_sdk .capture_exception (
272- error , span ._scope if isinstance (span , StreamedSpan ) else span .scope
273- )
275+ if is_ignored :
276+ span .__exit__ (None , None , None )
277+ else :
278+ sentry_sdk .capture_exception (
279+ error , span ._scope if isinstance (span , StreamedSpan ) else span .scope
280+ )
281+ span .__exit__ (type (error ), error , error .__traceback__ )
274282
275- span .__exit__ (type (error ), error , error .__traceback__ )
276283 del self .span_map [run_id ]
277284
278285 def _normalize_langchain_message (self , message : "BaseMessage" ) -> "Any" :
0 commit comments