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
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Extensions/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Updated OpenTelemetry core component version(s) to `1.15.2`.
([#4080](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4080))

* Fixed `RateLimitingSampler` to reject non-positive `maxTracesPerSecond` values.
([#4127](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/4127))

## 1.14.0-beta.1

Released 2025-Nov-13
Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Extensions/Trace/RateLimitingSampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class RateLimitingSampler : Sampler
/// <param name="maxTracesPerSecond">The maximum number of traces that will be emitted each second.</param>
public RateLimitingSampler(int maxTracesPerSecond)
{
if (maxTracesPerSecond <= 0)
{
throw new ArgumentOutOfRangeException(nameof(maxTracesPerSecond), maxTracesPerSecond, "Value must be greater than zero.");
}

var maxBalance = maxTracesPerSecond < 1.0 ? 1.0 : maxTracesPerSecond;
this.rateLimiter = new RateLimiter(maxTracesPerSecond, maxBalance);
var attributes = new Dictionary<string, object>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace OpenTelemetry.Extensions.Tests.Trace;

public class RateLimitingSamplerTests
{
[Theory]
[InlineData(0)]
[InlineData(-1)]
public void Constructor_ThrowsArgumentOutOfRangeException_WhenMaxTracesPerSecondIsNotPositive(int maxTracesPerSecond)
{
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => new RateLimitingSampler(maxTracesPerSecond));

Assert.Equal("maxTracesPerSecond", exception.ParamName);
}

[Fact]
public void ShouldSample_ReturnsRecordAndSample_WhenWithinRateLimit()
{
Expand Down
Loading