Skip to content

Commit db51e10

Browse files
committed
address comments
1 parent e40f7ba commit db51e10

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

sampler/xray/example/xray_sampling_on_rails_demonstration.ru

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ class WelcomeController < ActionController::Base
4343
end
4444
end
4545

46-
ENV['OTEL_TRACES_EXPORTER'] = 'console'
47-
ENV['OTEL_SERVICE_NAME'] = 'xray-sampler-on-rails-service'
46+
ENV['OTEL_TRACES_EXPORTER'] ||= 'console'
47+
ENV['OTEL_SERVICE_NAME'] ||= 'xray-sampler-on-rails-service'
48+
4849
OpenTelemetry::SDK.configure do |c|
4950
c.use_all({ 'OpenTelemetry::Instrumentation::ActiveRecord' => { enabled: false } })
5051
end
@@ -59,7 +60,7 @@ run App
5960

6061
#### Running and using the Sample App
6162
# To run this example run the `rackup` command with this file
62-
# Example: rackup trace_request_demonstration.ru
63+
# Example: rackup xray_sampling_on_rails_demonstration.ru
6364
# Navigate to http://localhost:9292/
6465
# Spans for any requests sampled by the X-Ray Sampler will appear in the console
6566

sampler/xray/lib/opentelemetry/sampler/xray/rate_limiter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def initialize(quota, max_balance_in_seconds = 1)
2020
end
2121

2222
def take(cost = 1)
23-
return false if @quota.zero?
23+
return false if @quota <= 0
2424

2525
quota_per_millis = @quota / 1000.0
2626

sampler/xray/test/rate_limiter_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,18 @@
4747
end
4848
assert_equal 30, spent
4949
end
50+
51+
it 'test_take_with_zero_quota' do
52+
limiter = OpenTelemetry::Sampler::XRay::RateLimiter.new(0, 1)
53+
54+
# Zero quota should always return false
55+
refute limiter.take(1)
56+
end
57+
58+
it 'test_take_with_negative_quota' do
59+
limiter = OpenTelemetry::Sampler::XRay::RateLimiter.new(-5, 1)
60+
61+
# Negative quota should always return false
62+
refute limiter.take(1)
63+
end
5064
end

0 commit comments

Comments
 (0)