From 49b1a5b00505d055e4a21e2e492f251099f1f2c8 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 6 Nov 2025 09:07:00 +0100 Subject: [PATCH 1/3] chore: Deprecate maximum lanchain spans option --- sentry_sdk/integrations/langchain.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 1f5b41bd43..53ea6cdc34 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -1,4 +1,5 @@ import itertools +import warnings from collections import OrderedDict from functools import wraps @@ -76,14 +77,19 @@ 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): + def __init__(self, include_prompts=True, max_spans=None): # type: (LangchainIntegration, bool, int) -> None self.include_prompts = include_prompts self.max_spans = max_spans + if max_spans is not None: + warnings.warn( + "The `max_spans` parameter of the `LangchainIntegration` constructor is" + "deprecated and will be removed in version 3.0 of sentry-sdk.", + DeprecationWarning, + stacklevel=2, + ) + @staticmethod def setup_once(): # type: () -> None @@ -108,7 +114,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 +122,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 is not 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) def _handle_error(self, run_id, error): # type: (UUID, Any) -> None From 144b69130485174021461933503643bdee06a301 Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 6 Nov 2025 09:35:21 +0100 Subject: [PATCH 2/3] . --- sentry_sdk/integrations/langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 53ea6cdc34..2a930cd9a6 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -78,7 +78,7 @@ class LangchainIntegration(Integration): origin = f"auto.ai.{identifier}" def __init__(self, include_prompts=True, max_spans=None): - # type: (LangchainIntegration, bool, int) -> None + # type: (LangchainIntegration, bool, Optional[int]) -> None self.include_prompts = include_prompts self.max_spans = max_spans From 726a4a13e1a457b1fcc28e73ede6333094ee431d Mon Sep 17 00:00:00 2001 From: Alexander Alderman Webb Date: Thu, 6 Nov 2025 09:36:25 +0100 Subject: [PATCH 3/3] . --- sentry_sdk/integrations/langchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 2a930cd9a6..04bf153519 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -84,7 +84,7 @@ def __init__(self, include_prompts=True, max_spans=None): if max_spans is not None: warnings.warn( - "The `max_spans` parameter of the `LangchainIntegration` constructor is" + "The `max_spans` parameter of `LangchainIntegration` is " "deprecated and will be removed in version 3.0 of sentry-sdk.", DeprecationWarning, stacklevel=2,