Skip to content

Commit 25999b5

Browse files
chore: Deprecate max_spans LangChain parameter (#5074)
Set the default value of the `max_spans` parameter of `LangchainIntegration` to `None`, so that LangChain spans are not exited early by default. Deprecate the parameter and announce its removal in the next major release. Closes #4985
1 parent c4d0ba8 commit 25999b5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

sentry_sdk/integrations/langchain.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
import warnings
23
from collections import OrderedDict
34
from 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

Comments
 (0)