Title: `instrumentLangGraph` and `createLangChainCallbackHandler` silently drop spans when used together · Issue #19627 · getsentry/sentry-javascript · GitHub
Open Graph Title: `instrumentLangGraph` and `createLangChainCallbackHandler` silently drop spans when used together · Issue #19627 · getsentry/sentry-javascript
X Title: `instrumentLangGraph` and `createLangChainCallbackHandler` silently drop spans when used together · Issue #19627 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
X Description: Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/19627
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`instrumentLangGraph` and `createLangChainCallbackHandler` silently drop spans when used together","articleBody":"### Is there an existing issue for this?\n\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/browser\n\n### SDK Version\n\n^10.40.0\n\n### Framework Version\n\n_No response_\n\n### Link to Sentry event\n\nhttps://pri-dogfooding-ai.sentry.io/insights/ai-agents/?project=4510951776059472&statsPeriod=30d&trace=043dd6239e7645d9b70f641fe3ec2f83&span=undefined&trace-timestamp=1772622191\n\n### Reproduction Example/SDK Setup\n\n_No response_\n\n### Steps to Reproduce\n\n```js\nconst graph = new StateGraph(IdeaState)\n .addNode(\"expand\", expandNode) // calls llm.invoke()\n .addNode(\"validate\", validateNode) // calls llm.invoke()\n .addNode(\"differentiate\", diffNode) // calls llm.invoke()\n .addNode(\"roadmap\", roadmapNode) // calls llm.invoke()\n .addNode(\"pitch\", pitchNode) // calls llm.invoke()\n .addEdge(START, \"expand\")\n .addEdge(\"expand\", \"validate\")\n .addEdge(\"validate\", \"differentiate\")\n .addEdge(\"differentiate\", \"roadmap\")\n .addEdge(\"roadmap\", \"pitch\")\n .addEdge(\"pitch\", END);\n\nSentry.instrumentLangGraph(graph, { recordInputs: true, recordOutputs: true });\nconst compiled = graph.compile({ name: \"idea-forge\" });\n\nconst sentryHandler = Sentry.createLangChainCallbackHandler({\n recordInputs: true,\n recordOutputs: true,\n});\nconst result = await compiled.invoke({ idea: \"test\" }, { callbacks: [sentryHandler] });\n```\n\n### Expected Result\n\nAll 5 LLM calls should produce `chat` spans in the trace.\n\n### Actual Result\n\n| Setup | `chat` spans captured |\n|-------|----------------------|\n| `instrumentLangGraph` + `createLangChainCallbackHandler` | **1 out of 5** |\n| `createLangChainCallbackHandler` only | 5 out of 5 |\n| `instrumentLangGraph` only | 0 (expected — no callback handler) |\n\n4 out of 5 `chat` spans are silently dropped with no error or warning.\n\nAdditionally, the trace contains multiple spurious nested `invoke_agent` sub-spans with near-zero durations (0.20ms) that should not exist:\n\n```\ninvoke_agent idea-forge 7.43s ← top-level (expected)\n invoke_agent idea-forge 2.70ms ← spurious\n invoke_agent idea-forge 1.60ms ← spurious\n invoke_agent idea-forge 0.20ms ← spurious\n invoke_agent idea-forge 4.41s\n chat claude-haiku-4-5-20251001 4.41s ← only 1 of 5 chat spans\n invoke_agent idea-forge 0.20ms ← spurious\n invoke_agent idea-forge 0.20ms ← spurious\n```\n\n### Additional Context\n\n**Possible Root Cause:**\n\n`instrumentLangGraph` wraps `invoke()` inside `Sentry.startSpan()`. As async execution passes through sequential nodes, the span context from `startSpan` is not consistently maintained across all node invocations. Some `handleChatModelStart` callbacks from the handler fire outside an active span context and their spans are dropped.\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>","author":{"url":"https://github.com/priscilawebdev","@type":"Person","name":"priscilawebdev"},"datePublished":"2026-03-04T11:11:24Z","url":"https://github.com/getsentry/sentry-javascript/issues/19627"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e4d6c258-aebb-985c-9eaa-6f32609b3f02 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 90B4:267483:15CCF:1DD32:6B042B1C |
| html-safe-nonce | 99cc795b9a1028fc7513f72654ea56e34f403d3f5ce15221aa47a1a5455cc57a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MEI0OjI2NzQ4MzoxNUNDRjoxREQzMjo2QjA0MkIxQyIsInZpc2l0b3JfaWQiOiI2MDY3NTcxNzIxODY1ODAwNDc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 54c970ffbfbed4873d8d78ca2f86197c28a8116c1e8ffea88010774fdc4877a9 |
| hovercard-subject-tag | issue:4021436388 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/19627/issue_layout |
| twitter:image | https://opengraph.githubassets.com/738c6e0cd267b3ceb881b6f331aec1c968f9dbec2944954760643fa463ed590d/getsentry/sentry-javascript/issues/19627 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/738c6e0cd267b3ceb881b6f331aec1c968f9dbec2944954760643fa463ed590d/getsentry/sentry-javascript/issues/19627 |
| og:image:alt | Is there an existing issue for this? I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I have reviewed the documentation https://docs.sentry.io/ I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | priscilawebdev |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width