Skip to content

feat: client reports#1549

Merged
jpnurmi merged 18 commits intomasterfrom
jpnurmi/feat/client-reports
Apr 9, 2026
Merged

feat: client reports#1549
jpnurmi merged 18 commits intomasterfrom
jpnurmi/feat/client-reports

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Mar 3, 2026

Track and report discarded events per the client reports spec:

  • sample_rate: events dropped by the sample rate
  • before_send: events, transactions, logs, and metrics dropped by before-send hooks
  • ratelimit_backoff: envelope items dropped by rate limiter
  • network_error: envelope items lost on send failure
  • send_error: envelope items rejected by the server (4xx/5xx)
  • queue_overflow: logs and metrics dropped when the batcher is full

Reports are opportunistically attached to outgoing envelopes. Opt-out via sentry_options_set_send_client_reports().

Close: #1216

@jpnurmi jpnurmi force-pushed the jpnurmi/feat/http-retry branch from b133fd6 to 93db900 Compare March 17, 2026 16:15
Base automatically changed from jpnurmi/feat/http-retry to master March 31, 2026 19:23
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/client-reports branch 3 times, most recently from 03b4c49 to 08697e5 Compare April 1, 2026 10:23
@jpnurmi jpnurmi changed the title WIP: feat: client reports feat: client reports Apr 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 3dbe3d8

@jpnurmi jpnurmi force-pushed the jpnurmi/feat/client-reports branch 6 times, most recently from d20984f to dd39920 Compare April 2, 2026 11:15
@jpnurmi jpnurmi marked this pull request as ready for review April 2, 2026 11:16
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/client-reports branch from 3a646a5 to 47ca4e4 Compare April 2, 2026 15:16
jpnurmi and others added 13 commits April 8, 2026 16:41
Subtract reported values instead of zeroing to preserve concurrent
increments that happen between read and reset.
Use the item type string directly to determine the data category
instead of going through the lossy RL category mapping.
The rate limiter is updated from the response headers before the status
code is returned. Pass NULL to skip the stale rate limiter check since
all items were already serialized and sent.
Split http_send_request so the rate limiter is updated after recording
discards, not before. This ensures items that were rate-limited during
serialization are not also counted as send_error.
Replaces the read-then-subtract approach with atomic exchange (store 0).
Each counter value is now consumed exactly once, so no discard counts
are lost under concurrent access. The tradeoff is that counts are
drained at read time, so they are lost if the envelope item allocation
fails afterwards.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Counters from a previous session carry over and get piggybacked onto
the next outgoing envelope, which is acceptable for best-effort
telemetry.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Retried envelopes are raw (opaque bytes from disk), so their items
cannot be inspected directly. Serialize and deserialize the raw
envelope to get structured items for discard recording.

Also skip into_envelope for raw envelopes to prevent draining counters
into an envelope that cannot accept new items.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Per the developer docs: "For an HTTP 429 Too Many Requests response,
SDKs MUST discard the envelope, but MUST NOT record a client report,
because the upstream already does this."

https://develop.sentry.dev/sdk/telemetry/client-reports/#rate-limited-http-429

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Split sentry__client_report_into_envelope into sentry__client_report_save
+ sentry__envelope_add_client_report so that on send failure, the consumed
counts can be restored via sentry__client_report_restore instead of being
silently lost with the discarded envelope.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace sentry__envelope_is_rate_limited() with
sentry__envelope_can_add_client_report() which also rejects raw
(file-backed) envelopes. This prevents the transport from draining
global discard counters into a report that cannot be attached to a
raw envelope, which would silently lose the counts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/client-reports branch from a674385 to 2586cdb Compare April 8, 2026 15:52
Copy link
Copy Markdown
Collaborator

@supervacuus supervacuus left a comment

Choose a reason for hiding this comment

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

I like the changes applied to the counts 👍

Also, client reports beautifully highlight the value of your transport refactorings. Thanks again for that.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Zero the report struct after restoring so that a double restore
does not double the counts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

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 7c5044d. Configure here.

@jpnurmi jpnurmi merged commit 713acd6 into master Apr 9, 2026
59 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/feat/client-reports branch April 9, 2026 13:33
jpnurmi added a commit to getsentry/sentry-docs that referenced this pull request Apr 10, 2026
Document the new send_client_reports option added in sentry-native
0.13.6 (getsentry/sentry-native#1549), which lets users opt out of
client reports tracking for discarded events.
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.

Add Client Reports to the native SDK

3 participants