Skip to content

Commit

Permalink
Fix rate limiting sampler to drop trace when lower bound is zero (#3604)
Browse files Browse the repository at this point in the history
* Fix rate limiting sampler to drop trace when lower bound is zero

* Add change log entry

* Update CHANGELOG.md

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>

---------

Co-authored-by: Chester Cheung <cheung.zhy.csu@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 22, 2023
1 parent 83b942a commit 440185c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- - AWS SDK span name to be of the format `Service.Operation` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3521)
- AWS SDK span name to be of the format `Service.Operation` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3521)
- Prevent sampler configuration reset from erroneously sampling first span in `go.opentelemetry.io/contrib/samplers/jaegerremote`. (#3603, #3604)

## [1.16.0-rc.1/0.41.0-rc.1/0.9.0-rc.1] - 2023-03-02

Expand Down
7 changes: 6 additions & 1 deletion samplers/jaegerremote/internal/utils/rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ type RateLimiter struct {

// NewRateLimiter creates a new RateLimiter.
func NewRateLimiter(creditsPerSecond, maxBalance float64) *RateLimiter {
balance := maxBalance
if creditsPerSecond == 0 {
balance = 0
}

return &RateLimiter{
creditsPerSecond: creditsPerSecond,
balance: maxBalance,
balance: balance,
maxBalance: maxBalance,
lastTick: time.Now(),
timeNow: time.Now,
Expand Down
4 changes: 4 additions & 0 deletions samplers/jaegerremote/sampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func TestRateLimitingSampler(t *testing.T) {
assert.Equal(t, trace.RecordAndSample, result.Decision)
result = sampler.ShouldSample(trace.SamplingParameters{Name: testOperationName})
assert.Equal(t, trace.Drop, result.Decision)

sampler = newRateLimitingSampler(0)
result = sampler.ShouldSample(trace.SamplingParameters{Name: testOperationName})
assert.Equal(t, trace.Drop, result.Decision)
}

func TestGuaranteedThroughputProbabilisticSamplerUpdate(t *testing.T) {
Expand Down

0 comments on commit 440185c

Please sign in to comment.