feat(core)!: Remove enableTruncation flag and gen_ai text truncation#22516
feat(core)!: Remove enableTruncation flag and gen_ai text truncation#22516nicohrubec wants to merge 1 commit into
enableTruncation flag and gen_ai text truncation#22516Conversation
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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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'; |
There was a problem hiding this comment.
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.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit b75fca6. Configure here.
size-limit report 📦
|


Stacked on #22495. Removes the
enableTruncationintegration 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
streamGenAiSpansremoval.Decisions
getTruncatedJsonStringpath. With truncation off (the default sincestreamGenAiSpansshipped), 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 vianormalizeContent, so they were unaffected and keep that path.sentry.sdk_meta.gen_ai.input.messages.original_lengthremoved. It existed only to signal that truncation dropped messages; with no truncation it would always equal the real count.@sentry/coreand@sentry/server-utils(the tracing-channel + vercel-ai dc-subscriber implementations).enableTruncationand this cleanup were pre-noted inMIGRATION.md, so that file is left as-is.Structure
mediaStripping.ts(stripInlineMediaFromMessagesmoved there and exported);messageTruncation.tsis deleted.instrument-with-pii.mjs) since stripping no longer depends on a truncation flag.