From 351c788fd7c297f082421563bd42687c7c84314b Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Thu, 27 Aug 2020 11:17:01 -0300 Subject: [PATCH] Renaming ProbabilitySampler to TraceIdRatioBasedSampler (#1174) * Renaming ProbabilitySampler to TraceIdRatioBasedSampler * updating changelog Co-authored-by: Cijo Thomas --- src/OpenTelemetry/CHANGELOG.md | 2 ++ src/OpenTelemetry/README.md | 4 +-- ...Sampler.cs => TraceIdRatioBasedSampler.cs} | 13 +++++----- ...est.cs => TraceIdRatioBasedSamplerTest.cs} | 26 +++++++++---------- 4 files changed, 24 insertions(+), 21 deletions(-) rename src/OpenTelemetry/Trace/{ProbabilitySampler.cs => TraceIdRatioBasedSampler.cs} (87%) rename test/OpenTelemetry.Tests/Trace/{ProbabilitySamplerTest.cs => TraceIdRatioBasedSamplerTest.cs} (76%) diff --git a/src/OpenTelemetry/CHANGELOG.md b/src/OpenTelemetry/CHANGELOG.md index 2a0c0d90734..d816da31890 100644 --- a/src/OpenTelemetry/CHANGELOG.md +++ b/src/OpenTelemetry/CHANGELOG.md @@ -36,6 +36,8 @@ [#1135](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1135)) * Renamed `ParentOrElseSampler` to `ParentBasedSampler` ([#1173](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1173)) +* Renamed `ProbabilitySampler` to `TraceIdRatioBasedSampler` + ([#1174](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1174)) ## 0.4.0-beta.2 diff --git a/src/OpenTelemetry/README.md b/src/OpenTelemetry/README.md index 1336d894528..10f1ade922e 100644 --- a/src/OpenTelemetry/README.md +++ b/src/OpenTelemetry/README.md @@ -58,7 +58,7 @@ reducing the number of samples of traces collected and sent to the backend. If no sampler is explicitly specified, the default is to use [AlwaysOnSampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#alwayson). The following example shows how to change it to -[ProbabilitySampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#probability) +[TraceIdRatioBasedSampler](https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#traceidratiobased) with sampling probability of 25%. ```csharp @@ -67,7 +67,7 @@ using OpenTelemetry.Trace; using var otel = Sdk.CreateTracerProvider(b => b .AddActivitySource("MyCompany.MyProduct.MyLibrary") - .SetSampler(new ProbabilitySampler(0.25)) + .SetSampler(new TraceIdRatioBasedSampler(0.25)) .UseConsoleExporter()); ``` diff --git a/src/OpenTelemetry/Trace/ProbabilitySampler.cs b/src/OpenTelemetry/Trace/TraceIdRatioBasedSampler.cs similarity index 87% rename from src/OpenTelemetry/Trace/ProbabilitySampler.cs rename to src/OpenTelemetry/Trace/TraceIdRatioBasedSampler.cs index dca7e6ee2e8..e5bea683a64 100644 --- a/src/OpenTelemetry/Trace/ProbabilitySampler.cs +++ b/src/OpenTelemetry/Trace/TraceIdRatioBasedSampler.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,18 +21,19 @@ namespace OpenTelemetry.Trace /// /// Samples traces according to the specified probability. /// - public sealed class ProbabilitySampler : Sampler + public sealed class TraceIdRatioBasedSampler + : Sampler { private readonly long idUpperBound; private readonly double probability; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The desired probability of sampling. This must be between 0.0 and 1.0. /// Higher the value, higher is the probability of a given Activity to be sampled in. /// - public ProbabilitySampler(double probability) + public TraceIdRatioBasedSampler(double probability) { if (probability < 0.0 || probability > 1.0) { @@ -41,8 +42,8 @@ public ProbabilitySampler(double probability) this.probability = probability; - // The expected description is like ProbabilitySampler{0.000100} - this.Description = "ProbabilitySampler{" + this.probability.ToString("F6", CultureInfo.InvariantCulture) + "}"; + // The expected description is like TraceIdRatioBasedSampler{0.000100} + this.Description = "TraceIdRatioBasedSampler{" + this.probability.ToString("F6", CultureInfo.InvariantCulture) + "}"; // Special case the limits, to avoid any possible issues with lack of precision across // double/long boundaries. For probability == 0.0, we use Long.MIN_VALUE as this guarantees diff --git a/test/OpenTelemetry.Tests/Trace/ProbabilitySamplerTest.cs b/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs similarity index 76% rename from test/OpenTelemetry.Tests/Trace/ProbabilitySamplerTest.cs rename to test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs index 0c1ee11cab7..b1f9bf84d2a 100644 --- a/test/OpenTelemetry.Tests/Trace/ProbabilitySamplerTest.cs +++ b/test/OpenTelemetry.Tests/Trace/TraceIdRatioBasedSamplerTest.cs @@ -1,4 +1,4 @@ -// +// // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,29 +19,29 @@ namespace OpenTelemetry.Trace.Tests { - public class ProbabilitySamplerTest + public class TraceIdRatioBasedSamplerTest { private const string ActivityDisplayName = "MyActivityName"; private static readonly ActivityKind ActivityKindServer = ActivityKind.Server; [Fact] - public void ProbabilitySampler_OutOfRangeHighProbability() + public void OutOfRangeHighProbability() { - Assert.Throws(() => new ProbabilitySampler(1.01)); + Assert.Throws(() => new TraceIdRatioBasedSampler(1.01)); } [Fact] - public void ProbabilitySampler_OutOfRangeLowProbability() + public void OutOfRangeLowProbability() { - Assert.Throws(() => new ProbabilitySampler(-0.00001)); + Assert.Throws(() => new TraceIdRatioBasedSampler(-0.00001)); } [Fact] - public void ProbabilitySampler_SampleBasedOnTraceId() + public void SampleBasedOnTraceId() { - Sampler defaultProbability = new ProbabilitySampler(0.0001); + Sampler defaultProbability = new TraceIdRatioBasedSampler(0.0001); - // This traceId will not be sampled by the ProbabilitySampler because the first 8 bytes as long + // This traceId will not be sampled by the TraceIdRatioBasedSampler because the first 8 bytes as long // is not less than probability * Long.MAX_VALUE; var notSampledtraceId = ActivityTraceId.CreateFromBytes( @@ -68,7 +68,7 @@ public void ProbabilitySampler_SampleBasedOnTraceId() SamplingDecision.NotRecord, defaultProbability.ShouldSample(new SamplingParameters(default, notSampledtraceId, ActivityDisplayName, ActivityKindServer, null, null)).Decision); - // This traceId will be sampled by the ProbabilitySampler because the first 8 bytes as long + // This traceId will be sampled by the TraceIdRatioBasedSampler because the first 8 bytes as long // is less than probability * Long.MAX_VALUE; var sampledtraceId = ActivityTraceId.CreateFromBytes( @@ -97,10 +97,10 @@ public void ProbabilitySampler_SampleBasedOnTraceId() } [Fact] - public void ProbabilitySampler_GetDescription() + public void GetDescription() { - var expectedDescription = "ProbabilitySampler{0.500000}"; - Assert.Equal(expectedDescription, new ProbabilitySampler(0.5).Description); + var expectedDescription = "TraceIdRatioBasedSampler{0.500000}"; + Assert.Equal(expectedDescription, new TraceIdRatioBasedSampler(0.5).Description); } } }