Class: Datadog::AppSec::SampleRate

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/appsec/sample_rate.rb

Overview

SampleRate basic sample rate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rate) ⇒ SampleRate

Returns a new instance of SampleRate.



9
10
11
# File 'lib/datadog/appsec/sample_rate.rb', line 9

def initialize(rate)
  @rate = rate
end

Instance Attribute Details

#rateObject (readonly)

Returns the value of attribute rate.



7
8
9
# File 'lib/datadog/appsec/sample_rate.rb', line 7

def rate
  @rate
end

Instance Method Details

#sample?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/datadog/appsec/sample_rate.rb', line 13

def sample?
  return false if rate <= 0
  return true if rate >= 1

  Kernel.rand < rate
end