Skip to content

fix(metrics): Add missing metric byte outcomes#3905

Merged
buenaflor merged 5 commits into
mainfrom
fix/record-metric-buffer-drops
Jul 21, 2026
Merged

fix(metrics): Add missing metric byte outcomes#3905
buenaflor merged 5 commits into
mainfrom
fix/record-metric-buffer-drops

Conversation

@buenaflor

@buenaflor buenaflor commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Discarded metrics now record paired trace_metric count and trace_metric_byte size outcomes wherever the SDK can determine the encoded size. This covers beforeSendMetric, unexpected capture failures, telemetry buffer overflow, rate-limit filtering, and transport failures.

trace_metric_byte response-header limits are parsed and applied to metric envelope items. Encoding failures still record the metric count but omit the byte outcome because no encoded size is available.

💡 Motivation and Context

Metric drops previously reported only item counts, or no outcome at all for telemetry buffer rejection. This left discarded metric volume invisible and did not honor byte-category rate limits. The shared metric recorder now mirrors the existing log count/byte behavior across the same SDK paths.

Fixes #3752

💚 How did you test it?

  • fvm dart test test/client_reports test/telemetry/metric test/telemetry/processing test/protocol/rate_limit_parser_test.dart test/protocol/rate_limiter_test.dart test/transport/http_transport_test.dart
  • Focused fvm dart analyze for all modified files

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec
  • No breaking changes

🔮 Next steps

None.

Record trace_metric outcomes when the telemetry buffer rejects metrics.

Cover oversized and encoding-failure cases with regression tests.

Fixes #3752

Co-Authored-By: Codex <[email protected]>
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Features

  • (replay) Record segment names on Android by buenaflor in #3897
  • (tracing) Emit segment name source by buenaflor in #3904

Fixes

Flutter

  • Add app start screen attribute by buenaflor in #3893
  • Prevent StateError when delayed frames list is empty by muhammadkamel in #3876

Other

  • (metrics) Add missing metric byte outcomes by buenaflor in #3905

Dependencies

Deps

  • chore(deps): update Native SDK to v0.15.4 by github-actions in #3910
  • chore(deps): update Android SDK to v8.49.0 by github-actions in #3895
  • chore(deps): update Native SDK to v0.15.3 by github-actions in #3862
  • chore(deps): update Cocoa SDK to v8.58.4 by github-actions in #3864
  • chore(deps): update Android SDK to v8.48.0 by github-actions in #3873

Internal Changes

  • (dart) Accept beta wasm function name by sentry-junior in #3898

🤖 This preview updates automatically when you update the PR.

@buenaflor
buenaflor marked this pull request as ready for review July 20, 2026 13:32
@buenaflor
buenaflor requested a review from denrase as a code owner July 20, 2026 13:32
Copilot AI review requested due to automatic review settings July 20, 2026 13:32
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.46%. Comparing base (b9e9506) to head (fd4c60c).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rc/client_reports/noop_client_report_recorder.dart 0.00% 1 Missing ⚠️
.../src/telemetry/metric/metric_capture_pipeline.dart 87.50% 1 Missing ⚠️
packages/dart/lib/src/utils/transport_utils.dart 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3905      +/-   ##
==========================================
+ Coverage   87.38%   87.46%   +0.07%     
==========================================
  Files         338      338              
  Lines       12314    12345      +31     
==========================================
+ Hits        10761    10797      +36     
+ Misses       1553     1548       -5     
Flag Coverage Δ
sentry 87.62% <91.17%> (+0.13%) ⬆️
sentry_dio 97.73% <ø> (ø)
sentry_drift 93.57% <ø> (ø)
sentry_file 65.29% <ø> (ø)
sentry_firebase_remote_config 100.00% <ø> (ø)
sentry_flutter 91.16% <ø> (ø)
sentry_grpc 99.09% <ø> (ø)
sentry_hive 77.48% <ø> (ø)
sentry_isar 74.37% <ø> (ø)
sentry_link 21.50% <ø> (ø)
sentry_logging 97.01% <ø> (ø)
sentry_sqflite 88.81% <ø> (ø)
sentry_supabase 97.27% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR wires the metric in-memory telemetry buffer’s onDrop callback to the client report recorder so that metrics rejected before buffering are no longer silently dropped, aligning metric behavior with existing log-buffer handling.

Changes:

  • Add onDrop handling for the metric buffer to record discarded outcomes as trace_metric (DataCategory.metric) with buffer_overflow / internal_sdk_error.
  • Add regression tests asserting client report outcomes for oversized and unencodable metrics.

Review Axes (Standards / Spec / Correctness)

  • Standards: No public API changes observed; added wiring follows the established pattern already used for the log buffer in the same integration. Tests are consistent with existing test style in this file.
  • Spec: Matches the issue requirements: oversized metrics record buffer_overflow, encoder failures record internal_sdk_error, and the category is trace_metric via DataCategory.metric.
  • Correctness: InMemoryTelemetryBuffer already invokes onDrop for encodeFailed / tooLarge; the integration now correctly records outcomes on those paths. Tests cover both drop causes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/dart/lib/src/telemetry/processing/processor_integration.dart Pass onDrop to the metric buffer and record client report outcomes under DataCategory.metric (trace_metric).
packages/dart/test/telemetry/processing/processor_integration_test.dart Add tests to verify client report outcomes for oversized and unencodable metrics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Report the encoded size of oversized metrics under trace_metric_byte.

Keep encoding failures count-only because no encoded size is available.

Refs #3752

Co-Authored-By: Codex <[email protected]>
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Android Performance metrics 🚀

  Plain With Sentry Diff
Startup time 359.55 ms 351.22 ms -8.33 ms
Size 14.55 MiB 15.87 MiB 1.31 MiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
aaa2730 354.04 ms 370.46 ms 16.41 ms
667e3c4 402.86 ms 394.04 ms -8.82 ms
6f47800 451.04 ms 509.64 ms 58.60 ms
0fb3800 465.64 ms 536.77 ms 71.13 ms
ce5c42b 401.52 ms 394.63 ms -6.90 ms
b6c8720 457.41 ms 519.04 ms 61.63 ms
53356d8 394.48 ms 400.70 ms 6.22 ms
c26ed0a 465.52 ms 476.38 ms 10.86 ms
20faa47 400.26 ms 392.90 ms -7.37 ms
c5cf749 379.18 ms 360.60 ms -18.58 ms

App size

Revision Plain With Sentry Diff
aaa2730 14.31 MiB 15.49 MiB 1.19 MiB
667e3c4 14.55 MiB 15.87 MiB 1.31 MiB
6f47800 6.54 MiB 7.69 MiB 1.15 MiB
0fb3800 6.54 MiB 7.69 MiB 1.15 MiB
ce5c42b 14.31 MiB 15.49 MiB 1.19 MiB
b6c8720 6.54 MiB 7.69 MiB 1.15 MiB
53356d8 14.09 MiB 15.28 MiB 1.19 MiB
c26ed0a 13.93 MiB 14.93 MiB 1.00 MiB
20faa47 13.93 MiB 15.18 MiB 1.25 MiB
c5cf749 14.31 MiB 15.49 MiB 1.19 MiB

Previous results on branch: fix/record-metric-buffer-drops

Startup times

Revision Plain With Sentry Diff
b1182da 347.09 ms 360.02 ms 12.93 ms

App size

Revision Plain With Sentry Diff
b1182da 14.55 MiB 15.87 MiB 1.31 MiB

@buenaflor
buenaflor marked this pull request as draft July 20, 2026 13:38
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

iOS Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1239.40 ms 1243.07 ms 3.67 ms
Size 5.83 MiB 6.28 MiB 458.13 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
af96ef2 1260.79 ms 1259.61 ms -1.17 ms
b6c8720 1252.65 ms 1266.61 ms 13.96 ms
af4c7c1 1246.85 ms 1255.35 ms 8.50 ms
8af916c 1246.66 ms 1240.79 ms -5.87 ms
d0aa4b6 1268.23 ms 1268.39 ms 0.15 ms
91629ec 1257.91 ms 1255.93 ms -1.98 ms
c002f00 1252.47 ms 1258.78 ms 6.31 ms
a34fde0 1255.35 ms 1254.31 ms -1.03 ms
3135a81 1258.11 ms 1247.48 ms -10.63 ms
d5a1225 1252.46 ms 1254.66 ms 2.20 ms

App size

Revision Plain With Sentry Diff
af96ef2 5.53 MiB 6.02 MiB 501.31 KiB
b6c8720 7.86 MiB 9.44 MiB 1.58 MiB
af4c7c1 5.83 MiB 6.28 MiB 460.73 KiB
8af916c 5.73 MiB 6.18 MiB 463.84 KiB
d0aa4b6 5.53 MiB 6.02 MiB 502.04 KiB
91629ec 5.83 MiB 6.28 MiB 459.63 KiB
c002f00 5.65 MiB 6.09 MiB 448.38 KiB
a34fde0 5.66 MiB 6.10 MiB 451.57 KiB
3135a81 5.73 MiB 6.17 MiB 453.76 KiB
d5a1225 5.73 MiB 6.17 MiB 453.73 KiB

Previous results on branch: fix/record-metric-buffer-drops

Startup times

Revision Plain With Sentry Diff
b1182da 1249.42 ms 1255.19 ms 5.77 ms
5d94ade 1262.31 ms 1261.17 ms -1.15 ms

App size

Revision Plain With Sentry Diff
b1182da 5.83 MiB 6.28 MiB 461.30 KiB
5d94ade 5.83 MiB 6.28 MiB 458.13 KiB

Record paired metric count and byte outcomes across capture, buffering, rate limiting, and transport failures.

Honor trace_metric_byte rate limits for metric envelope items.

Refs #3752

Co-Authored-By: Codex <[email protected]>
@buenaflor buenaflor changed the title fix(metrics): Record dropped buffer outcomes fix(metrics): Add missing metric byte outcomes Jul 20, 2026
@buenaflor
buenaflor marked this pull request as ready for review July 20, 2026 13:58
Comment thread packages/dart/lib/src/client_reports/client_report_recorder.dart Outdated
Comment thread packages/dart/lib/src/utils/transport_utils.dart
@buenaflor
buenaflor enabled auto-merge (squash) July 21, 2026 09:41
@buenaflor
buenaflor merged commit a28f929 into main Jul 21, 2026
160 checks passed
@buenaflor
buenaflor deleted the fix/record-metric-buffer-drops branch July 21, 2026 09:44
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.

Record client report outcomes for metrics dropped by the telemetry buffer

3 participants