Skip to content

[WIP] Sampling code extraction#147

Draft
bantonsson wants to merge 3 commits intoproject/sampling-extractionfrom
ban/sampling-extraction-again
Draft

[WIP] Sampling code extraction#147
bantonsson wants to merge 3 commits intoproject/sampling-extractionfrom
ban/sampling-extraction-again

Conversation

@bantonsson
Copy link
Collaborator

What does this PR do?

This PR currently hides all the OTel specific things in the sampling code behind traits, so the sampling logic can be moved to a separate crate.

Motivation

Make the sampling code more generic and move it into a separate crate so it can be reused.

Additional Notes

The benchmarks are on par with the original code. Some improvements and a few minor regressions. There will be additional changes that move the code out.

pub struct TraceRootSamplingInfo {
mechanism: SamplingMechanism,
rate: f64,
rl_effective_rate: Option<i32>,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rl_effective_rate: Option<i32>,
rl_effective_rate: Option<f32>,

? don't we need the rate limiter rate to be a float between 0 and 1?

| mechanism::LOCAL_USER_TRACE_SAMPLING_RULE
| mechanism::REMOTE_USER_TRACE_SAMPLING_RULE
| mechanism::REMOTE_DYNAMIC_TRACE_SAMPLING_RULE
| mechanism::APPSEC
Copy link
Member

Choose a reason for hiding this comment

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

In Python we set appsec to AUTO_KEEP/AUTO_REJECT and not user, is USER_PAIR correct here for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch 👀
We ported the sampler from the python code, a bit before the change fro, user to auto was made in this commit DataDog/dd-trace-py#14043

@bantonsson bantonsson changed the base branch from main to project/sampling-extraction February 13, 2026 13:42
@bantonsson bantonsson force-pushed the ban/sampling-extraction-again branch from 05fa719 to e72fef1 Compare February 13, 2026 13:42
@bantonsson bantonsson force-pushed the ban/sampling-extraction-again branch from e72fef1 to 7dd3ba1 Compare February 13, 2026 14:10
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.

3 participants