Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions sentry_sdk/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -108,17 +105,18 @@ 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

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
Expand Down