Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Jan 20, 2026

Changes

  • This simplifies AI message truncation to always keep only the last message and truncate it if needed. Previously we dropped oldest messages one by one until we fit within the limit.
  • Set embeddings input as a separate attribute gen_ai.embeddings.input and do not truncate that.
  • Also added support for truncating plain string arrays. Not sure if we need that at the moment, since we no longer truncate embeddings, but shouldn't hurt.

Test Updates

  • Updated all node integration and unit tests to work with the new logic.
  • Extended the node integration suite to always test the two main scenarios (keep the large message and then either truncate if the last message is large or leave it as is if it is small).
  • Removed the embeddings truncation tests and instead added a new embeddings scenario that checks that embeddings inputs are all kept (even if an array with multiple entries is passed).

Closes #18916

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.2 kB - -
@sentry/browser - with treeshaking flags 23.71 kB - -
@sentry/browser (incl. Tracing) 42.02 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.66 kB - -
@sentry/browser (incl. Tracing, Replay) 80.63 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.28 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.33 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 97.53 kB - -
@sentry/browser (incl. Feedback) 41.92 kB - -
@sentry/browser (incl. sendFeedback) 29.89 kB - -
@sentry/browser (incl. FeedbackAsync) 34.89 kB - -
@sentry/browser (incl. Metrics) 26.31 kB - -
@sentry/browser (incl. Logs) 26.46 kB - -
@sentry/browser (incl. Metrics & Logs) 27.11 kB - -
@sentry/react 26.93 kB - -
@sentry/react (incl. Tracing) 44.26 kB - -
@sentry/vue 29.64 kB - -
@sentry/vue (incl. Tracing) 43.82 kB - -
@sentry/svelte 25.22 kB - -
CDN Bundle 27.78 kB - -
CDN Bundle (incl. Tracing) 42.83 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 43.65 kB - -
CDN Bundle (incl. Tracing, Replay) 79.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 84.97 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 85.89 kB - -
CDN Bundle - uncompressed 81.27 kB - -
CDN Bundle (incl. Tracing) - uncompressed 126.81 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 129.65 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 243.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.15 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 258.96 kB - -
@sentry/nextjs (client) 46.62 kB - -
@sentry/sveltekit (client) 42.39 kB - -
@sentry/node-core 51.9 kB -0.01% -1 B 🔽
@sentry/node 165.46 kB +0.03% +42 B 🔺
@sentry/node - without tracing 93.66 kB - -
@sentry/aws-serverless 109.16 kB - -

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 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 9,497 - 8,959 +6%
GET With Sentry 1,739 18% 1,585 +10%
GET With Sentry (error only) 6,248 66% 6,016 +4%
POST Baseline 1,223 - 1,171 +4%
POST With Sentry 603 49% 570 +6%
POST With Sentry (error only) 1,079 88% 1,030 +5%
MYSQL Baseline 3,429 - 3,248 +6%
MYSQL With Sentry 514 15% 358 +44%
MYSQL With Sentry (error only) 2,800 82% 2,590 +8%

View base workflow run

Copy link

@cursor cursor bot left a comment

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 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

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.

Overall looks really good. Two things we should do:

  1. Take care of embeddings input
  2. Remove the media filtering logic entirely (lmk if that's something you want to do as a follow up, we can create a ticket and tackle it after)

let bytesUsed = 0;
let startIndex = stripped.length; // Index where the kept suffix starts
// Strip inline media from the single message
const stripped = stripInlineMediaFromMessages([lastMessage]);
Copy link
Member

Choose a reason for hiding this comment

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

We should entirely remove inline media logic

Copy link
Member Author

Choose a reason for hiding this comment

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

will do in a follow-up if need be

'gen_ai.operation.name': 'embeddings',
'sentry.op': 'gen_ai.embeddings',
'gen_ai.system': 'openai',
'gen_ai.request.messages': '["This is a small input that fits within the limit"]',
Copy link
Member

@RulaKhaled RulaKhaled Jan 21, 2026

Choose a reason for hiding this comment

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

so yah we don't want this format, we should map this to https://getsentry.github.io/sentry-conventions/generated/attributes/gen_ai.html#gen_aiembeddingsinput instead of gen_ai.request.messages, let's take care of this here so that request messages type is consistent with the type listed in https://getsentry.github.io/sentry-conventions/generated/attributes/gen_ai.html#gen_aiinputmessages

for truncate message logic for embeddings, according to TEL experience team, we don't need to worry about this just yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should be good now. When setting the request attributes I now set embeddings inputs separately and it is excluded from the truncation

@nicohrubec nicohrubec requested a review from RulaKhaled January 21, 2026 15:34
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.

lgtm, thanks Nico

@nicohrubec nicohrubec merged commit 1b2eea3 into develop Jan 21, 2026
411 of 413 checks passed
@nicohrubec nicohrubec deleted the nh/simplify-truncation-logic branch January 21, 2026 16:25
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.

Simplify truncation logic to only keep the last message and exclude embeddings

3 participants