Skip to content

feat(sdk): Add configurable S4S transaction sampling#108097

Merged
JoshFerge merged 8 commits intomasterfrom
claude/optimize-sentry-sdk-FhRuz
Feb 19, 2026
Merged

feat(sdk): Add configurable S4S transaction sampling#108097
JoshFerge merged 8 commits intomasterfrom
claude/optimize-sentry-sdk-FhRuz

Conversation

@JoshFerge
Copy link
Copy Markdown
Member

@JoshFerge JoshFerge commented Feb 12, 2026

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

  • 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

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
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 12, 2026
Apply transaction sampling unconditionally when sending to the S4S
upstream, since the S4S DSN always targets s4s2.
Copy link
Copy Markdown
Member

@mwarkentin mwarkentin left a comment

Choose a reason for hiding this comment

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

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).
@JoshFerge JoshFerge changed the title Add transaction sampling for s4s2 region based on trace_id feat(sdk): Add configurable S4S transaction sampling Feb 13, 2026
@JoshFerge JoshFerge marked this pull request as ready for review February 13, 2026 23:23
@JoshFerge JoshFerge requested a review from a team as a code owner February 13, 2026 23:23
@JoshFerge JoshFerge requested a review from mwarkentin February 13, 2026 23:23
Copy link
Copy Markdown
Contributor

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

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Copy link
Copy Markdown
Member

@mwarkentin mwarkentin left a comment

Choose a reason for hiding this comment

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

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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not related to our changes here, but I wonder if this can be cleaned up now? :)

Copy link
Copy Markdown
Member

@markstory markstory left a comment

Choose a reason for hiding this comment

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

This looks like it will work well for transactions. Do we also have to be concerned with span envelopes?

JoshFerge and others added 3 commits February 18, 2026 11:01
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]>
@JoshFerge
Copy link
Copy Markdown
Member Author

This looks like it will work well for transactions. Do we also have to be concerned with span envelopes?

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.

@JoshFerge JoshFerge merged commit bee9759 into master Feb 19, 2026
98 checks passed
@JoshFerge JoshFerge deleted the claude/optimize-sentry-sdk-FhRuz branch February 19, 2026 17:02
JonasBa pushed a commit that referenced this pull request Feb 19, 2026
## 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>
mchen-sentry pushed a commit that referenced this pull request Feb 24, 2026
## 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>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

claude-code-assisted Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants