Skip to content

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Oct 5, 2025

Description:

fixes: #17809

  • Implements message truncation for gen_ai.request.messages and vercel.ai.prompt to prevent oversized payloads from exceeding ingestion limits.

Changes:

  • Add messageTruncation.ts utility with byte size calculation and oldest-first truncation
  • Apply truncation to all AI integrations (OpenAI, Google GenAI, Anthropic, Vercel AI)
  • Set 20KB default limit for gen_ai messages
  • Preserve recent message context by removing oldest messages first

cursor[bot]

This comment was marked as outdated.

@RulaKhaled RulaKhaled self-requested a review October 6, 2025 08:38
@RulaKhaled RulaKhaled changed the title add byte size limit and oldest first truncation for gen_ai messages feat(core): Add byte size limit and oldest first truncation for gen_ai messages Oct 6, 2025
Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

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

Thank you for contributing 🎉 ! Let's address some comments before merging this

// For models.generateContent: ContentListUnion: Content | Content[] | PartUnion | PartUnion[]
if ('contents' in params) {
span.setAttributes({ [GEN_AI_REQUEST_MESSAGES_ATTRIBUTE]: JSON.stringify(params.contents) });
const contents = params.contents;
Copy link
Member

Choose a reason for hiding this comment

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

can you revert the comment removal to help others understand the request structure? this could also be a string

}

// Extract and record AI request inputs, if present. This is intentionally separate from response attributes.
function addRequestAttributes(span: Span, params: Record<string, unknown>): void {
Copy link
Member

Choose a reason for hiding this comment

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

can you also revert back this JSDoc comment?

cursor[bot]

This comment was marked as outdated.

@naaa760
Copy link
Author

naaa760 commented Oct 7, 2025

@RulaKhaled
addressed the comments
let me know!

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

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

Thanks for resolving comments, it already looks better! I've pushed a quick commit for truncation functionality + added some JSDocs here :4d047e5 (this is a different branch) could you give this a shot? :) + can you take care of tests and the quick comments left?

@naaa760
Copy link
Author

naaa760 commented Oct 10, 2025

@RulaKhaled
have you checked again?

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@RulaKhaled
Copy link
Member

@RulaKhaled have you checked again?

I pushed changes to truncation file to help get this to finish line, but i'm having issues pushing more from my local setup to this branch. Can you resolve the rest of unresolved comments please? to be clear:

  1. Resolve the lint issues
  2. Add some tests

I'll pick this up again on Monday, thanks for resolving the comments :)

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.

Implement Byte Size Limit and Oldest First Truncation for gen_ai.*.messages
2 participants