Skip to content
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
2 changes: 2 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
[#1127](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1127)
[#1129](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1129)
[#1135](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1135))
* Renamed `ParentOrElseSampler` to `ParentBasedSampler`
([#1173](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1173))

## 0.4.0-beta.2

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ParentOrElseSampler.cs" company="OpenTelemetry Authors">
// <copyright file="ParentBasedSampler.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,19 +22,19 @@ namespace OpenTelemetry.Trace
/// Sampler implementation which will take a sample if parent Activity or any linked Activity is sampled.
/// Otherwise, samples root traces according to the specified delegate sampler.
/// </summary>
public sealed class ParentOrElseSampler : Sampler
public sealed class ParentBasedSampler : Sampler
{
private readonly Sampler delegateSampler;

/// <summary>
/// Initializes a new instance of the <see cref="ParentOrElseSampler"/> class.
/// Initializes a new instance of the <see cref="ParentBasedSampler"/> class.
/// </summary>
/// <param name="delegateSampler">The <see cref="Sampler"/> to be called to decide whether or not to sample a root trace.</param>
public ParentOrElseSampler(Sampler delegateSampler)
public ParentBasedSampler(Sampler delegateSampler)
{
this.delegateSampler = delegateSampler ?? throw new ArgumentNullException(nameof(delegateSampler));

this.Description = $"ParentOrElse{{{delegateSampler.Description}}}";
this.Description = $"ParentBased{{{delegateSampler.Description}}}";
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/TracerProviderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TracerProviderBuilder
private readonly List<ActivityProcessor> processors = new List<ActivityProcessor>();
private readonly List<string> sources = new List<string>();
private Resource resource = Resource.Empty;
private Sampler sampler = new ParentOrElseSampler(new AlwaysOnSampler());
private Sampler sampler = new ParentBasedSampler(new AlwaysOnSampler());

internal TracerProviderBuilder()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ParentOrElseSamplerTests.cs" company="OpenTelemetry Authors">
// <copyright file="ParentBasedSamplerTests.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,28 +18,28 @@

namespace OpenTelemetry.Trace.Tests
{
public class ParentOrElseSamplerTests
public class ParentBasedSamplerTests
{
private readonly ParentOrElseSampler parentOrElseAlwaysOnSampler = new ParentOrElseSampler(new AlwaysOnSampler());
private readonly ParentOrElseSampler parentOrElseAlwaysOffSampler = new ParentOrElseSampler(new AlwaysOffSampler());
private readonly ParentBasedSampler parentBasedOnSampler = new ParentBasedSampler(new AlwaysOnSampler());
private readonly ParentBasedSampler parentBasedOffSampler = new ParentBasedSampler(new AlwaysOffSampler());

[Fact]
public void ParentOrElseSampler_SampledParent()
public void SampledParent()
{
// No parent, use delegate sampler.
Assert.Equal(
new SamplingResult(SamplingDecision.RecordAndSampled),
this.parentOrElseAlwaysOnSampler.ShouldSample(default));
this.parentBasedOnSampler.ShouldSample(default));

// No parent, use delegate sampler.
Assert.Equal(
new SamplingResult(SamplingDecision.NotRecord),
this.parentOrElseAlwaysOffSampler.ShouldSample(default));
this.parentBasedOffSampler.ShouldSample(default));

// Not sampled parent, don't sample.
Assert.Equal(
new SamplingResult(SamplingDecision.NotRecord),
this.parentOrElseAlwaysOnSampler.ShouldSample(
this.parentBasedOnSampler.ShouldSample(
new SamplingParameters(
parentContext: new ActivityContext(
ActivityTraceId.CreateRandom(),
Expand All @@ -52,7 +52,7 @@ public void ParentOrElseSampler_SampledParent()
// Sampled parent, sample.
Assert.Equal(
new SamplingResult(SamplingDecision.RecordAndSampled),
this.parentOrElseAlwaysOffSampler.ShouldSample(
this.parentBasedOffSampler.ShouldSample(
new SamplingParameters(
parentContext: new ActivityContext(
ActivityTraceId.CreateRandom(),
Expand All @@ -64,7 +64,7 @@ public void ParentOrElseSampler_SampledParent()
}

[Fact]
public void ParentOrElseSampler_SampledParentLink()
public void SampledParentLink()
{
var notSampledLink = new ActivityLink[]
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public void ParentOrElseSampler_SampledParentLink()
// Not sampled link, don't sample.
Assert.Equal(
new SamplingResult(SamplingDecision.NotRecord),
this.parentOrElseAlwaysOnSampler.ShouldSample(
this.parentBasedOnSampler.ShouldSample(
new SamplingParameters(
parentContext: notSampledParent,
traceId: default,
Expand All @@ -103,7 +103,7 @@ public void ParentOrElseSampler_SampledParentLink()
// Sampled link, sample.
Assert.Equal(
new SamplingResult(SamplingDecision.RecordAndSampled),
this.parentOrElseAlwaysOffSampler.ShouldSample(
this.parentBasedOffSampler.ShouldSample(
new SamplingParameters(
parentContext: notSampledParent,
traceId: default,
Expand Down