Skip to content

fix(relay): Limit maximum number of otel logs deserialized from protos - #6274

Draft
klochek wants to merge 2 commits into
christopherklochek/ingest-1099-add-bounded-json-serializerfrom
christopherklochek/ingest-1100-add-bounded-proto-serializer
Draft

klochek wants to merge 2 commits into
christopherklochek/ingest-1099-add-bounded-json-serializerfrom
christopherklochek/ingest-1100-add-bounded-proto-serializer

Conversation

@klochek

@klochek klochek commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

(This points at a personal branch with which it shares a little boilerplate; will point at main when that one is merged.)

@klochek
klochek requested a review from a team as a code owner July 30, 2026 19:53
@linear-code

linear-code Bot commented Jul 30, 2026

Copy link
Copy Markdown

INGEST-1100

@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 da82bf9. Configure here.

);
Error::Invalid(DiscardReason::InvalidProtobuf)
})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Limit error remapped incorrectly

Medium Severity

otel_proto_deserializer::deserialize already returns logs::Error, including TooManyExpandedLogs, but parse_logs_data maps every failure to Invalid(InvalidProtobuf). Oversized protobuf payloads are still rejected, yet they surface as corrupt protobuf instead of the dedicated limit outcome.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit da82bf9. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be worth looking at.


match merge_logs_data(&mut meter, &mut out, &mut payload, DecodeContext::default()) {
Ok(()) => Ok(out),
Err(_) if meter.is_empty() => Err(logs::Error::TooManyExpandedLogs),

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: A protobuf parsing error can be misclassified as TooManyExpandedLogs if it occurs after exactly the maximum number of logs have been processed, because the error check uses meter.is_empty().
Severity: LOW

Suggested Fix

Modify the error handling to pattern-match on the specific error type returned from merge_logs_data, such as a potential Error::MeterExhausted, instead of relying on the state of the meter with meter.is_empty(). This will correctly distinguish between exceeding the log limit and a general protobuf decoding failure.

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: relay-server/src/processing/logs/integrations/otel_proto_deserializer.rs#L179

Potential issue: When parsing a protobuf payload, if the payload contains exactly the
maximum number of allowed log elements followed by corrupt or truncated data, a parsing
error will be incorrectly classified. The code successfully processes all valid
elements, exhausting the `meter`. When it then fails to parse the trailing corrupt data,
the error handling logic checks `meter.is_empty()`, which is true, and incorrectly
returns `Err(logs::Error::TooManyExpandedLogs)`. The correct error should be
`Invalid(DiscardReason::InvalidProtobuf)`. This misclassification leads to incorrect
outcome tracking and metrics for invalid payloads.

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

@klochek
klochek force-pushed the christopherklochek/ingest-1099-add-bounded-json-serializer branch from 2ce987e to 6b0b235 Compare August 28, 2026 07:18
@klochek
klochek force-pushed the christopherklochek/ingest-1099-add-bounded-json-serializer branch from 3b34513 to 4db355a Compare September 24, 2026 15:52
Comment on lines +642 to +643
/// The maximum number of logs that can result from a log expansion.
pub max_expanded_log_count: usize,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What constitutes an "expansion" might be confusing to users, should this just be max_log_count, and then also apply to non-integration logs? Or is there a good reason why integrations should have a different limit than our own log format?

If this only applies to Otel logs, I would name the option max_otel_log_count.

Suggested change
/// The maximum number of logs that can result from a log expansion.
pub max_expanded_log_count: usize,
/// The maximum number of logs in a single submission.
pub max_log_count: usize,

@klochek
klochek marked this pull request as draft October 15, 2026 19:49
@klochek
klochek force-pushed the christopherklochek/ingest-1099-add-bounded-json-serializer branch from 4db355a to 2fa492c Compare October 15, 2026 19:52

This branch has not been deployed

No deployments
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.

2 participants