Skip to content

feat(core)!: Remove enableTruncation flag and gen_ai text truncation#22516

Draft
nicohrubec wants to merge 3 commits into
feat/remove-stream-gen-ai-spans-flagfrom
feat/remove-enable-truncation-flag
Draft

feat(core)!: Remove enableTruncation flag and gen_ai text truncation#22516
nicohrubec wants to merge 3 commits into
feat/remove-stream-gen-ai-spans-flagfrom
feat/remove-enable-truncation-flag

Conversation

@nicohrubec

Copy link
Copy Markdown
Member

Stacked on #22495. Removes the enableTruncation integration option and the gen_ai message text-truncation machinery, while keeping (and fixing) inline media stripping.

Now that gen_ai spans always ride the v2 span path — which has far larger size limits than legacy transactions — the byte-limit text cropping and the "keep only the last message" reduction that existed to fit gen_ai payloads into transaction size limits are dead weight. This is a follow-up to the streamGenAiSpans removal.

Decisions

  • Media stripping is now unconditional — this fixes a latent leak. Previously, for openai/anthropic/google-genai/vercel-ai/workers-ai, inline media was only stripped on the getTruncatedJsonString path. With truncation off (the default since streamGenAiSpans shipped), inline base64 blobs could leak into span attributes for those providers. getGenAiMessagesJsonString (the replacement) always strips inline media before serializing. langchain/langgraph already stripped media independently via normalizeContent, so they were unaffected and keep that path.
  • All messages are now kept. Text truncation used to keep only the last message; the new path serializes every message (with inline media stripped). Integration/unit tests were updated to assert this new behavior — e.g. the anthropic media test now expects both messages, not just the last.
  • sentry.sdk_meta.gen_ai.input.messages.original_length removed. It existed only to signal that truncation dropped messages; with no truncation it would always equal the real count.
  • Scope covers both @sentry/core and @sentry/server-utils (the tracing-channel + vercel-ai dc-subscriber implementations).
  • enableTruncation and this cleanup were pre-noted in MIGRATION.md, so that file is left as-is.

Structure

  • Media-stripping logic is consolidated into mediaStripping.ts (stripInlineMediaFromMessages moved there and exported); messageTruncation.ts is deleted.
  • Truncation-specific test scenarios/instruments are removed; the image-stripping tests are re-pointed at the default recording instruments (instrument-with-pii.mjs) since stripping no longer depends on a truncation flag.

Removes the `enableTruncation` integration option and the gen_ai message
text-truncation machinery. Now that gen_ai spans always ride the v2 span
path (which has far larger size limits than legacy transactions), the
byte-limit text cropping and "keep only the last message" behavior that
existed to fit gen_ai payloads into transaction size limits is no longer
needed.

Inline media stripping is kept and, importantly, is now unconditional.
Previously image/media stripping was entangled with truncation: for
openai/anthropic/google-genai/vercel-ai/workers-ai it only happened on the
`getTruncatedJsonString` path, so with truncation off (the default) inline
base64 blobs could leak into span attributes. `getGenAiMessagesJsonString`
now always strips inline media before serializing, keeping all messages.

Also removes the now-meaningless
`sentry.sdk_meta.gen_ai.input.messages.original_length` attribute (it only
ever signaled that truncation dropped messages).

Media-stripping logic is consolidated into `mediaStripping.ts`;
`messageTruncation.ts` is deleted. Truncation-specific test scenarios and
instruments are removed, and the image-stripping tests are re-pointed at
the default recording instruments.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot 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 b75fca6. Configure here.

Comment thread packages/core/src/server-exports.ts
@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.77 kB -0.06% -16 B 🔽
@sentry/browser - with treeshaking flags 26.21 kB -0.06% -14 B 🔽
@sentry/browser (incl. Tracing) 46.29 kB -0.04% -16 B 🔽
@sentry/browser (incl. Tracing + Span Streaming) 48.08 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.12 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay) 85.57 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.21 kB -0.02% -11 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 90.28 kB -0.02% -12 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 102.93 kB -0.04% -32 B 🔽
@sentry/browser (incl. Feedback) 44.96 kB +0.01% +3 B 🔺
@sentry/browser (incl. sendFeedback) 32.57 kB -0.05% -14 B 🔽
@sentry/browser (incl. FeedbackAsync) 37.63 kB -0.01% -2 B 🔽
@sentry/browser (incl. Metrics) 28.86 kB -0.06% -17 B 🔽
@sentry/browser (incl. Logs) 29.08 kB -0.09% -24 B 🔽
@sentry/browser (incl. Metrics & Logs) 29.78 kB -0.06% -16 B 🔽
@sentry/react 29.56 kB -0.09% -24 B 🔽
@sentry/react (incl. Tracing) 48.59 kB -0.02% -5 B 🔽
@sentry/vue 33.2 kB -0.06% -18 B 🔽
@sentry/vue (incl. Tracing) 48.25 kB -0.05% -20 B 🔽
@sentry/svelte 27.79 kB -0.07% -19 B 🔽
CDN Bundle 30.1 kB -0.02% -5 B 🔽
CDN Bundle (incl. Tracing) 48.16 kB -0.02% -7 B 🔽
CDN Bundle (incl. Logs, Metrics) 31.69 kB -0.02% -4 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) 49.48 kB -0.02% -5 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 70.95 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay) 85.72 kB -0.01% -6 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.02 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 91.5 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.78 kB - -
CDN Bundle - uncompressed 89.72 kB -0.04% -33 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 144.82 kB -0.03% -33 B 🔽
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.43 kB -0.04% -33 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.8 kB -0.03% -33 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.19 kB -0.02% -33 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.06 kB -0.02% -33 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.02 kB -0.02% -33 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.76 kB -0.02% -33 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.71 kB -0.02% -33 B 🔽
@sentry/nextjs (client) 51.1 kB -0.06% -26 B 🔽
@sentry/sveltekit (client) 46.71 kB -0.08% -33 B 🔽
@sentry/core/server 79.31 kB -1.1% -878 B 🔽
@sentry/core/browser 51.98 kB -0.03% -14 B 🔽
@sentry/node 123.44 kB -0.71% -877 B 🔽
@sentry/node (incl. diagnostics channel injection) 148.85 kB -0.59% -883 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB +0.01% +2 B 🔺
@sentry/node - without tracing 74.43 kB +0.03% +19 B 🔺
@sentry/aws-serverless 83.92 kB +0.01% +7 B 🔺
@sentry/cloudflare (withSentry) - minified 194.38 kB -1.15% -2.26 kB 🔽
@sentry/cloudflare (withSentry) 477.98 kB -1.22% -5.89 kB 🔽

View base workflow run

nicohrubec and others added 2 commits July 23, 2026 11:14
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The deleted truncation tests were the only ones exercising
`traceLifecycle: 'stream'` for openai/anthropic/google-genai/langchain/
langgraph gen_ai spans. Re-point the (otherwise orphaned)
scenario-span-streaming.mjs + instrument-streaming.mjs at a new
non-truncation test per provider that asserts full gen_ai input messages
are recorded under span streaming.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to 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.

1 participant