fix(metrics): Add missing metric byte outcomes#3905
Conversation
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]>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Features
FixesFlutter
Other
DependenciesDeps
Internal Changes
🤖 This preview updates automatically when you update the PR. |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
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
onDrophandling for the metric buffer to record discarded outcomes astrace_metric(DataCategory.metric) withbuffer_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 recordinternal_sdk_error, and the category istrace_metricviaDataCategory.metric. - Correctness:
InMemoryTelemetryBufferalready invokesonDropforencodeFailed/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]>
Android Performance metrics 🚀
|
| 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 |
iOS Performance metrics 🚀
|
| 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 |
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]>
Co-authored-by: Denis Andrašec <[email protected]>
📜 Description
Discarded metrics now record paired
trace_metriccount andtrace_metric_bytesize outcomes wherever the SDK can determine the encoded size. This coversbeforeSendMetric, unexpected capture failures, telemetry buffer overflow, rate-limit filtering, and transport failures.trace_metric_byteresponse-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.dartfvm dart analyzefor all modified files📝 Checklist
sendDefaultPiiis enabled🔮 Next steps
None.