Skip to content

Commit

Permalink
[Tests] Simplify usage of SamplingResult constructor (#1915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Jun 20, 2024
1 parent 51d3675 commit 9114d0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,7 @@ private class TestSampler(SamplingDecision samplingDecision, IEnumerable<KeyValu

public override SamplingResult ShouldSample(in SamplingParameters samplingParameters)
{
if (this.attributes != null)
{
return new SamplingResult(this.samplingDecision, this.attributes);
}

return new SamplingResult(this.samplingDecision);
return new SamplingResult(this.samplingDecision, this.attributes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public async Task CanRecordAndSampleSearchCall()
var sampler = new TestSampler
{
SamplingAction =
(samplingParameters) =>
_ =>
{
samplerCalled = true;
return new SamplingResult(SamplingDecision.RecordAndSample);
Expand All @@ -207,7 +207,7 @@ public async Task CanRecordAndSampleSearchCall()
{
Assert.True(samplerCalled);
Assert.False(Sdk.SuppressInstrumentation);
Assert.True(a.IsAllDataRequested); // If Proccessor.OnStart is called, activity's IsAllDataRequested is set to true
Assert.True(a.IsAllDataRequested); // If Processor.OnStart is called, activity's IsAllDataRequested is set to true
startCalled++;
};

Expand Down Expand Up @@ -250,7 +250,7 @@ public async Task CanSupressDownstreamActivities()
var sampler = new TestSampler
{
SamplingAction =
(samplingParameters) =>
_ =>
{
samplerCalled = true;
return new SamplingResult(SamplingDecision.RecordAndSample);
Expand All @@ -267,7 +267,7 @@ public async Task CanSupressDownstreamActivities()
{
Assert.True(samplerCalled);
Assert.False(Sdk.SuppressInstrumentation);
Assert.True(a.IsAllDataRequested); // If Proccessor.OnStart is called, activity's IsAllDataRequested is set to true
Assert.True(a.IsAllDataRequested); // If Processor.OnStart is called, activity's IsAllDataRequested is set to true
startCalled++;
};

Expand Down Expand Up @@ -310,7 +310,7 @@ public async Task CanDropSearchCall()
var sampler = new TestSampler
{
SamplingAction =
(samplingParameters) =>
_ =>
{
samplerCalled = true;
return new SamplingResult(SamplingDecision.Drop);
Expand All @@ -327,7 +327,7 @@ public async Task CanDropSearchCall()
{
Assert.True(samplerCalled);
Assert.False(Sdk.SuppressInstrumentation);
Assert.False(a.IsAllDataRequested); // If Proccessor.OnStart is called, activity's IsAllDataRequested is set to true
Assert.False(a.IsAllDataRequested); // If Processor.OnStart is called, activity's IsAllDataRequested is set to true
startCalled++;
};

Expand Down Expand Up @@ -740,7 +740,7 @@ public async Task CapturesBasedOnSamplingDecision(SamplingDecision samplingDecis
var client = new ElasticClient(new ConnectionSettings(new InMemoryConnection()).DefaultIndex("customer"));

using (Sdk.CreateTracerProviderBuilder()
.SetSampler(new TestSampler() { SamplingAction = (samplingParameters) => new SamplingResult(samplingDecision) })
.SetSampler(new TestSampler() { SamplingAction = _ => new SamplingResult(samplingDecision) })
.AddElasticsearchClientInstrumentation()
.SetResourceBuilder(expectedResource)
.AddProcessor(processor)
Expand Down

0 comments on commit 9114d0b

Please sign in to comment.