Skip to content

Commit

Permalink
Simplify sampler description (#895)
Browse files Browse the repository at this point in the history
* simplify sampler description

* only allow get

* protected setter

* steal code from Mikel

* fix comment

* fix ci

Co-authored-by: Cijo Thomas <[email protected]>
  • Loading branch information
reyang and cijothomas authored Jul 23, 2020
1 parent 2dd8daa commit a03af9e
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 18 deletions.
9 changes: 7 additions & 2 deletions src/OpenTelemetry/Trace/Sampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ namespace OpenTelemetry.Trace
/// </summary>
public abstract class Sampler
{
protected Sampler()
{
this.Description = this.GetType().Name;
}

/// <summary>
/// Gets the sampler description.
/// Gets or sets the sampler description.
/// </summary>
public abstract string Description { get; }
public string Description { get; protected set; }

/// <summary>
/// Checks whether activity needs to be created and tracked.
Expand Down
3 changes: 0 additions & 3 deletions src/OpenTelemetry/Trace/Samplers/AlwaysOffSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ namespace OpenTelemetry.Trace.Samplers
/// </summary>
public sealed class AlwaysOffSampler : Sampler
{
/// <inheritdoc />
public override string Description { get; } = "AlwaysOffSampler";

/// <inheritdoc />
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
Expand Down
3 changes: 0 additions & 3 deletions src/OpenTelemetry/Trace/Samplers/AlwaysOnSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ namespace OpenTelemetry.Trace.Samplers
/// </summary>
public sealed class AlwaysOnSampler : Sampler
{
/// <inheritdoc />
public override string Description { get; } = "AlwaysOnSampler";

/// <inheritdoc />
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
Expand Down
3 changes: 0 additions & 3 deletions src/OpenTelemetry/Trace/Samplers/ParentOrElseSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public ParentOrElseSampler(Sampler delegateSampler)
this.Description = $"ParentOrElse{{{delegateSampler.Description}}}";
}

/// <inheritdoc />
public override string Description { get; }

/// <inheritdoc />
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
Expand Down
3 changes: 0 additions & 3 deletions src/OpenTelemetry/Trace/Samplers/ProbabilitySampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public ProbabilitySampler(double probability)
}
}

/// <inheritdoc />
public override string Description { get; }

/// <inheritdoc />
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private class TestSampler : Sampler

public SamplingParameters LatestSamplingParameters { get; private set; }

public override string Description { get; } = nameof(TestSampler);

public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
this.LatestSamplingParameters = samplingParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ private class TestSampler : Sampler
{
public Func<SamplingParameters, SamplingResult> SamplingAction { get; set; }

public override string Description { get; } = nameof(TestSampler);

public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
return this.SamplingAction?.Invoke(samplingParameters) ?? new SamplingResult(true);
Expand Down

0 comments on commit a03af9e

Please sign in to comment.