Skip to content

Commit

Permalink
[AzureMonitor] Change drop sampling result to recordOnly (#933)
Browse files Browse the repository at this point in the history
* change drop sampling result to recordOnly

* fix test

* update change log
  • Loading branch information
vishweshbankwar authored Feb 1, 2023
1 parent cad8d76 commit 98989a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenTelemetry.Extensions.AzureMonitor;
/// </summary>
public class ApplicationInsightsSampler : Sampler
{
private static readonly SamplingResult DropSamplingResult = new(false);
private static readonly SamplingResult RecordOnlySamplingResult = new(SamplingDecision.RecordOnly);
private readonly SamplingResult recordAndSampleSamplingResult;
private readonly float samplingRatio;

Expand Down Expand Up @@ -63,7 +63,7 @@ public override SamplingResult ShouldSample(in SamplingParameters samplingParame
{
if (this.samplingRatio == 0)
{
return DropSamplingResult;
return RecordOnlySamplingResult;
}

if (this.samplingRatio == 1)
Expand All @@ -79,7 +79,7 @@ public override SamplingResult ShouldSample(in SamplingParameters samplingParame
}
else
{
return DropSamplingResult;
return RecordOnlySamplingResult;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Extensions.AzureMonitor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

* Sampler will now return `RecordOnly` SamplingResult when the telemetry is
sampled out.
([#933](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/933))

## 1.0.0-beta.2

Released 2022-Sept-12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void VerifyHashAlgorithmCorrectness()

// Verify sample ratio: 0
ApplicationInsightsSampler zeroSampler = new ApplicationInsightsSampler(samplingRatio: 0);
Assert.Equal(SamplingDecision.Drop, zeroSampler.ShouldSample(testParams1).Decision);
Assert.Equal(SamplingDecision.Drop, zeroSampler.ShouldSample(testParams2).Decision);
Assert.Equal(SamplingDecision.RecordOnly, zeroSampler.ShouldSample(testParams1).Decision);
Assert.Equal(SamplingDecision.RecordOnly, zeroSampler.ShouldSample(testParams2).Decision);

// Verify sample ratio: 1
ApplicationInsightsSampler oneSampler = new ApplicationInsightsSampler(samplingRatio: 1);
Expand All @@ -61,7 +61,7 @@ public void VerifyHashAlgorithmCorrectness()
// Verify sample ratio: 0.5.
// This is below the sample score for testId2, but strict enough to drop testId1
ApplicationInsightsSampler ratioSampler = new ApplicationInsightsSampler(samplingRatio: 0.5f);
Assert.Equal(SamplingDecision.Drop, ratioSampler.ShouldSample(testParams1).Decision);
Assert.Equal(SamplingDecision.RecordOnly, ratioSampler.ShouldSample(testParams1).Decision);
Assert.Equal(SamplingDecision.RecordAndSample, ratioSampler.ShouldSample(testParams2).Decision);
}

Expand Down

0 comments on commit 98989a0

Please sign in to comment.