feat(sdk): Add configurable S4S transaction sampling#108097
feat(sdk): Add configurable S4S transaction sampling#108097
Conversation
When the region is s4s2, deterministically sample transactions at 1% before sending to S4S upstream, based on hashing the trace_id. This reduces high-volume transaction traffic (post_process_group, process_workflows_event, etc.) to S4S while preserving trace-level consistency in the sampling decision. https://claude.ai/code/session_01Axg7gBXDmQT6yyqKp2B6fR
Apply transaction sampling unconditionally when sending to the S4S upstream, since the S4S DSN always targets s4s2.
mwarkentin
left a comment
There was a problem hiding this comment.
Couple of general suggestions - any
…ansaction-sample-rate Deterministically sample transaction/span data sent to S4S upstream based on trace_id. Errors and logs are never dropped. Default rate is 1.0 (keep all).
There was a problem hiding this comment.
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.
mwarkentin
left a comment
There was a problem hiding this comment.
LGTM, but perhaps good to get another backend dev ✅
| x | ||
| for x in envelope.items | ||
| if x.data_category != "statsd" | ||
| or in_random_rollout("store.allow-s4s-ddm-sample-rate") |
There was a problem hiding this comment.
Not related to our changes here, but I wonder if this can be cleaned up now? :)
markstory
left a comment
There was a problem hiding this comment.
This looks like it will work well for transactions. Do we also have to be concerned with span envelopes?
Extend _should_drop_s4s to cover span envelopes (item type "span") in addition to transaction envelopes. Previously, newer SDK-style span envelopes bypassed sampling entirely because get_transaction_event() returns None for them. Co-Authored-By: Claude <[email protected]>
i've added support for span envelope sampling. at the moment we're not sending span envelopes with our python sdk, but this could change in the future. i've added a comment as well. |
## Description Adds deterministic, trace_id-based sampling for transaction/span data sent to the S4S upstream. This reduces transaction volume while keeping complete traces together. ## Changes - Added `store.s4s-transaction-sample-rate` option (default `1.0` = keep all) - Extracted `_should_drop_s4s()` method on `MultiplexingTransport` - Deterministic sampling using direct hex parsing of trace_id (no hashing needed) - Errors and logs are never dropped - Metrics track both dropped (`s4s_dropped`) and sent (`upstream`) events ## Usage Set `store.s4s-transaction-sample-rate` to `0.05` to keep 5% of transactions. ## Test plan - [x] Unit tests for all sampling paths (default rate, zero rate, errors, determinism, missing trace_id) - [ ] Deploy with `1.0` (no-op) and verify metrics - [ ] Lower to `0.05` and monitor `internal.captured.events.upstream.s4s_dropped` vs `internal.captured.events.upstream` --------- Co-authored-by: Claude <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
## Description Adds deterministic, trace_id-based sampling for transaction/span data sent to the S4S upstream. This reduces transaction volume while keeping complete traces together. ## Changes - Added `store.s4s-transaction-sample-rate` option (default `1.0` = keep all) - Extracted `_should_drop_s4s()` method on `MultiplexingTransport` - Deterministic sampling using direct hex parsing of trace_id (no hashing needed) - Errors and logs are never dropped - Metrics track both dropped (`s4s_dropped`) and sent (`upstream`) events ## Usage Set `store.s4s-transaction-sample-rate` to `0.05` to keep 5% of transactions. ## Test plan - [x] Unit tests for all sampling paths (default rate, zero rate, errors, determinism, missing trace_id) - [ ] Deploy with `1.0` (no-op) and verify metrics - [ ] Lower to `0.05` and monitor `internal.captured.events.upstream.s4s_dropped` vs `internal.captured.events.upstream` --------- Co-authored-by: Claude <[email protected]> Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
Description
Adds deterministic, trace_id-based sampling for transaction/span data sent to the S4S upstream. This reduces transaction volume while keeping complete traces together.
Changes
store.s4s-transaction-sample-rateoption (default1.0= keep all)_should_drop_s4s()method onMultiplexingTransports4s_dropped) and sent (upstream) eventsUsage
Set
store.s4s-transaction-sample-rateto0.05to keep 5% of transactions.Test plan
1.0(no-op) and verify metrics0.05and monitorinternal.captured.events.upstream.s4s_droppedvsinternal.captured.events.upstream