11import itertools
2+ import warnings
23from collections import OrderedDict
34from functools import wraps
45
@@ -76,14 +77,19 @@ class LangchainIntegration(Integration):
7677 identifier = "langchain"
7778 origin = f"auto.ai.{ identifier } "
7879
79- # The most number of spans (e.g., LLM calls) that can be processed at the same time.
80- max_spans = 1024
81-
82- def __init__ (self , include_prompts = True , max_spans = 1024 ):
83- # type: (LangchainIntegration, bool, int) -> None
80+ def __init__ (self , include_prompts = True , max_spans = None ):
81+ # type: (LangchainIntegration, bool, Optional[int]) -> None
8482 self .include_prompts = include_prompts
8583 self .max_spans = max_spans
8684
85+ if max_spans is not None :
86+ warnings .warn (
87+ "The `max_spans` parameter of `LangchainIntegration` is "
88+ "deprecated and will be removed in version 3.0 of sentry-sdk." ,
89+ DeprecationWarning ,
90+ stacklevel = 2 ,
91+ )
92+
8793 @staticmethod
8894 def setup_once ():
8995 # type: () -> None
@@ -108,17 +114,18 @@ class SentryLangchainCallback(BaseCallbackHandler): # type: ignore[misc]
108114 """Callback handler that creates Sentry spans."""
109115
110116 def __init__ (self , max_span_map_size , include_prompts ):
111- # type: (int, bool) -> None
117+ # type: (Optional[ int] , bool) -> None
112118 self .span_map = OrderedDict () # type: OrderedDict[UUID, WatchedSpan]
113119 self .max_span_map_size = max_span_map_size
114120 self .include_prompts = include_prompts
115121
116122 def gc_span_map (self ):
117123 # type: () -> None
118124
119- while len (self .span_map ) > self .max_span_map_size :
120- run_id , watched_span = self .span_map .popitem (last = False )
121- self ._exit_span (watched_span , run_id )
125+ if self .max_span_map_size is not None :
126+ while len (self .span_map ) > self .max_span_map_size :
127+ run_id , watched_span = self .span_map .popitem (last = False )
128+ self ._exit_span (watched_span , run_id )
122129
123130 def _handle_error (self , run_id , error ):
124131 # type: (UUID, Any) -> None
0 commit comments