Skip to content

Add support for wide event sampling - #7965

Merged
lmac012 merged 6 commits into
developfrom
feature/lukasz/wide-event-sampling
Jul 29, 2026
Merged

Add support for wide event sampling#7965
lmac012 merged 6 commits into
developfrom
feature/lukasz/wide-event-sampling

Conversation

@lmac012

@lmac012 lmac012 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Task/Issue URL: https://app.asana.com/1/137249556945/project/1205648422731273/task/1213138183491587?focus=true
API proposal: https://app.asana.com/1/137249556945/project/1202552961248957/task/1213453461866489?focus=true

Description

Steps to test this PR

  • Build and install from the base branch
  • Launch the app
  • Disable internet connection (e.g. turn airplane mode)
  • Perform an action that creates a wide event (e.g. use fire button)
  • Inspect wide_events.db and verify that the wide event is stored
  • Update the app using build from this branch
  • Inspect wide_events.db and verify that wide_events table now has sampling_probability and all existing records have it set to 1.0.
  • Enable internet connection
  • Verify that the event is sent with sample_rate = 1.0 param.

No UI changes


Note

Medium Risk
Touches statistics persistence, migration, and outbound telemetry shape; default 1.0 preserves existing behavior until features opt into lower rates.

Overview
Adds optional sampling to wide events so high-volume flows can record a fraction of journeys without call-site handling for dropped flows.

WideEventClient.flowStart now accepts samplingProbability (0.0–1.0, default 1.0). At start, a random draw decides whether to persist the flow; sampled-out runs return SAMPLED_OUT_FLOW_ID and all later flowStep / flowFinish / interval / abort calls on that ID are no-ops with no DB writes. Kept flows store the probability on the row (Room v3 migration defaults legacy events to 1.0).

API and analytics payloads now emit the stored rate instead of a fixed value: global.sample_rate on the wide-event POST body and global.sample_rate on pixels. Cursor wide-events docs describe the parameter and sentinel behavior.

Tests across app, VPN, PIR, subscriptions, and sync are updated for the new flowStart arity; WideEventClientTest covers validation, sampling, and sentinel no-ops.

Reviewed by Cursor Bugbot for commit 09d95d0. Bugbot is set up for automated code reviews on this repo. Configure here.

lmac012 commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@lmac012
lmac012 force-pushed the feature/lukasz/wide-event-sampling branch from c82e058 to f90de59 Compare March 13, 2026 15:34
@lmac012
lmac012 force-pushed the feature/lukasz/wide-event-sampling branch from f90de59 to c2293f2 Compare March 16, 2026 15:25
@lmac012
lmac012 force-pushed the feature/lukasz/wide-event-sampling branch 2 times, most recently from 3476a70 to c746446 Compare June 26, 2026 08:51
@lmac012
lmac012 marked this pull request as ready for review June 26, 2026 09:37
lmac012 and others added 4 commits July 27, 2026 11:17
Store sampleRate (Float, default 1.0) in the WideEventEntity, propagate
it through the repository interface and mapper so it is available when
events are later sent to the backend. Includes DB migration (v1→v2).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
flowStart() now accepts a sampleRate parameter (0.0–1.0). When an event
is sampled out, SAMPLED_OUT_ID is returned immediately with zero disk
I/O. All subsequent operations (flowStep, flowFinish, flowAbort,
intervalStart, intervalEnd) on that ID are silent no-ops.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use event.samplingProbability instead of hardcoded value when building API
and pixel payloads. Change GlobalSection.sampleRate type from Int
to Float to match the stored value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lmac012
lmac012 force-pushed the feature/lukasz/wide-event-sampling branch from c746446 to 5cec301 Compare July 27, 2026 09:35
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ API Proposal reminder

This PR changes the public surface of one or more -api modules, but the API Proposals field of the PR description is empty. This is a non-blocking reminder — please double-check whether a proposal is needed.

Changed -api source files:

  • statistics/statistics-api/src/main/java/com/duckduckgo/app/statistics/wideevents/WideEventClient.kt

To clear this reminder, edit the PR description and either:

  • add the approved API Proposal link(s) in the API Proposals field (one per line), or
  • write None there if this PR does not change the public API (e.g. KDoc, comments, tests).

See the API Proposals section in .cursor/rules/contributions.mdc for details.

@lmac012
lmac012 force-pushed the feature/lukasz/wide-event-sampling branch from 5cec301 to 09d95d0 Compare July 27, 2026 10:29
@lmac012
lmac012 requested a review from joshliebe July 28, 2026 13:35

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

Code makes sense and tested, works as expected ✅

@lmac012
lmac012 merged commit 2ac7b09 into develop Jul 29, 2026
52 of 56 checks passed
@lmac012
lmac012 deleted the feature/lukasz/wide-event-sampling branch July 29, 2026 21:04
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.

2 participants