Skip to content

fix(node): Use context-scoped suppression for LangChain + AI provider span deduplication#19688

Draft
nicohrubec wants to merge 5 commits intodevelopfrom
nh/deduplicate-agent-client-spans
Draft

fix(node): Use context-scoped suppression for LangChain + AI provider span deduplication#19688
nicohrubec wants to merge 5 commits intodevelopfrom
nh/deduplicate-agent-client-spans

Conversation

@nicohrubec
Copy link
Copy Markdown
Member

When both LangChain and an AI provider integration (OpenAI, Anthropic, Google GenAI) are active, a single LangChain invoke() call produces duplicate gen_ai.chat spans — one from LangChain's callback handler and one from the underlying provider instrumentation.

The previous fix globally disabled provider instrumentations when LangChain was detected, but this broke direct provider SDK calls unrelated to LangChain.

This PR sets a suppression flag on the current scope during LangChain invoke/stream/batch execution. Provider instrumentations check this flag and skip span creation if set.

Closes #19687

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 6, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 25.64 kB +0.05% +12 B 🔺
@sentry/browser - with treeshaking flags 24.14 kB +0.03% +7 B 🔺
@sentry/browser (incl. Tracing) 42.44 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Profiling) 47.1 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Replay) 81.26 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.88 kB +0.02% +8 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 85.95 kB +0.02% +9 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 98.21 kB +0.01% +7 B 🔺
@sentry/browser (incl. Feedback) 42.44 kB +0.02% +7 B 🔺
@sentry/browser (incl. sendFeedback) 30.31 kB +0.04% +11 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.36 kB +0.04% +11 B 🔺
@sentry/browser (incl. Metrics) 26.8 kB +0.04% +9 B 🔺
@sentry/browser (incl. Logs) 26.95 kB +0.03% +8 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.62 kB +0.04% +9 B 🔺
@sentry/react 27.39 kB +0.04% +9 B 🔺
@sentry/react (incl. Tracing) 44.78 kB +0.02% +8 B 🔺
@sentry/vue 30.09 kB +0.04% +10 B 🔺
@sentry/vue (incl. Tracing) 44.31 kB +0.03% +9 B 🔺
@sentry/svelte 25.66 kB +0.04% +9 B 🔺
CDN Bundle 28.18 kB +0.04% +9 B 🔺
CDN Bundle (incl. Tracing) 43.27 kB +0.03% +11 B 🔺
CDN Bundle (incl. Logs, Metrics) 29.02 kB +0.04% +9 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 44.11 kB +0.03% +10 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 68.1 kB +0.02% +8 B 🔺
CDN Bundle (incl. Tracing, Replay) 80.15 kB +0.02% +12 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 81.01 kB +0.02% +10 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.66 kB +0.02% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.54 kB +0.02% +10 B 🔺
CDN Bundle - uncompressed 82.38 kB +0.04% +26 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 128.09 kB +0.03% +26 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.21 kB +0.04% +26 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.93 kB +0.02% +26 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.88 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.98 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.8 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.89 kB +0.02% +26 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.7 kB +0.01% +26 B 🔺
@sentry/nextjs (client) 47.19 kB +0.02% +9 B 🔺
@sentry/sveltekit (client) 42.9 kB +0.02% +8 B 🔺
@sentry/node-core 52.24 kB - -
@sentry/node 174.75 kB +0.03% +42 B 🔺
@sentry/node - without tracing 97.41 kB +0.03% +24 B 🔺
@sentry/aws-serverless 113.21 kB +0.02% +18 B 🔺

View base workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,941 - 8,786 +2%
GET With Sentry 1,619 18% 1,661 -3%
GET With Sentry (error only) 5,965 67% 6,004 -1%
POST Baseline 1,141 - 1,166 -2%
POST With Sentry 568 50% 536 +6%
POST With Sentry (error only) 1,026 90% 1,032 -1%
MYSQL Baseline 3,227 - 3,173 +2%
MYSQL With Sentry 418 13% 361 +16%
MYSQL With Sentry (error only) 2,619 81% 2,571 +2%

View base workflow run

Copy link
Copy Markdown
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

This is great! Can you also please adapt https://github.com/getsentry/sentry-javascript/blob/develop/.agents/skills/add-ai-integration/SKILL.md to mention that lowest-level ai integrations have to check for suppression?

And also, we can add a rule to bugbot to specifically lint for this, see https://github.com/getsentry/sentry-javascript/blob/develop/.cursor/BUGBOT.md#auto-instrumentation-sdk-integrations-sentry-specific-conventions as an example.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you apply the label PR: no-auto-close I will leave it alone ... forever!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Bun

  • Add bunRuntimeMetricsIntegration by chargome in #19979
  • Set http response header attributes instead of response context headers by Lms24 in #19821

Core

  • Support registerTool/registerResource/registerPrompt in MCP integration by betegon in #20071
  • Support embeddings in langchain by nicohrubec in #20017
  • Support embedding APIs in google-genai by nicohrubec in #19797
  • Add sentry.timestamp.sequence attribute for timestamp tie-breaking by logaretm in #19421

Deno

  • Add denoRuntimeMetricsIntegration by chargome in #20023
  • Set http response header attributes instead of response context headers by Lms24 in #19822

Deps

  • Bump lodash.template from 4.5.0 to 4.18.1 by dependabot in #20085
  • Bump @xmldom/xmldom from 0.8.3 to 0.8.12 by dependabot in #20066
  • Bump OpenTelemetry dependencies by andreiborza in #20046
  • Bump babel-loader from 10.0.0 to 10.1.1 by dependabot in #19997
  • Bump handlebars from 4.7.7 to 4.7.9 by dependabot in #20008
  • Bump mongodb-memory-server-global from 10.1.4 to 11.0.1 by dependabot in #19888
  • Bump stacktrace-parser from 0.1.10 to 0.1.11 by dependabot in #19887
  • Bump yauzl from 3.2.0 to 3.2.1 by dependabot in #19809
  • Bump mysql2 from 3.14.4 to 3.19.1 by dependabot in #19787
  • Bump OpenTelemetry dependencies by andreiborza in #19682
  • Bump hono from 4.12.5 to 4.12.7 by dependabot in #19747
  • Bump simple-git from 3.30.0 to 3.33.0 by dependabot in #19744

Nestjs

  • Instrument @nestjs/bullmq by nicohrubec in #19759
  • Use more specific span origins for NestJS guards, pipes, interceptors, and exception filters by nicohrubec in #19751
  • Instrument @nestjs/schedule decorators by nicohrubec in #19735

Node

  • Add nodeRuntimeMetricsIntegration by chargome in #19923
  • Avoid OTEL instrumentation for outgoing requests on Node 22+ by mydea in #17355
  • Expose headersToSpanAttributes option on nativeNodeFetchIntegration by andreiborza in #19770

Nuxt

  • Add middleware instrumentation compatibility for Nuxt 5 by s1gr1d in #19968
  • Support parametrized SSR routes in Nuxt 5 by s1gr1d in #19977
  • Conditionally use plugins based on Nitro version (v2/v3) by s1gr1d in #19955

Other

  • (astro) Add Astro 6 support by Lms24 in #19745
  • (browser) Replace element timing spans with metrics by logaretm in #19869
  • (browser/cloudflare) Export conversation id from browser and cloudflare runtimes by nicohrubec in #19820
  • (cloudflare) Support basic WorkerEntrypoint by JPeer264 in #19884
  • (core, node) Portable Express integration by isaacs in #19928
  • (effect) Add @sentry/effect SDK (alpha) by JPeer264 in #19644
  • (elysia) Elysia SDK by logaretm in #19509
  • (hono) Add basic instrumentation for Node runtime by s1gr1d in #19817
  • (nextjs) Vercel queue instrumentation by chargome in #19799
  • (node-core) Add OTLP integration for node-core/light by andreiborza in #19729
  • (node, bun) Enforce minimum collection interval in runtime metrics integrations by chargome in #20068
  • (remix) Server Timing Headers Trace Propagation by onurtemizkan in #18653
  • (solid) Add route parametrization for Solid Router by andreiborza in #20031

Bug Fixes 🐛

Ci

  • Update validate-pr action to remove draft enforcement by stephanie-anderson in #20037
  • Update validate-pr action to remove draft enforcement by stephanie-anderson in #20035

Cloudflare

  • Ensure every request instruments functions by JPeer264 in #20044
  • Send correct events in local development by JPeer264 in #19900
  • Forward ctx argument to Workflow.do user callback by Lms24 in #19891
  • Use correct env types for withSentry by JPeer264 in #19836
  • Recreate client when previous one was disposed by JPeer264 in #19727

Core

  • Replace regex with string check in stack parser to prevent main thread blocking by chargome in #20089
  • Set span.status to error when MCP tool returns JSON-RPC error response by betegon in #20082
  • Guard nullish response in supabase PostgREST handler by antonis in #20033
  • Preserve .withResponse() on Anthropic instrumentation by nicohrubec in #19935
  • Truncate content array format in Vercel by nicohrubec in #19911
  • Send internal_error as span status for Vercel error spans by nicohrubec in #19921
  • Do not overwrite user provided conversation id in Vercel by nicohrubec in #19903
  • Return same value from startSpan as callback returns by s1gr1d in #19300
  • Align error span status message with core SpanStatusType for langchain/google-genai by nicohrubec in #19863
  • Fallback to sendDefaultPii setting in langchain and langgraph in non-node environments by nicohrubec in #19813
  • Align Vercel embedding spans with semantic conventions by nicohrubec in #19795
  • Improve Vercel AI SDK instrumentation attributes by RulaKhaled in #19717

Deps

  • Update lockfile to resolve h3@1.15.10 by chargome in #19933
  • Bump fast-xml-parser to 5.5.8 in @azure/core-xml chain by chargome in #19918
  • Bump next to 15.5.14 in nextjs-15 and nextjs-15-intl E2E test apps by chargome in #19917
  • Bump socket.io-parser to 4.2.6 to fix CVE-2026-33151 by chargome in #19880
  • Bump next to 15.5.13/16.1.7 to fix CVE-2026-1525, CVE-202-33036 and related by chargome in #19870
  • Bump devalue 5.6.3 to 5.6.4 to fix CVE-2026-30226 by chargome in #19849
  • Bump file-type to 21.3.2 and @nestjs/common to 11.1.17 by chargome in #19847
  • Bump unhead 2.1.4 to 2.1.12 to fix CVE-2026-31860 and CVE-2026-31873 by chargome in #19848
  • Bump flatted 3.3.1 to 3.4.2 to fix CVE-2026-32141 by chargome in #19842
  • Bump tar 7.5.10 to 7.5.11 to fix CVE-2026-31802 by chargome in #19846
  • Bump hono 4.12.5 to 4.12.7 in cloudflare-hono E2E test app by chargome in #19850
  • Bump undici 6.23.0 to 6.24.1 to fix multiple CVEs by chargome in #19841

Hono

  • Align error mechanism by s1gr1d in #19831
  • Allow passing env and fix type issues by s1gr1d in #19825

Nestjs

  • Add node to nest metadata by chargome in #19875
  • Fork isolation scope in @nestjs/event-emitter instrumentation by nicohrubec in #19725

Nextjs

  • Skip tracing for tunnel requests by chargome in #19861
  • Strip sourceMappingURL comments after deleting source maps in turbopack builds by chargome in #19814
  • Log correct lastEventId when error is thrown in component render by s1gr1d in #19764

Node

  • Use context-scoped suppression for LangChain + AI provider span deduplication by nicohrubec in #19688
  • Deduplicate sentry-trace and baggage headers on outgoing requests by Lms24 in #19960
  • Ensure startNewTrace propagates traceId in OTel environments by logaretm in #19963

Nuxt

  • Use virtual module for Nuxt pages data (SSR route parametrization) by s1gr1d in #20020
  • Upload client source maps by s1gr1d in #19805

Other

  • (aws-serverless) Add timeout to _endSpan forceFlush to prevent Lambda hanging by logaretm in #20064
  • (browser) Skip browserTracingIntegration setup for bot user agents by chargome in #19708
  • (browser-tests) Pin axios to 1.13.5 to avoid compromised 1.14.1 by andreiborza in #20047
  • (craft) Add missing mainDocsUrl for @sentry/effect SDK by bc-sentry in #19860
  • (deno) Clear pre-existing OTel global before registering TracerProvider by sergical in #19723
  • (e2e) Pin @opentelemetry/api to 1.9.0 in ts3.8 test app by logaretm in #19992
  • (gatsby) Fix errorHandler signature to match bundler-plugin-core API by JPeer264 in #20048
  • (node-core) Recycle propagationContext for each request by Lms24 in #19835
  • (opentelemetry) Convert seconds timestamps in span.end() to milliseconds by logaretm in #19958
  • (profiling) Disable profiling in worker threads by chargome in #20040
  • (profiling-node) Fix NODE_VERSION rendered as [object Object] in warning by logaretm in #19788
  • (react-router) Disable debug ID injection in Vite plugin to prevent double injection by isaacs in #19890
  • (serverless) Add node to metadata by nicohrubec in #19878

Documentation 📚

New Release

  • Document sdkName for craft by s1gr1d in #19736
  • Update docs based on new Craft flow by s1gr1d in #19731

Other

  • (changelog) Add entry for @sentry/hono alpha release by s1gr1d in #19828
  • (hono) Document usage without "*" by s1gr1d in #19756
  • (release) Update publishing-a-release.md by nicohrubec in #19982

Internal Changes 🔧

Browser

  • Reduce browser package bundle size by HazAT in #19856
  • Add simulated mfe integration test by chargome in #19768

Changelog

  • Update changelog for 10.47.0 by chargome in #20050
  • Update changelog for 10.46.0 by nicohrubec in #19973
  • Add changelog for 10.45.0 by Lms24 in #19877
  • Update changelog for 10.44.0 by JPeer264 in #19843

Ci

  • Fix "Gatbsy" typo in issue package label workflow by chargome in #19905
  • Extract metadata workflow by chargome in #19680

Cloudflare

  • Enable multi-worker tests for CF integration tests by JPeer264 in #19938
  • Prepare for WorkerEntrypoint by JPeer264 in #19742

Core

  • Do not emit spans for chats.create in google-genai by nicohrubec in #19990
  • Unify .do* span ops to gen_ai.generate_content by nicohrubec in #20074
  • Simplify addResponseAttributes in openai integration by nicohrubec in #20013
  • Extract shared endStreamSpan for AI integrations by nicohrubec in #20021
  • Remove provider-specific AI span attributes in favor of gen_ai attributes in sentry conventions by nicohrubec in #20011
  • Introduce instrumented method registry for AI integrations by nicohrubec in #19981
  • Consolidate getOperationName into one shared utility by nicohrubec in #19971
  • Remove duplicate buildMethodPath utility from openai by nicohrubec in #19969
  • Simplify core utility functions for smaller bundle by HazAT in #19854
  • Fix flaky metric sequence number test by nicohrubec in #19754

Deps

  • Bump mshick/add-pr-comment from dd126dd8c253650d181ad9538d8b4fa218fc31e8 to e7516d74559b5514092f5b096ed29a629a1237c6 by dependabot in #20078
  • Bump getsentry/craft/.github/workflows/changelog-preview.yml from 2.24.1 to 2.25.2 by dependabot in #20081
  • Bump amqplib from 0.10.7 to 0.10.9 by dependabot in #20000
  • Bump actions/upload-artifact from 6 to 7 by dependabot in #19569
  • Bump srvx from 0.11.12 to 0.11.13 by dependabot in #20001
  • Bump @apollo/server from 5.4.0 to 5.5.0 by dependabot in #20007
  • Bump next from 16.1.5 to 16.1.7 in /dev-packages/e2e-tests/test-applications/nextjs-16 by dependabot in #19851
  • Bump tedious from 18.6.1 to 19.2.1 by dependabot in #19786

Deps Dev

  • Remove esbuild override in astro-5-cf-workers E2E test by isaacs in #20024
  • Bump node-forge from 1.3.2 to 1.4.0 by dependabot in #20012
  • Bump yaml from 2.8.2 to 2.8.3 by dependabot in #19985
  • Bump effect from 3.19.19 to 3.20.0 by dependabot in #19926
  • Bump qunit-dom from 3.2.1 to 3.5.0 by dependabot in #19546
  • Bump @react-router/node from 7.13.0 to 7.13.1 by dependabot in #19544
  • Bump file-type from 20.5.0 to 21.3.1 by dependabot in #19748

E2e

  • Add e2e tests for nodeRuntimeMetricsIntegration by chargome in #19989
  • Add MFE e2e test using vite-plugin-federation by chargome in #19778

Lint

  • Resolve oxlint warnings by isaacs in #19893
  • Rule adjustments and fix warnings by logaretm in #19612

Nextjs

  • Skip broken ISR tests by chargome in #19871
  • Add vercel queue tests to next-16 by chargome in #19798

Nuxt

  • Make Nuxt 5 (nightly) E2E optional by s1gr1d in #20113
  • Extract core logic for storage/database to prepare for Nuxt v5 by s1gr1d in #19920
  • Extract handler patching to extra plugin for Nitro v2/v3 by s1gr1d in #19915

Other

  • (agents) Be more explicit on linting and formatting by chargome in #19803
  • (astro) Re-enable server island tracing e2e test in Astro 6 by Lms24 in #19872
  • (astro,cloudflare) Add an E2E test for Astro 6 on Cloudflare by JPeer264 in #19781
  • (browser-tests) Add waitForMetricRequest helper by logaretm in #20002
  • (claude) Enable Claude Code Intelligence (LSP) by s1gr1d in #19930
  • (deno) Expand Deno E2E test coverage by chargome in #19957
  • (effect) Add Effect to craft, README and issue templates by JPeer264 in #19837
  • (elysia) Drop @elysiajs/opentelemetry dependency by logaretm in #19947
  • (gitflow) Sync master with develop by chargome in #20054
  • (nestjs) Move event instrumentation unit tests to separate file by nicohrubec in #19738
  • (node) Add node integration tests for Vercel ToolLoopAgent by nicohrubec in #20087
  • (node-integration-tests) Remove unnecessary file-type dependency by Lms24 in #19824
  • (react) Add gql tests for react router by chargome in #19844
  • (release) Switch from action-prepare-release to Craft by BYK in #18763
  • (remix) Replace glob with native recursive fs walk by roli-lpci in #19531
  • (skills) Add skill-creator and update managed agent skills by chargome in #19713
  • (sveltekit) Replace recast + @babel/parser with acorn by roli-lpci in #19533
  • Update validate-pr workflow by stephanie-anderson in #20072
  • Remove unused tsconfig-template folder by mydea in #20067
  • Add external contributor to CHANGELOG.md by javascript-sdk-gitflow in #19925
  • Add external contributor to CHANGELOG.md by javascript-sdk-gitflow in #19909
  • Add oxlint migration commits to blame ignore by logaretm in #19784
  • Bump oxlint and oxfmt by logaretm in #19771
  • Clean up lint and format script names by logaretm in #19719
  • Add oxlint typescript program suppression to workspace settings by logaretm in #19692
  • Auto changes made from "yarn fix" by JPeer264 in #19710

Other

  • [Gitflow] Merge master into develop by javascript-sdk-gitflow in #19980
  • [Gitflow] Merge master into develop by javascript-sdk-gitflow in #19882
  • [Gitflow] Merge master into develop by javascript-sdk-gitflow in #19857

🤖 This preview updates automatically when you update the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI provider spans are suppressed globally when LangChain integration is active

2 participants