Class: OpenTelemetry::Exporters::Datadog::DatadogProbabilitySampler
- Inherits:
-
Object
- Object
- OpenTelemetry::Exporters::Datadog::DatadogProbabilitySampler
- Defined in:
- lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb
Overview
Implements sampling based on a probability but records all spans regardless.
Constant Summary collapse
- DEFAULT =
new(1.0)
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Class Method Summary collapse
-
.default_with_probability(probability = 1.0) ⇒ Object
Returns a new sampler.
Instance Method Summary collapse
-
#initialize(probability) ⇒ DatadogProbabilitySampler
constructor
A new instance of DatadogProbabilitySampler.
- #sample?(trace_id) ⇒ Boolean
-
#should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean
private
See Samplers.
Constructor Details
#initialize(probability) ⇒ DatadogProbabilitySampler
Returns a new instance of DatadogProbabilitySampler.
19 20 21 22 23 |
# File 'lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb', line 19 def initialize(probability) @probability = probability @id_upper_bound = (probability * (2**64 - 1)).ceil @description = format('TraceIdRatioBased{%.6f}', probability) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
17 18 19 |
# File 'lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb', line 17 def description @description end |
Class Method Details
.default_with_probability(probability = 1.0) ⇒ Object
Returns a new sampler. The probability of sampling a trace is equal to that of the specified probability.
47 48 49 50 51 |
# File 'lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb', line 47 def self.default_with_probability(probability = 1.0) raise ArgumentError, 'probability must be in range [0.0, 1.0]' unless (0.0..1.0).include?(probability) new(probability) end |
Instance Method Details
#sample?(trace_id) ⇒ Boolean
25 26 27 |
# File 'lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb', line 25 def sample?(trace_id) @probability == 1.0 || trace_id[8, 8].unpack1('Q>') < @id_upper_bound end |
#should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
See Samplers.
32 33 34 35 36 37 38 39 40 |
# File 'lib/opentelemetry/exporters/datadog/datadog_probability_sampler.rb', line 32 def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) # Ignored for sampling decision: links, name, kind, attributes. tracestate = OpenTelemetry::Trace.current_span(parent_context).context.tracestate if sample?(trace_id) OpenTelemetry::SDK::Trace::Samplers::Result.new(decision: OpenTelemetry::SDK::Trace::Samplers::Decision::RECORD_AND_SAMPLE, tracestate: tracestate) else OpenTelemetry::SDK::Trace::Samplers::Result.new(decision: OpenTelemetry::SDK::Trace::Samplers::Decision::RECORD_ONLY, tracestate: tracestate) end end |