From 1297682ee7b770b794f729db62c56006521d2d6c Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 30 Oct 2025 11:27:01 +0100 Subject: [PATCH] chore(langchain): Remove integration span limit by default --- sentry_sdk/integrations/langchain.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 1f5b41bd43..4947213da8 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -76,11 +76,8 @@ class LangchainIntegration(Integration): identifier = "langchain" origin = f"auto.ai.{identifier}" - # The most number of spans (e.g., LLM calls) that can be processed at the same time. - max_spans = 1024 - - def __init__(self, include_prompts=True, max_spans=1024): - # type: (LangchainIntegration, bool, int) -> None + def __init__(self, include_prompts=True, max_spans=None): + # type: (LangchainIntegration, bool, Optional[int]) -> None self.include_prompts = include_prompts self.max_spans = max_spans @@ -108,7 +105,7 @@ class SentryLangchainCallback(BaseCallbackHandler): # type: ignore[misc] """Callback handler that creates Sentry spans.""" def __init__(self, max_span_map_size, include_prompts): - # type: (int, bool) -> None + # type: (Optional[int], bool) -> None self.span_map = OrderedDict() # type: OrderedDict[UUID, WatchedSpan] self.max_span_map_size = max_span_map_size self.include_prompts = include_prompts @@ -116,9 +113,10 @@ def __init__(self, max_span_map_size, include_prompts): def gc_span_map(self): # type: () -> None - while len(self.span_map) > self.max_span_map_size: - run_id, watched_span = self.span_map.popitem(last=False) - self._exit_span(watched_span, run_id) + if self.max_span_map_size: + while len(self.span_map) > self.max_span_map_size: + run_id, watched_span = self.span_map.popitem(last=False) + self._exit_span(watched_span, run_id) def _handle_error(self, run_id, error): # type: (UUID, Any) -> None