Skip to content

chore: remove SDK-side data truncation, defer to Relay#1093

Open
dingsdax wants to merge 5 commits into
masterfrom
ref/remove-sdk-side-truncation
Open

chore: remove SDK-side data truncation, defer to Relay#1093
dingsdax wants to merge 5 commits into
masterfrom
ref/remove-sdk-side-truncation

Conversation

@dingsdax

@dingsdax dingsdax commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remove SDK-side truncation of event message text (8,192 char hard limit) and stacktrace argument variables (String.slice truncation)
  • Relay already enforces the same limits with proper _meta annotations, so users now get visible truncation indicators in the Sentry UI instead of silent data loss

Message truncation removed (lib/sentry/client.ex)

Removed the @max_message_length (8,192) constant and String.slice call from sanitize_message/2. Relay already enforces the same limit on logentry.message and logentry.formatted, adding _meta truncation markers that the Sentry UI renders.

Stacktrace arg truncation removed (lib/sentry/event.ex)

Removed the String.slice call in stacktrace_args_to_vars/1, keeping only inspect(arg, inspect_opts). The inspect_opts (from :max_stacktrace_arg_length) still prevent the SDK from materializing huge strings, but the hard slice is gone so Relay can enforce its max_bytes = 2048 limit on frame vars with proper metadata.

fixes: ELIXIR-32
fixes: #937

dingsdax and others added 2 commits June 23, 2026 15:18
Remove redundant SDK-side truncation of message formatted text
(8192 char limit) and stacktrace argument vars (513 char limit).
Relay enforces the same limits with proper _meta annotations, giving
users visible truncation indicators in the Sentry UI instead of
silent data loss.

- Remove @max_message_length constant and String.slice in
  sanitize_message/2 (Relay: max_chars=8192 + 200 allowance)
- Remove String.slice on inspect(arg) in stacktrace_args_to_vars/1
  (Relay: max_bytes=2048 on vars field)
- Update test to assert full message preservation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dingsdax dingsdax changed the title ref: Remove SDK-side data truncation, defer to Relay chore: remove SDK-side data truncation, defer to Relay Jun 23, 2026
@linear-code

linear-code Bot commented Jun 23, 2026

Copy link
Copy Markdown

ELIXIR-32

dingsdax and others added 2 commits June 23, 2026 15:31
…-truncation

# Conflicts:
#	lib/sentry/client.ex
#	lib/sentry/event.ex
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dingsdax dingsdax requested a review from solnic June 23, 2026 13:37
Comment thread lib/sentry/event.ex
|> Enum.with_index()
|> Map.new(fn {arg, index} ->
{"arg#{index}", String.slice(inspect(arg, inspect_opts), 0, max_length)}
{"arg#{index}", inspect(arg, inspect_opts)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Removing the hard truncation on stacktrace arguments can lead to excessively large output from inspect/2, as the new printable_limit and limit options do not fully constrain the size of complex data structures.
Severity: LOW

Suggested Fix

To restore the safety guarantee, consider applying a final truncation to the output of the inspect call. For example, using inspect(arg, inspect_opts) |> String.slice(0, max_length) would ensure the resulting string for each argument does not exceed the configured max_stacktrace_arg_length, preventing pathologically large data from creating oversized payloads.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: lib/sentry/event.ex#L472

Potential issue: The removal of the hard `String.slice` truncation for stacktrace
arguments in `stacktrace_args_to_vars` introduces a risk of generating excessively large
strings. The `inspect/2` function is now used with `printable_limit` and `limit`
options, but these do not provide a complete safeguard. The `printable_limit` only
applies to strings and charlists, while `limit` only caps the number of elements in a
collection, not their individual sizes. A pathological data structure, such as a large
map where values are themselves large, complex terms, could bypass these limits and
produce an inspected string of millions of characters, potentially leading to high
memory consumption or issues with downstream services that have payload size limits.

Also affects:

  • lib/sentry/client.ex:345~350

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yep this is technically correct—we'd be able to post huge inspected data structures to Sentry.

@dingsdax dingsdax Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Relay enforces max_bytes=2048 + max_depth=5 on frame.vars via its TrimmingProcessor: anything over budget gets trimmed with ... and a _meta remark so the UI shows a truncation indicator.
The limits are defined in the stacktrace schema. So this should be fine.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Right but isn't relay running on Sentry's servers? We'd still egress lots of data here no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, but it's fine. this change aligns with what we do in other SDKs too, the main benefit is that the truncation shows up in the UI when done in Relay

Comment thread .gitignore Outdated
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.

Remove unnecessary SDK-side data truncation and rely on Relay for handling max length limits.

3 participants