Skip to content

fix(traces): update payload size after dropping traces#1091

Open
lym953 wants to merge 9 commits intomainfrom
yiming.luo/drop-traces-2
Open

fix(traces): update payload size after dropping traces#1091
lym953 wants to merge 9 commits intomainfrom
yiming.luo/drop-traces-2

Conversation

@lym953
Copy link
Contributor

@lym953 lym953 commented Mar 9, 2026

This PR

After dropping sampled-out traces, recompute body_size. This ensures the TraceAggregator's 3.2 MB batch limit is evaluated against only the data that will actually be sent to the backend.

Upgrades the version of some external crates because those are the versions used in libdatadog.

Testing

  • Unit tests

Note

The recomputed size uses the protobuf encoded payload size, different from the original size, computed from: (from Claude)

  • Datadog tracer path: src/traces/trace_agent.rs:506 — body_size is the first element of the tuple returned by get_traces_from_request_body() / get_v05_traces_from_request_body(), which is the raw HTTP request
    body byte count (msgpack-encoded bytes).
  • OTLP path: src/otlp/agent.rs:167 — let body_size = size_of_val(&traces) where traces is a TracerPayloadCollection, giving only the stack size of the Rust enum (~32 bytes).

The new approach be more accurate because it's computed at a later point for the size of protobuf data, which is what's finally sent to Datadog.

By the way, the size doesn't need to be accurate. An approximate size is good enough. See:
https://github.com/DataDog/libdatadog/blob/3f3efefb2ff45d7a5491b770480396d001b87631/libdd-trace-utils/src/send_data/mod.rs#L148

Also here are some sample logs (logging node not included in the PR) showing the different sizes computed in different ways:

body_size (original): 582, body_size (encoded_len): 1355
body_size (original): 373, body_size (encoded_len): 1269
body_size (original): 336, body_size (encoded_len): 899

…iority filtering

After filtering sampled-out TraceChunks from the payload, recompute body_size
using prost::Message::encoded_len() on the remaining TracerPayloads instead of
passing through the original (unfiltered) request body size. This ensures the
TraceAggregator's 3.2 MB batch limit is evaluated against only the data that
will actually be sent to the backend.

Since libdd-trace-protobuf uses prost 0.14 while bottlecap depends on prost
0.13, add prost014 as an aliased direct dependency so the prost 0.14 Message
trait is accessible for TracerPayload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lym953 lym953 changed the title fix(traces): use protobuf encoded_len for body_size after sampling-pr… fix(traces): update payload size after dropping traces Mar 9, 2026
lym953 and others added 5 commits March 9, 2026 15:52
… tonic-types

Replaces the prost014 alias workaround with a straightforward prost 0.14
upgrade. opentelemetry-proto (0.30→0.31) and tonic-types (0.13→0.14) both
moved to prost 0.14, so all three can be bumped together, eliminating the
dual-version dependency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lym953 lym953 marked this pull request as ready for review March 9, 2026 20:25
@lym953 lym953 requested a review from a team as a code owner March 9, 2026 20:25
@lym953 lym953 requested a review from duncanista March 9, 2026 20:25
lym953 and others added 3 commits March 9, 2026 16:46
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.

1 participant