Class: Sqreen::Ecosystem::Tracing::Sampler::MaxCallsPrimitive

Inherits:
Object
  • Object
show all
Defined in:
lib/sqreen/ecosystem/tracing/sampler.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_calls) ⇒ MaxCallsPrimitive

Returns a new instance of MaxCallsPrimitive.



138
139
140
141
142
143
# File 'lib/sqreen/ecosystem/tracing/sampler.rb', line 138

def initialize(max_calls)
  @max_calls = max_calls
  @disabled = false # to avoid lock
  @mutex = Mutex.new
  @num_calls = 0
end

Instance Method Details

#triggers?Boolean

Returns:

  • (Boolean)


145
146
147
148
149
150
151
152
# File 'lib/sqreen/ecosystem/tracing/sampler.rb', line 145

def triggers?
  return false if @disabled
  num_calls = @mutex.synchronize do
    @num_calls += 1
  end

  num_calls <= @max_calls
end