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 doc comments for Samplers. #617

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/OpenTelemetry/Trace/Samplers/AlwaysOffSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

namespace OpenTelemetry.Trace.Samplers
{
/// <summary>
/// Sampler implementation which will sample out all the spans.
/// </summary>
public sealed class AlwaysOffSampler : Sampler
{
/// <inheritdoc />
public override string Description { get; } = nameof(AlwaysOffSampler);

/// <inheritdoc />
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry/Trace/Samplers/AlwaysOnSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@

namespace OpenTelemetry.Trace.Samplers
{
/// <summary>
/// Sampler implementation which will sample in all the spans.
/// This sampler will be used as the default Sampler, if no other Sampler is configured.
/// </summary>
public sealed class AlwaysOnSampler : Sampler
{
/// <inheritdoc />
public override string Description { get; } = nameof(AlwaysOnSampler);

/// <inheritdoc />
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry/Trace/Samplers/AlwaysParentSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@

namespace OpenTelemetry.Trace.Samplers
{
/// <summary>
/// Sampler implementation which will sample in, if parent span is sampled in.
/// If parent span is invalid, span is sampled out.
/// </summary>
public sealed class AlwaysParentSampler : Sampler
{
/// <inheritdoc />
public override string Description { get; } = nameof(AlwaysParentSampler);

/// <inheritdoc />
Expand Down
17 changes: 15 additions & 2 deletions src/OpenTelemetry/Trace/Samplers/ProbabilitySampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@

namespace OpenTelemetry.Trace.Samplers
{
/// <inheritdoc />
/// <summary>
/// Sampler implementation which will sample in, if parent span or any linked span is sampled in.
/// Otherwise, samples in a percentage of the spans.
/// The probability of sampling a span is equal to that of the specified probability.
/// </summary>
public sealed class ProbabilitySampler : Sampler
{
private readonly long idUpperBound;
private readonly double probability;

/// <summary>
/// Initializes a new instance of the <see cref="ProbabilitySampler"/> class.
/// </summary>
/// <param name="probability">The desired probability of sampling. This must be between 0.0 and 1.0.
/// Higher the value, higher is the probability of a given span to be sampled in.
/// </param>
public ProbabilitySampler(double probability)
{
if (probability < 0.0 || probability > 1.0)
Expand All @@ -33,7 +43,10 @@ public ProbabilitySampler(double probability)
}

this.probability = probability;
this.Description = $"ProbabilitySampler({this.probability:F6})";

// The expected description is like ProbabilitySampler{0.000100}
// https://docs.microsoft.com/dotnet/standard/base-types/composite-formatting#escaping-braces
this.Description = string.Format("{0}{1:F6}{2}", "ProbabilitySampler{", this.probability, "}");

// 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
Expand Down
3 changes: 2 additions & 1 deletion test/OpenTelemetry.Tests/Impl/Trace/Samplers/SamplersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ public void ProbabilitySampler_SampleBasedOnTraceId()
[Fact]
public void ProbabilitySampler_GetDescription()
{
Assert.Equal($"ProbabilitySampler({0.5:F6})", new ProbabilitySampler(0.5).Description);
var expectedDescription = "ProbabilitySampler{0.500000}";
Assert.Equal(expectedDescription, new ProbabilitySampler(0.5).Description);
}

// Applies the given sampler to NUM_SAMPLE_TRIES random traceId/spanId pairs.
Expand Down