Skip to content

fix(server-utils): Don't capture caller-handled LangChain errors - #23593

Merged
nicohrubec merged 3 commits into
developfrom
fix/langchain-instrumentation-error-capture
Aug 26, 2026
Merged

fix(server-utils): Don't capture caller-handled LangChain errors#23593
nicohrubec merged 3 commits into
developfrom
fix/langchain-instrumentation-error-capture

Conversation

@nicohrubec

@nicohrubecnicohrubec commented Aug 25, 2026

Copy link
Copy Markdown
Member

LangChain's callback error handlers (handleLLMError, handleChainError, handleToolError) and the embeddings wrapper called captureException(error, { handled: false }). These errors reject invoke()/embedQuery() to the caller, so the instrumentation recorded an "unhandled crash" for an error the application handles. This is the same problem fixed for the OpenAI, Anthropic, and Google GenAI client wrappers in #23024.

Related to #23023

@github-actions

github-actionsBot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser28.57 kB--
@sentry/browser - with treeshaking flags26.92 kB--
@sentry/browser - with treeshaking flags tracing without tracing26.82 kB--
@sentry/browser (incl. Tracing)48.58 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.6 kB--
@sentry/browser (incl. Tracing, Profiling)51.51 kB--
@sentry/browser (incl. Tracing, Replay)88.04 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags77.44 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)92.75 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)105.44 kB--
@sentry/browser (incl. Feedback)45.81 kB--
@sentry/browser (incl. sendFeedback)33.36 kB--
@sentry/browser (incl. FeedbackAsync)38.46 kB--
@sentry/browser (incl. Metrics)29.51 kB--
@sentry/browser (incl. Logs)29.8 kB--
@sentry/browser (incl. Metrics & Logs)30.43 kB--
@sentry/react30.31 kB--
@sentry/react (incl. Tracing)50.79 kB--
@sentry/vue35.69 kB--
@sentry/vue (incl. Tracing)50.82 kB--
@sentry/svelte28.59 kB--
CDN Bundle30.36 kB--
CDN Bundle (incl. Tracing)49.07 kB--
CDN Bundle (incl. Logs, Metrics)32.56 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)50.95 kB--
CDN Bundle (incl. Replay, Logs, Metrics)72.98 kB--
CDN Bundle (incl. Tracing, Replay)86.56 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)88.44 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)92.33 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)94.25 kB--
CDN Bundle - uncompressed89.97 kB--
CDN Bundle (incl. Tracing) - uncompressed146.69 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed96.26 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed152.38 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed225.36 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed266.12 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed271.79 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed279.81 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed285.48 kB--
@sentry/nextjs (client)53.33 kB--
@sentry/sveltekit (client)49.03 kB--
@sentry/core/server65.08 kB--
@sentry/core/browser52.38 kB--
@sentry/node121.46 kB-0.03%-31 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection)85.19 kB--
@sentry/node - without tracing87.62 kB+0.03%+21 B 🔺
@sentry/aws-serverless95.77 kB+0.03%+26 B 🔺
@sentry/cloudflare (withSentry) - minified199.5 kB--
@sentry/cloudflare (withSentry)495.46 kB--

View base workflow run

nicohrubecand others added 2 commits August 26, 2026 10:45
LangChain's callback error handlers (handleLLMError, handleChainError,
handleToolError) and the embeddings wrapper called captureException with
handled: false. These errors reject invoke()/embedQuery() to the caller, so the
instrumentation recorded an "unhandled crash" for an error the application
handles, the same issue fixed for the OpenAI, Anthropic and Google GenAI client
wrappers in #23024. The span is still marked failed and the error still
propagates; only the event goes away.
The integration tests masked these with .ignore('event'); those masks are
removed so the tests no longer hide instrumentation-level captures.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t capturing
The embeddings wrapper no longer records caller-handled errors, so the unit test
now asserts the error propagates and captureException is not called.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicohrubec
nicohrubecforce-pushed the fix/langchain-instrumentation-error-capture branch from a843a9f to 797b166CompareAugust 26, 2026 08:46

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 797b166. Configure here.

Comment threadpackages/server-utils/src/ai/langchain/embeddings.ts
…embeddings auto-instrumentation
The Node diagnostics-channel path for embedQuery/embedDocuments passed
captureError with handled: false into bindTracingChannelToSpan, so it still
recorded caller-handled embedding errors as unhandled crashes even after the
manual instrumentEmbeddingMethod wrapper stopped. Drop captureError; the span is
still marked failed on error and the rejection propagates to the caller.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nicohrubec
nicohrubec marked this pull request as ready for review August 26, 2026 09:24
@nicohrubec
nicohrubec requested review from a team as code ownersAugust 26, 2026 09:24
@nicohrubec
nicohrubec requested review from JPeer264, andreiborza and isaacs and removed request for a teamAugust 26, 2026 09:24
@nicohrubec
nicohrubec merged commit 3ff658e into developAug 26, 2026
201 checks passed
@nicohrubec
nicohrubec deleted the fix/langchain-instrumentation-error-capture branch August 26, 2026 09:36
nicohrubec added a commit that referenced this pull request Aug 26, 2026
)
LangGraph's compiled-graph invoke wrapper and tool-node wrapper called
`captureException(error, { handled: false })` and then rethrew. The
error rejects `invoke()` to the caller, so the instrumentation recorded
an "unhandled crash" for an error the application handles. This is the
same problem fixed for the OpenAI, Anthropic, and Google GenAI client
wrappers in #23024, and for LangChain in #23593.
Related to #23023
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
nicohrubec added a commit that referenced this pull request Aug 26, 2026
Backport of: #23593
## Differences to the original PR
- On v10 the LangChain instrumentation lives in
`packages/core/src/tracing/langchain/` (it moved to
`@sentry/server-utils` on v11), so the callback-handler and embeddings
changes are applied there with v10's internal imports.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@nicohrubec@andreiborza