◐ Shell
clean mode source ↗

fix(langchain): filter GraphBubbleUp control-flow exceptions in _handle_error by wahajahmed010 · Pull Request #6495 · getsentry/sentry-python

Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: sentry_sdk/integrations/langchain.py#L282-L283

Potential issue: In the Langchain integration's `_handle_error` function, when an error
is an instance of `_graph_bubble_up` (a control-flow exception used in LangGraph), the
function returns early. This is correct for not capturing it as a Sentry issue, but it
skips the necessary cleanup logic that closes the span and removes it from
`self.span_map`. In applications that use features like human-in-the-loop interrupts,
this will be triggered frequently, causing the `span_map` to grow indefinitely. This
results in a memory leak, as the garbage collection for the map is disabled by default.