Skip to content

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

Draft
nicohrubec wants to merge 1 commit 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 1 commit 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.

GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE,
} from './tracing/ai/gen-ai-attributes';
export { getGenAiMessagesJsonString, resolveAIRecordingOptions } from './tracing/ai/utils';
export { GEN_AI_REQUEST_MODEL_ATTRIBUTE, GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE } from './tracing/ai/gen-ai-attributes';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Incomplete public API migration notes

Medium Severity

This is flagged because of the Breaking Changes rule in the review guidelines. Public exports getTruncatedJsonString, shouldEnableTruncation, and GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE are removed, and public helpers like addOpenAiRequestAttributes change signature, but MIGRATION.md only mentions the enableTruncation flag. Downstream importers and anyone querying sentry.sdk_meta.gen_ai.input.messages.original_length get no migration guidance.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit b75fca6. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.75 kB added added
@sentry/browser - with treeshaking flags 26.18 kB added added
@sentry/browser (incl. Tracing) 46.58 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.39 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.38 kB added added
@sentry/browser (incl. Tracing, Replay) 85.82 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.46 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 90.54 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 103.2 kB added added
@sentry/browser (incl. Feedback) 44.93 kB added added
@sentry/browser (incl. sendFeedback) 32.55 kB added added
@sentry/browser (incl. FeedbackAsync) 37.61 kB added added
@sentry/browser (incl. Metrics) 28.83 kB added added
@sentry/browser (incl. Logs) 29.05 kB added added
@sentry/browser (incl. Metrics & Logs) 29.75 kB added added
@sentry/react 29.54 kB added added
@sentry/react (incl. Tracing) 48.86 kB added added
@sentry/vue 33.17 kB added added
@sentry/vue (incl. Tracing) 48.55 kB added added
@sentry/svelte 27.77 kB added added
CDN Bundle 30.09 kB added added
CDN Bundle (incl. Tracing) 48.48 kB added added
CDN Bundle (incl. Logs, Metrics) 31.67 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 49.77 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 70.93 kB added added
CDN Bundle (incl. Tracing, Replay) 85.98 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.3 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.79 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.06 kB added added
CDN Bundle - uncompressed 89.68 kB added added
CDN Bundle (incl. Tracing) - uncompressed 146.56 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.39 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.54 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.15 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.8 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.76 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.5 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.45 kB added added
@sentry/nextjs (client) 51.37 kB added added
@sentry/sveltekit (client) 46.99 kB added added
@sentry/core/server 79.26 kB added added
@sentry/core/browser 51.96 kB added added
@sentry/node 123.39 kB added added
@sentry/node (incl. diagnostics channel injection) 148.77 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB added added
@sentry/node - without tracing 74.36 kB added added
@sentry/aws-serverless 83.85 kB added added
@sentry/cloudflare (withSentry) - minified 194.32 kB added added
@sentry/cloudflare (withSentry) 477.9 kB added added

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