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

attribute-based sampler #1208

Closed
wants to merge 8 commits into from
Closed

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Jan 11, 2024

this adds an attribute-based sampler, which can be configured to inspect a semconv attribute on a span, and either sample it in or out by applying a PCRE regex to it.
adding an alternative syntax to define samplers and sampler args from env vars. now we also support "sampler1,...,samplerN" chaining of samplers, and the ability to define sampler args via ".=,..."

this adds an attribute-based sampler, which can be configured to inspect a semconv attribute on a span, and either sample it
in our out by applying a PCRE regex to it.
adding an alternative syntax to define samplers and sampler args from env vars. now we also support "sampler1,...,samplerN" chaining
of samplers, and the ability to define sampler args via "<samplername>.<arg>=<value>,..."
@brettmc
Copy link
Collaborator Author

brettmc commented Jan 11, 2024

The primary use-case for this would be to sample out URLs like /health which are very repetitive and of little value.

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (102f5dc) 83.20% compared to head (47bd899) 83.38%.
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1208      +/-   ##
============================================
+ Coverage     83.20%   83.38%   +0.18%     
- Complexity     2262     2293      +31     
============================================
  Files           285      286       +1     
  Lines          6435     6507      +72     
============================================
+ Hits           5354     5426      +72     
  Misses         1081     1081              
Flag Coverage Δ
7.4 82.03% <100.00%> (+0.20%) ⬆️
8.0 83.28% <100.00%> (+0.18%) ⬆️
8.1 83.44% <100.00%> (+0.18%) ⬆️
8.2 83.42% <98.59%> (+0.16%) ⬆️
8.3 83.42% <98.59%> (+0.16%) ⬆️
8.4 83.42% <98.59%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/Contrib/Otlp/SpanConverter.php 99.00% <100.00%> (ø)
src/SDK/Trace/Sampler/AttributeBasedSampler.php 100.00% <100.00%> (ø)
src/SDK/Trace/SamplerFactory.php 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1af8334...47bd899. Read the comment docs.

@bobstrecansky bobstrecansky marked this pull request as ready for review January 17, 2024 13:05
@bobstrecansky bobstrecansky requested a review from a team January 17, 2024 13:05
Copy link
Contributor

@Nevay Nevay left a comment

Choose a reason for hiding this comment

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

I think we should at least allow matching on SpanKind too, similar to Javas RuleBasedRoutingSampler.

If we want to allow for a wider range of configuration options: I did some prototyping that unifies Javas RuleBasedRoutingSampler and LinksBasedSampler in a single RuleBasedSampler. (We could still keep the "attribute" env configuration and create a RuleBasedSampler with an AttributeRule (+ optional attribute.spankind SpanKindRule)).

switch ($this->mode) {
case self::ALLOW:
if (!$attributes->has($this->attribute)) {
return new SamplingResult(SamplingResult::DROP);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return new SamplingResult(SamplingResult::DROP);
break;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did some prototyping that unifies Javas RuleBasedRoutingSampler and LinksBasedSampler

I was just reading about the idea of a rule-based sampler in this OTEP and I like the idea of using that approach over what I've done here, given the increased usefulness (and hopefully also compatibility with the proposed sampling configuration).

The prototype looks great, I think we should go with that approach. For the time being, it might not be configurable via env vars (and so not available to auto-instrumentation/sdk-autoloading) due to the complexity of the configuration.

@@ -19,6 +19,7 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-json": "*",
"ext-pcre": "*",
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we shouldn't list core extensions as requirement

@brettmc brettmc marked this pull request as draft January 18, 2024 03:08
@brettmc
Copy link
Collaborator Author

brettmc commented Jan 18, 2024

Setting back to draft, because it probably won't be merged as-is...

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