Class: Aspecto::OpenTelemetry::Sampler::MessageProcessSampler

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

Overview

OpenTelemetry sampler which implements the remote rules logic with fallback to service sampler

Instance Method Summary collapse

Constructor Details

#initialize(rules_sampler, service_sampler) ⇒ MessageProcessSampler

Returns a new instance of MessageProcessSampler.



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

def initialize(rules_sampler, service_sampler)
  @rules_sampler = rules_sampler
  @service_sampler = service_sampler
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/aspecto/opentelemetry/sampler/message_process_sampler.rb', line 25

def description
  "MessageProcessSampler"
end

#should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/aspecto/opentelemetry/sampler/message_process_sampler.rb', line 17

def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
  if attributes && attributes[::OpenTelemetry::SemanticConventions::Trace::MESSAGING_OPERATION] == "process"
    sampling_decision = should_sample_processing(parent_context, links, name, attributes)
    return sampling_decision if sampling_decision
  end
  @service_sampler.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
end