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

feat: Deterministic Sampler #51

Merged
merged 16 commits into from
Jan 17, 2023
Merged

feat: Deterministic Sampler #51

merged 16 commits into from
Jan 17, 2023

Conversation

emilyashley
Copy link
Contributor

@emilyashley emilyashley commented Dec 16, 2022

Which problem is this PR solving?

Short description of the changes

  • Creates a DeterministicSampler that uses a given sample rate from our HoneycombOptions to determine which Sampler to use: ON, OFF, or TraceRatioID and returns a SamplingResult.
  • Each of these samplers uses the parent based implementation that respects its parent span's sampling decision.
  • Adjusted sample rate options for zero

How to verify that this has the expected result

Try playing around with the example (/examples/hello-world-flask) and Honeycomb Usage Mode.
HONEYCOMB_API_KEY=[redacted] OTEL_SERVICE_NAME=“hello-world-flask” SAMPLE_RATE=3 DEBUG=TRUE poetry run opentelemetry-instrument flask run and curl localhost:5000

Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looking good so far - I've added some early feedback.

honeycomb/opentelemetry/distro.py Outdated Show resolved Hide resolved
.pylintrc Outdated Show resolved Hide resolved
honeycomb/opentelemetry/trace.py Outdated Show resolved Hide resolved
tests/test_sampler.py Outdated Show resolved Hide resolved
@@ -296,7 +301,8 @@ def __init__(

self.sample_rate = parse_int(
SAMPLE_RATE,
(sample_rate or DEFAULT_SAMPLE_RATE),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to edit the way we do this here a lil, since 0 is falsey but it's still a valid sample rate parameter.

@@ -177,6 +177,14 @@ def test_can_set_sample_rate_with_param():
options = HoneycombOptions(sample_rate=123)
assert options.sample_rate == 123

def test_can_set_sample_rate_of_zero_param():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

added these tests to ensure setting 0 (a falsey value in python) still makes it through and set as a sample rate!

@emilyashley emilyashley marked this pull request as ready for review January 12, 2023 21:51
@emilyashley emilyashley requested a review from a team January 12, 2023 21:51

class DeterministicSampler(Sampler):
"""
Custom samplers can be created by subclassing Sampler and implementing
Copy link
Contributor Author

@emilyashley emilyashley Jan 12, 2023

Choose a reason for hiding this comment

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

OPE! I forgot to change this filler docstring. I'll get it!

@MikeGoldsmith MikeGoldsmith added this to the Beta milestone Jan 13, 2023
Copy link
Contributor

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

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

Looks great - good work @emilyashley 👍🏻

Copy link
Contributor

@pkanal pkanal left a comment

Choose a reason for hiding this comment

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

Looks great! Left a couple of non-blocking comments 🚀

)


def test_sample_with_undefined_rate_defaults_to_DEFAULT_ON_and_recorded():
Copy link
Contributor

Choose a reason for hiding this comment

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

TY for these detailed tests! ✨

undefined_rate_sampler = configure_sampler()
# test the `DEFAULT_SAMPLE_RATE` is applied (i.e. 1)
assert undefined_rate_sampler.rate == DEFAULT_SAMPLE_RATE
# test the inner DeterministicSampler choice
Copy link
Contributor

Choose a reason for hiding this comment

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

For these subtest cases, is it possible to do sub tests in python? or perhaps make them their own test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good call! I don't know offhand but I'll look into it as we build out more features and tests.

self.rate = rate

if self.rate <= 0:
# Sampler that respects its parent span's sampling decision,
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments are super helpful 👍🏽

ratio = 1.0 / self.rate
self._sampler = ParentBasedTraceIdRatio(ratio)

# pylint: disable=too-many-arguments
Copy link
Contributor

Choose a reason for hiding this comment

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

Are too-many-arguments out of our control in this case because we're using the should_sample args from OTel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, we gotta match upstream 👍

@emilyashley emilyashley merged commit 8c75623 into main Jan 17, 2023
@emilyashley emilyashley deleted the emash-sampler branch January 17, 2023 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Honeycomb deterministic sampler
3 participants