Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rule-based sampler #4152

Closed
wants to merge 5 commits into from

Conversation

brettmc
Copy link
Contributor

@brettmc brettmc commented Jul 17, 2024

This is based on PHP's implementation of a rules-based sampler, which itself is based on and expands on Java's rule-based samplers.

Looking through other SIGs repositories, I didn't find any other similar implementations to try to integrate with this.

Related: open-telemetry/opentelemetry-configuration#102 (comment)
Prototype: open-telemetry/opentelemetry-php-contrib#279

For non-trivial changes, follow the change proposal process.

this is based on PHP's implementation of a rules-based sampler, which itself is based on extending Java's implementation.
@brettmc brettmc requested review from a team July 17, 2024 03:50
@@ -79,6 +79,7 @@ formats is required. Implementing more than one format is optional.
| [Sampling](specification/trace/sdk.md#sampling) | Optional | Go | Java | JS | Python | Ruby | Erlang | PHP | Rust | C++ | .NET | Swift |
| Allow samplers to modify tracestate | | + | + | | + | + | + | + | + | + | + | + |
| ShouldSample gets full parent Context | | + | + | + | + | + | + | + | + | + | - | + |
| Sampler: RulesBasedSampler | Optional | | | | | | | | | | | |
Copy link
Member

Choose a reason for hiding this comment

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

is there already a spec for rule based samplers? If so, please link to it. Otherwise we can't add something to compliance matrix that isn't spec-ed yet.

Copy link
Contributor Author

@brettmc brettmc Jul 17, 2024

Choose a reason for hiding this comment

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

linked. the spec change to add a rule-based sampler is the main focus of this PR, so I assumed it would be both-or-neither.

@brettmc brettmc changed the title adding rule-based sampler add rule-based sampler Jul 17, 2024
* A `RuleBased` sampler MUST be configured with a set of rules and a fallback
`Sampler` to use if the `Span` does not match any of the configured rules. The
rules MUST be processed in the order they were provided.
* A `Rule` requires a list of tests, and a delegate `Sampler` to be invoked if
Copy link
Member

Choose a reason for hiding this comment

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

This describes a specific implementation of Rule. As an abstraction a Rule is just a Sampler, is it not?

And the RuleBased sampler itself seems just like a stand-in for logical expression, discussed in #1844

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This describes a specific implementation of Rule. As an abstraction a Rule is just a Sampler, is it not?

No, it's not a Sampler by itself. A rule is a logical expression which is applied to a component of ShouldSample (eg span name, or attributes), and will evaluate to true or false. If all of the rules in a set are true, then the associated Sampler is invoked.

And the RuleBased sampler itself seems just like a stand-in for logical expression, discussed in #1844

It's related to #1844, because that spawned Java's RuleBasedRoutingSampler which in turn influenced this PR. So I think this PR is the implementation that resolves #1844 at spec level.

Copy link
Member

@yurishkuro yurishkuro Jul 17, 2024

Choose a reason for hiding this comment

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

a logical expression which is applied to [a span], and will evaluate to true or false.

That's almost exactly the definition of a sampler.

So I think this PR is the implementation that resolves #1844 at spec level.

Actually I meant this OTEP https://github.com/open-telemetry/oteps/pull/250/files.

@dmathieu
Copy link
Member

Advanced rule like this seems weird within an application. I'd personally expect this to be in the collector, not in an SDK.

@brettmc
Copy link
Contributor Author

brettmc commented Jul 17, 2024

Advanced rule like this seems weird within an application. I'd personally expect this to be in the collector, not in an SDK.

@dmathieu all of the options within the rules are based on Sampler's ShouldSample arguments provided for the purpose of making sampling decisions, so it seems fair to make them available for that purpose. I agree that the most asked-for case is simply to ignore health checks though.

@carlosalberto
Copy link
Contributor

cc @jmacd

@arminru arminru added the area:sampling Related to trace sampling label Jul 23, 2024
Copy link

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jul 31, 2024
Copy link

github-actions bot commented Aug 7, 2024

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:sampling Related to trace sampling Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants