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 a provider for consistent parent based probability sampler #1005

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions consistent-sampling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ otelJava.moduleName.set("io.opentelemetry.contrib.sampler.consistent")

dependencies {
api("io.opentelemetry:opentelemetry-sdk-trace")
api("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi")
testImplementation("org.hipparchus:hipparchus-core:2.3")
testImplementation("org.hipparchus:hipparchus-stat:2.3")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.contrib.sampler.consistent;

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSamplerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;

public final class ConsistentParentBasedProbabilitySamplerProvider
implements ConfigurableSamplerProvider {

@Override
public Sampler createSampler(ConfigProperties config) {
double samplingProbability = config.getDouble("otel.traces.sampler.arg", 1.0d);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you want to force the samplingProbability into the interval [0.0, 1.0]? If out of the range, an exception will be thrown by the statement below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ConsistentProbabilityBasedSampler is already throwing an IllegalArgumentException if it's not within the range.

https://github.com/open-telemetry/opentelemetry-java-contrib/blob/main/consistent-sampling/src/main/java/io/opentelemetry/contrib/sampler/consistent/ConsistentProbabilityBasedSampler.java#L31-L33

if (samplingProbability < 0.0 || samplingProbability > 1.0) {
  throw new IllegalArgumentException("Sampling probability must be in range [0.0, 1.0]!");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly my point. I just wondered if this is the behavior you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I misread your comment.

Yes and I believe that was @oertl's intention as well.
TraceIdRatioBasedSampler in java sdk also has the same behaviour.
We could default to 1.0, but I think failing here would probably be more explicit.

return ConsistentSampler.parentBased(ConsistentSampler.probabilityBased(samplingProbability));
}

@Override
public String getName() {
return "consistent_parent_based_probability";
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would consistent_parentbased_probability work?

Copy link
Member

Choose a reason for hiding this comment

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

how about

  • consistent_always_on
  • consistent_always_off
  • consistent_probability
  • consistent_rate_limit
  • parentbased_consistent_always_on
  • parentbased_consistent_always_off
  • parentbased_consistent_probability
  • parentbased_consistent_rate_limit

(don't need to add them all in this PR, but trying to understand the naming pattern)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, updated to parentbased_consistent_probability

Copy link
Contributor

@laurit laurit Aug 18, 2023

Choose a reason for hiding this comment

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

could you also rename the sampler provider class to match the name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.opentelemetry.contrib.sampler.consistent.ConsistentParentBasedProbabilitySamplerProvider