diff --git a/src/OpenTelemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs b/src/OpenTelemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs
index 0aa3aa32d8..4c8497ede1 100644
--- a/src/OpenTelemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs
+++ b/src/OpenTelemetry.Sampler.AWS/AWSXRayRemoteSamplerBuilder.cs
@@ -62,7 +62,7 @@ public AWSXRayRemoteSamplerBuilder SetPollingInterval(TimeSpan pollingInterval)
///
/// Sets the endpoint for the TCP proxy to connect to. This is the address to the port on the
- /// OpenTelemetry Collector configured for proxying X-Ray sampling requests.If unset, defaults to
+ /// OpenTelemetry Collector configured for proxying X-Ray sampling requests. If unset, defaults to
/// .
///
/// the endpoint for the TCP proxy.
@@ -90,12 +90,7 @@ public AWSXRayRemoteSampler Build()
// Should not be exposed to public.
internal AWSXRayRemoteSamplerBuilder SetClock(Clock clock)
{
- if (clock == null)
- {
- throw new ArgumentNullException(nameof(clock));
- }
-
- this.clock = clock;
+ this.clock = clock ?? throw new ArgumentNullException(nameof(clock));
return this;
}
diff --git a/src/OpenTelemetry.Sampler.AWS/SamplingRuleApplier.cs b/src/OpenTelemetry.Sampler.AWS/SamplingRuleApplier.cs
index 56cc0f0443..3450c30577 100644
--- a/src/OpenTelemetry.Sampler.AWS/SamplingRuleApplier.cs
+++ b/src/OpenTelemetry.Sampler.AWS/SamplingRuleApplier.cs
@@ -24,7 +24,7 @@ namespace OpenTelemetry.Sampler.AWS;
internal class SamplingRuleApplier
{
- public SamplingRuleApplier(string clientId, Clock clock, SamplingRule rule, Statistics statistics)
+ public SamplingRuleApplier(string clientId, Clock clock, SamplingRule rule, Statistics? statistics)
{
this.ClientId = clientId;
this.Clock = clock;
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj b/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
index e0fb3a51f5..59ebd9591e 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/OpenTelemetry.Sampler.AWS.Tests.csproj
@@ -3,6 +3,7 @@
net7.0;net6.0
$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)
+ enable
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRayRemoteSampler.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRayRemoteSampler.cs
index 652165e0ab..aab1148cdc 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRayRemoteSampler.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRayRemoteSampler.cs
@@ -68,7 +68,7 @@ public void TestSamplerUpdateAndSample()
// create sampler
AWSXRayRemoteSampler sampler = AWSXRayRemoteSampler.Builder(ResourceBuilder.CreateEmpty().Build())
.SetPollingInterval(TimeSpan.FromMilliseconds(10))
- .SetEndpoint(mockServer.Url)
+ .SetEndpoint(mockServer.Url!)
.SetClock(clock)
.Build();
@@ -117,9 +117,9 @@ private SamplingDecision DoSample(Trace.Sampler sampler, string serviceName)
ActivityTraceId.CreateRandom(),
"myActivityName",
ActivityKind.Server,
- new List>()
+ new List>
{
- new KeyValuePair("test", serviceName),
+ new("test", serviceName),
},
null);
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRaySamplerClient.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRaySamplerClient.cs
index fa78d9a108..863024a6cd 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRaySamplerClient.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestAWSXRaySamplerClient.cs
@@ -26,14 +26,14 @@ namespace OpenTelemetry.Sampler.AWS.Tests;
public class TestAWSXRaySamplerClient : IDisposable
{
- private WireMockServer mockServer;
+ private readonly WireMockServer mockServer;
- private AWSXRaySamplerClient client;
+ private readonly AWSXRaySamplerClient client;
public TestAWSXRaySamplerClient()
{
this.mockServer = WireMockServer.Start();
- this.client = new AWSXRaySamplerClient(this.mockServer.Url);
+ this.client = new AWSXRaySamplerClient(this.mockServer.Url!);
}
public void Dispose()
@@ -116,23 +116,23 @@ public void TestGetSamplingTargets()
this.CreateResponse("/SamplingTargets", "Data/GetSamplingTargetsResponse.json");
- var request = new GetSamplingTargetsRequest(new List()
+ var request = new GetSamplingTargetsRequest(new List
{
- new SamplingStatisticsDocument(
+ new(
"clientId",
"rule1",
100,
50,
10,
clock.ToDouble(clock.Now())),
- new SamplingStatisticsDocument(
+ new(
"clientId",
"rule2",
200,
100,
20,
clock.ToDouble(clock.Now())),
- new SamplingStatisticsDocument(
+ new(
"clientId",
"rule3",
20,
@@ -144,7 +144,7 @@ public void TestGetSamplingTargets()
var responseTask = this.client.GetSamplingTargets(request);
responseTask.Wait();
- GetSamplingTargetsResponse targetsResponse = responseTask.Result;
+ GetSamplingTargetsResponse targetsResponse = responseTask.Result!;
Assert.Equal(2, targetsResponse.SamplingTargetDocuments.Count);
Assert.Single(targetsResponse.UnprocessedStatistics);
@@ -175,9 +175,9 @@ public void TestGetSamplingTargetsWithMalformed()
.RespondWith(
Response.Create().WithStatusCode(200).WithHeader("Content-Type", "application/json").WithBody("notJson"));
- var request = new GetSamplingTargetsRequest(new List()
+ var request = new GetSamplingTargetsRequest(new List
{
- new SamplingStatisticsDocument(
+ new(
"clientId",
"rule1",
100,
@@ -189,7 +189,7 @@ public void TestGetSamplingTargetsWithMalformed()
var responseTask = this.client.GetSamplingTargets(request);
responseTask.Wait();
- GetSamplingTargetsResponse targetsResponse = responseTask.Result;
+ GetSamplingTargetsResponse? targetsResponse = responseTask.Result;
Assert.Null(targetsResponse);
}
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestClock.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestClock.cs
index a5444b3b9a..806f714578 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestClock.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestClock.cs
@@ -20,7 +20,7 @@ namespace OpenTelemetry.Sampler.AWS.Tests;
internal class TestClock : Clock
{
- private static readonly DateTime EpochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
+ private static readonly DateTime EpochStart = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
private DateTime nowTime;
public TestClock()
@@ -55,7 +55,7 @@ public override double ToDouble(DateTime dateTime)
return timestamp;
}
- // Advnaces the clock by a given time span.
+ // Advances the clock by a given time span.
public void Advance(TimeSpan time)
{
this.nowTime = this.nowTime.Add(time);
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestMatcher.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestMatcher.cs
index 3c320f2d81..671810abd2 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestMatcher.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestMatcher.cs
@@ -48,14 +48,14 @@ public void TestWildcardDoesNotMatch(string input, string pattern)
[Fact]
public void TestAttributeMatching()
{
- var tags = new List>()
+ var tags = new List>
{
- new KeyValuePair("dog", "bark"),
- new KeyValuePair("cat", "meow"),
- new KeyValuePair("cow", "mooo"),
+ new("dog", "bark"),
+ new("cat", "meow"),
+ new("cow", "mooo"),
};
- var ruleAttributes = new Dictionary()
+ var ruleAttributes = new Dictionary
{
{ "dog", "bar?" },
{ "cow", "mooo" },
@@ -67,11 +67,11 @@ public void TestAttributeMatching()
[Fact]
public void TestAttributeMatchingWithoutRuleAttributes()
{
- var tags = new List>()
+ var tags = new List>
{
- new KeyValuePair("dog", "bark"),
- new KeyValuePair("cat", "meow"),
- new KeyValuePair("cow", "mooo"),
+ new("dog", "bark"),
+ new("cat", "meow"),
+ new("cow", "mooo"),
};
var ruleAttributes = new Dictionary();
@@ -82,13 +82,13 @@ public void TestAttributeMatchingWithoutRuleAttributes()
[Fact]
public void TestAttributeMatchingWithoutSpanTags()
{
- var ruleAttributes = new Dictionary()
+ var ruleAttributes = new Dictionary
{
{ "dog", "bar?" },
{ "cow", "mooo" },
};
- Assert.False(Matcher.AttributeMatch(new List>(), ruleAttributes));
+ Assert.False(Matcher.AttributeMatch(new List>(), ruleAttributes));
Assert.False(Matcher.AttributeMatch(null, ruleAttributes));
}
}
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestRateLimiter.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestRateLimiter.cs
index 446cb4af6e..a0c60c7d29 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestRateLimiter.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestRateLimiter.cs
@@ -137,7 +137,7 @@ public async Task TestRateLimiterConcurrencyAsync()
TestClock clock = new TestClock();
RateLimiter limiter = new RateLimiter(1, numWorkers * creditsPerWorker, clock);
int count = 0;
- List tasks = new List(numWorkers);
+ List tasks = new(numWorkers);
for (int w = 0; w < numWorkers; ++w)
{
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestRulesCache.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestRulesCache.cs
index eafc974c00..fbfa0fb250 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestRulesCache.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestRulesCache.cs
@@ -42,7 +42,7 @@ public void TestUpdateRules()
// set up rules cache with a default rule
var defaultRule = this.CreateDefaultRule(1, 0.05);
- var stats = new Statistics()
+ var stats = new Statistics
{
RequestCount = 10,
SampleCount = 5,
@@ -51,9 +51,9 @@ public void TestUpdateRules()
var cache = new RulesCache(clock, "test", ResourceBuilder.CreateEmpty().Build(), new AlwaysOffSampler())
{
- RuleAppliers = new List()
+ RuleAppliers = new List
{
- { new SamplingRuleApplier("testId", clock, defaultRule, stats) },
+ { new("testId", clock, defaultRule, stats) },
},
};
@@ -80,10 +80,10 @@ public void TestUpdateRulesRemovesOlderRule()
// set up rule cache with 2 rules
var rulesCache = new RulesCache(clock, "test", ResourceBuilder.CreateEmpty().Build(), new AlwaysOffSampler())
{
- RuleAppliers = new List()
+ RuleAppliers = new List
{
- { new SamplingRuleApplier("testId", clock, this.CreateDefaultRule(1, 0.05), null) },
- { new SamplingRuleApplier("testId", clock, this.CreateRule("Rule1", 5, 0.20, 1), null) },
+ { new("testId", clock, this.CreateDefaultRule(1, 0.05), null) },
+ { new("testId", clock, this.CreateRule("Rule1", 5, 0.20, 1), null) },
},
};
@@ -103,10 +103,10 @@ public void TestShouldSampleMatchesExactRule()
var clock = new TestClock();
var rulesCache = new RulesCache(clock, "clientId", ResourceBuilder.CreateEmpty().Build(), new AlwaysOffSampler())
{
- RuleAppliers = new List()
+ RuleAppliers = new List
{
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("ruleWillMatch", 1, 0.0, 1), new Statistics()) }, // higher priority rule will sample
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("ruleWillNotMatch", 0, 0.0, 2), new Statistics()) }, // this rule will not sample
+ { new("clientId", clock, this.CreateRule("ruleWillMatch", 1, 0.0, 1), new Statistics()) }, // higher priority rule will sample
+ { new("clientId", clock, this.CreateRule("ruleWillNotMatch", 0, 0.0, 2), new Statistics()) }, // this rule will not sample
},
};
@@ -144,10 +144,10 @@ public void TestUpdateTargets()
var clock = new TestClock();
var rulesCache = new RulesCache(clock, "clientId", ResourceBuilder.CreateEmpty().Build(), new AlwaysOffSampler())
{
- RuleAppliers = new List()
+ RuleAppliers = new List
{
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("rule1", 1, 0.0, 1), new Statistics()) }, // this rule will sample 1 req/sec
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("rule2", 0, 0.0, 2), new Statistics()) },
+ { new("clientId", clock, this.CreateRule("rule1", 1, 0.0, 1), new Statistics()) }, // this rule will sample 1 req/sec
+ { new("clientId", clock, this.CreateRule("rule2", 0, 0.0, 2), new Statistics()) },
},
};
@@ -155,7 +155,7 @@ public void TestUpdateTargets()
Assert.Equal(SamplingDecision.Drop, rulesCache.ShouldSample(default).Decision);
// update targets
- var targetForRule1 = new SamplingTargetDocument()
+ var targetForRule1 = new SamplingTargetDocument
{
FixedRate = 0.0,
Interval = 0,
@@ -163,7 +163,7 @@ public void TestUpdateTargets()
ReservoirQuotaTTL = clock.ToDouble(clock.Now().AddMinutes(5)),
RuleName = "rule1",
};
- var targetForRule2 = new SamplingTargetDocument()
+ var targetForRule2 = new SamplingTargetDocument
{
FixedRate = 0.0,
Interval = 0,
@@ -172,7 +172,7 @@ public void TestUpdateTargets()
RuleName = "rule2",
};
- var targets = new Dictionary()
+ var targets = new Dictionary
{
{ "rule1", targetForRule1 },
{ "rule2", targetForRule2 },
@@ -192,15 +192,15 @@ public void TestNextTargetFetchTime()
var clock = new TestClock();
var rulesCache = new RulesCache(clock, "clientId", ResourceBuilder.CreateEmpty().Build(), new AlwaysOffSampler())
{
- RuleAppliers = new List()
+ RuleAppliers = new List
{
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("rule1", 1, 0.0, 1), new Statistics()) },
- { new SamplingRuleApplier("clientId", clock, this.CreateRule("rule2", 0, 0.0, 2), new Statistics()) },
+ { new("clientId", clock, this.CreateRule("rule1", 1, 0.0, 1), new Statistics()) },
+ { new("clientId", clock, this.CreateRule("rule2", 0, 0.0, 2), new Statistics()) },
},
};
// update targets
- var targetForRule1 = new SamplingTargetDocument()
+ var targetForRule1 = new SamplingTargetDocument
{
FixedRate = 0.0,
Interval = 10, // next target poll after 10s
@@ -208,7 +208,7 @@ public void TestNextTargetFetchTime()
ReservoirQuotaTTL = clock.ToDouble(clock.Now().Add(TimeSpan.FromMinutes(5))),
RuleName = "rule1",
};
- var targetForRule2 = new SamplingTargetDocument()
+ var targetForRule2 = new SamplingTargetDocument
{
FixedRate = 0.0,
Interval = 5, // next target poll after 5s
@@ -217,7 +217,7 @@ public void TestNextTargetFetchTime()
RuleName = "rule2",
};
- var targets = new Dictionary()
+ var targets = new Dictionary
{
{ "rule1", targetForRule1 },
{ "rule2", targetForRule2 },
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/TestSamplingRuleApplier.cs b/test/OpenTelemetry.Sampler.AWS.Tests/TestSamplingRuleApplier.cs
index 34ae66df43..35128b85e3 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/TestSamplingRuleApplier.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/TestSamplingRuleApplier.cs
@@ -40,7 +40,7 @@ public void TestRuleMatchesWithAllAttributes()
version: 1,
attributes: new Dictionary());
- var activityTags = new Dictionary()
+ var activityTags = new Dictionary
{
{ "http.host", "localhost" },
{ "http.method", "GET" },
@@ -69,7 +69,7 @@ public void TestRuleMatchesWithWildcardAttributes()
version: 1,
attributes: new Dictionary());
- var activityTags = new Dictionary()
+ var activityTags = new Dictionary
{
{ "http.host", "localhost" },
{ "http.method", "GET" },
@@ -143,7 +143,7 @@ public void TestRuleMatchesWithHttpTarget()
version: 1,
attributes: new Dictionary());
- var activityTags = new Dictionary()
+ var activityTags = new Dictionary
{
{ "http.target", "/helloworld" },
};
@@ -155,7 +155,7 @@ public void TestRuleMatchesWithHttpTarget()
[Fact]
public void TestAttributeMatching()
{
- var ruleAttributes = new Dictionary()
+ var ruleAttributes = new Dictionary
{
{ "dog", "bark" },
{ "cat", "meow" },
@@ -175,7 +175,7 @@ public void TestAttributeMatching()
version: 1,
attributes: ruleAttributes);
- var activityTags = new Dictionary()
+ var activityTags = new Dictionary
{
{ "http.target", "/helloworld" },
{ "dog", "bark" },
@@ -189,7 +189,7 @@ public void TestAttributeMatching()
[Fact]
public void TestAttributeMatchingWithLessActivityTags()
{
- var ruleAttributes = new Dictionary()
+ var ruleAttributes = new Dictionary
{
{ "dog", "bark" },
{ "cat", "meow" },
@@ -209,7 +209,7 @@ public void TestAttributeMatchingWithLessActivityTags()
version: 1,
attributes: ruleAttributes);
- var activityTags = new Dictionary()
+ var activityTags = new Dictionary
{
{ "http.target", "/helloworld" },
{ "dog", "bark" },
@@ -347,7 +347,7 @@ public void TestWithTarget()
var applier = new SamplingRuleApplier("clientId", clock, rule, new Statistics());
- // no target assigned yet. so borrow 1 from reseroir every second
+ // no target assigned yet. so borrow 1 from reservoir every second
Assert.Equal(SamplingDecision.RecordAndSample, applier.ShouldSample(default).Decision);
Assert.Equal(SamplingDecision.Drop, applier.ShouldSample(default).Decision);
clock.Advance(TimeSpan.FromSeconds(1));
@@ -355,7 +355,7 @@ public void TestWithTarget()
Assert.Equal(SamplingDecision.Drop, applier.ShouldSample(default).Decision);
// get the target
- SamplingTargetDocument target = new SamplingTargetDocument()
+ SamplingTargetDocument target = new SamplingTargetDocument
{
FixedRate = 0.0,
Interval = 10,
@@ -392,7 +392,7 @@ public void TestWithTargetWithoutQuota()
var applier = new SamplingRuleApplier("clientId", clock, rule, new Statistics());
- // no target assigned yet. so borrow 1 from reseroir every second
+ // no target assigned yet. so borrow 1 from reservoir every second
Assert.Equal(SamplingDecision.RecordAndSample, applier.ShouldSample(default).Decision);
Assert.Equal(SamplingDecision.Drop, applier.ShouldSample(default).Decision);
clock.Advance(TimeSpan.FromSeconds(1));
@@ -405,7 +405,7 @@ public void TestWithTargetWithoutQuota()
Assert.Equal(2, statistics.BorrowCount);
// get the target
- SamplingTargetDocument target = new SamplingTargetDocument()
+ SamplingTargetDocument target = new SamplingTargetDocument
{
FixedRate = 1.0,
Interval = 10,
diff --git a/test/OpenTelemetry.Sampler.AWS.Tests/Utils.cs b/test/OpenTelemetry.Sampler.AWS.Tests/Utils.cs
index b415200872..12e00e2ff2 100644
--- a/test/OpenTelemetry.Sampler.AWS.Tests/Utils.cs
+++ b/test/OpenTelemetry.Sampler.AWS.Tests/Utils.cs
@@ -28,17 +28,6 @@ internal static SamplingParameters CreateSamplingParameters()
return CreateSamplingParametersWithTags(new Dictionary());
}
- internal static SamplingParameters CreateSamplingParametersWithRootContext()
- {
- return new SamplingParameters(
- default,
- ActivityTraceId.CreateRandom(),
- "myActivityName",
- ActivityKind.Server,
- null,
- null);
- }
-
internal static SamplingParameters CreateSamplingParametersWithTags(Dictionary tags)
{
ActivityTraceId traceId = ActivityTraceId.CreateRandom();
@@ -47,11 +36,11 @@ internal static SamplingParameters CreateSamplingParametersWithTags(Dictionary>();
+ var tagList = new List>();
foreach (var tag in tags)
{
- tagList.Add(new KeyValuePair(tag.Key, tag.Value));
+ tagList.Add(new KeyValuePair(tag.Key, tag.Value));
}
return new SamplingParameters(
@@ -65,10 +54,10 @@ internal static SamplingParameters CreateSamplingParametersWithTags(Dictionary>()
+ var resourceAttributes = new List>
{
- new KeyValuePair("service.name", serviceName),
- new KeyValuePair("cloud.platform", cloudPlatform),
+ new("service.name", serviceName),
+ new("cloud.platform", cloudPlatform),
};
return ResourceBuilder.CreateEmpty().AddAttributes(resourceAttributes).Build();