Class: Aspecto::OpenTelemetry::Sampler::SamplingRule

Inherits:
Object
  • Object
show all
Defined in:
lib/aspecto/opentelemetry/sampler/sampling_rule.rb

Overview

Single rule for sampling

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule_config) ⇒ SamplingRule

Returns a new instance of SamplingRule.



12
13
14
15
16
17
# File 'lib/aspecto/opentelemetry/sampler/sampling_rule.rb', line 12

def initialize(rule_config)
  @id = rule_config["_id"]
  @sampler = ::OpenTelemetry::SDK::Trace::Samplers.trace_id_ratio_based(rule_config["samplingRate"])
  @conditions = rule_config["conditions"].map { |condition_config| Condition.new condition_config }
  @context = rule_config["context"]
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



19
20
21
# File 'lib/aspecto/opentelemetry/sampler/sampling_rule.rb', line 19

def context
  @context
end

#samplerObject (readonly)

Returns the value of attribute sampler.



19
20
21
# File 'lib/aspecto/opentelemetry/sampler/sampling_rule.rb', line 19

def sampler
  @sampler
end

Instance Method Details

#satisfies?(attributes, span_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/aspecto/opentelemetry/sampler/sampling_rule.rb', line 21

def satisfies?(attributes, span_name)
  @conditions.all? { |condition| condition.satisfies?(attributes, span_name) }
end