Class: Sbmt::Outbox::Middleware::OpenTelemetry::TracingCreateBatchMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/sbmt/outbox/middleware/open_telemetry/tracing_create_batch_middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(item_class, batch_attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sbmt/outbox/middleware/open_telemetry/tracing_create_batch_middleware.rb', line 8

def call(item_class, batch_attributes)
  return yield unless defined?(::OpenTelemetry)

  span_attributes = {
    "messaging.system" => "outbox",
    "messaging.outbox.box_type" => item_class.box_type.to_s,
    "messaging.outbox.box_name" => item_class.box_name,
    "messaging.outbox.owner" => item_class.owner,
    "messaging.destination" => item_class.name,
    "messaging.destination_kind" => "database"
  }

  tracer.in_span(span_name(item_class), attributes: span_attributes.compact, kind: :producer) do
    batch_attributes.each do |item_attributes|
      options = item_attributes[:options] ||= {}
      headers = options[:headers] || options["headers"] || {}
      ::OpenTelemetry.propagation.inject(headers)
    end

    yield
  end
end