Skip to content

feat(core): Add weight-based flushing to span buffer - #19579

Merged
Lms24 merged 2 commits into
lms/feat-span-firstfrom
lms/feat-span-buffer-weight-flushing
Mar 2, 2026
Merged

feat(core): Add weight-based flushing to span buffer#19579
Lms24 merged 2 commits into
lms/feat-span-firstfrom
lms/feat-span-buffer-weight-flushing

Conversation

@Lms24

@Lms24Lms24 commented Mar 2, 2026

Copy link
Copy Markdown
Member

Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:

  • tracks weight independently per trace
  • weight estimation follows the same strategy we use for logs and metrics. I optimized the calculation, adding fixed sizes for as many fields as possible. Only span name, attributes and links are computed dynamically, with the same assumptions and considerations as in logs and metrics.
  • My tests show that the size estimation roughly compares to factor 0.8 to 1.2 to the real sizes, depending on data on spans (no, few, many, primitive, array attributes and links, etc.)
  • For now, the limit is set to 5MB which is half of the 10MB Relay accepts for span envelopes.

: MAX_SPANS_PER_ENVELOPE;
this._flushInterval = flushInterval && flushInterval > 0 ? flushInterval : 5_000;
this._maxTraceWeight =
maxTraceWeightInBytes && maxTraceWeightInBytes > 0 ? maxTraceWeightInBytes : MAX_TRACE_WEIGHT_IN_BYTES;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing integration or E2E test for new feature

Low Severity

This feat PR adds weight-based flushing and span size estimation but only includes unit tests. Per the project review rules, feat PRs need at least one integration or E2E test. Consider adding an integration test that validates the end-to-end flow of weight-triggered flushing in a realistic scenario.

Additional Locations (1)

Fix in CursorFix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bugbot Autofix determined this is a false positive.

Comprehensive unit tests exist; integration tests require span streaming infrastructure that doesn't exist in any test suite yet.

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Correct, integration tests will follow soon!

@github-actions

github-actionsBot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊


Generated by Codecov Action

@github-actions

github-actionsBot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser25.64 kBaddedadded
@sentry/browser - with treeshaking flags24.16 kBaddedadded
@sentry/browser (incl. Tracing)42.66 kBaddedadded
@sentry/browser (incl. Tracing, Profiling)47.33 kBaddedadded
@sentry/browser (incl. Tracing, Replay)81.49 kBaddedadded
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags71.11 kBaddedadded
@sentry/browser (incl. Tracing, Replay with Canvas)86.18 kBaddedadded
@sentry/browser (incl. Tracing, Replay, Feedback)98.34 kBaddedadded
@sentry/browser (incl. Feedback)42.36 kBaddedadded
@sentry/browser (incl. sendFeedback)30.31 kBaddedadded
@sentry/browser (incl. FeedbackAsync)35.3 kBaddedadded
@sentry/browser (incl. Metrics)26.81 kBaddedadded
@sentry/browser (incl. Logs)26.96 kBaddedadded
@sentry/browser (incl. Metrics & Logs)27.64 kBaddedadded
@sentry/react27.4 kBaddedadded
@sentry/react (incl. Tracing)45 kBaddedadded
@sentry/vue30.3 kBaddedadded
@sentry/vue (incl. Tracing)44.51 kBaddedadded
@sentry/svelte25.67 kBaddedadded
CDN Bundle28.18 kBaddedadded
CDN Bundle (incl. Tracing)43.5 kBaddedadded
CDN Bundle (incl. Logs, Metrics)29.02 kBaddedadded
CDN Bundle (incl. Tracing, Logs, Metrics)44.33 kBaddedadded
CDN Bundle (incl. Replay, Logs, Metrics)68.11 kBaddedadded
CDN Bundle (incl. Tracing, Replay)80.33 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)81.24 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback)85.79 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)86.69 kBaddedadded
CDN Bundle - uncompressed82.41 kBaddedadded
CDN Bundle (incl. Tracing) - uncompressed128.77 kBaddedadded
CDN Bundle (incl. Logs, Metrics) - uncompressed85.25 kBaddedadded
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed131.6 kBaddedadded
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed208.91 kBaddedadded
CDN Bundle (incl. Tracing, Replay) - uncompressed245.65 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed248.47 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed258.45 kBaddedadded
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed261.26 kBaddedadded
@sentry/nextjs (client)47.36 kBaddedadded
@sentry/sveltekit (client)43.11 kBaddedadded
@sentry/node-core52.24 kBaddedadded
@sentry/node166.79 kBaddedadded
@sentry/node - without tracing94.02 kBaddedadded
@sentry/aws-serverless109.52 kBaddedadded

@github-actions

github-actionsBot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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.

ScenarioRequests/s% of BaselinePrev. Requests/sChange %
GET Baseline9,268--added
GET With Sentry1,59617%-added
GET With Sentry (error only)6,07866%-added
POST Baseline1,187--added
POST With Sentry56848%-added
POST With Sentry (error only)1,05189%-added
MYSQL Baseline3,203--added
MYSQL With Sentry42413%-added
MYSQL With Sentry (error only)2,63482%-added

@Lms24Lms24 self-assigned this Mar 2, 2026

@cursorcursorBot 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.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

return 8;
}
return 0;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate estimatePrimitiveSizeInBytes function in codebase

Low Severity

The newly added estimatePrimitiveSizeInBytes function in attributes.ts is a functionally identical duplicate of the existing private estimatePrimitiveSizeInBytes in client.ts (lines 1709–1719). Both check for string, number, and boolean types and return the same values. Similarly, estimateTypedAttributesSizeInBytes partially overlaps with estimateAttributesSizeInBytes in client.ts. The shared primitive estimator could be extracted into a common utility to avoid maintaining two copies.

Additional Locations (1)

Fix in CursorFix in Web

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes, this was deliberate for the moment. I want to unify this + adjust log/metric size estimation a bit more but this will happen against the develop branch for logs and metrics. estimatePrimitiveSizeInBytes should IMHO not be in client.ts but rather in attributes.ts.

Comment on lines +162 to +169
if (typeof value === 'string') {
return value.length * 2;
} else if (typeof value === 'boolean') {
return 4;
} else if (typeof value === 'number') {
return 8;
}
return 0;

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.

As this is for attributes, we probably only need to account for string, boolean and number. But just for the sake of completeness, I want to mention that there would still be symbol and bigint that would fall through and evaluate as 0 (in case this ever gets relevant).

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Good point! At the moment, we'd drop these attributes on spans since they're not supported. We might want to reconsider this eventually (see #18164), in which case we'd probably stringify them. So we'd report the stringified length * 2. I'm gonna leave this as-is for now though.

@Lms24
Lms24 merged commit 24015b1 into lms/feat-span-firstMar 2, 2026
216 of 217 checks passed
@Lms24
Lms24 deleted the lms/feat-span-buffer-weight-flushing branch March 2, 2026 13:40
@Lms24Lms24 mentioned this pull request Mar 4, 2026
Lms24 added a commit that referenced this pull request Mar 4, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 6, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 9, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 10, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 13, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 18, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
logaretm pushed a commit that referenced this pull request Mar 18, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 23, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Mar 30, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Apr 2, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Apr 8, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Lms24 added a commit that referenced this pull request Apr 9, 2026
Adds weight-based flushing and span size estimation to the span buffer.
Behaviour:
- tracks weight independently per trace
- weight estimation follows the same strategy we use for logs and
metrics. I optimized the calculation, adding fixed sizes for as many
fields as possible. Only span name, attributes and links are computed
dynamically, with the same assumptions and considerations as in logs and
metrics.
- My tests show that the size estimation roughly compares to factor 0.8
to 1.2 to the real sizes, depending on data on spans (no, few, many,
primitive, array attributes and links, etc.)
- For now, the limit is set to 5MB which is half of the 10MB Relay
accepts for span envelopes.
Sign up for freeto 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

@Lms24@s1gr1d