Class: Lepus::Producers::Middlewares::Instrumentation

Inherits:
Middleware
  • Object
show all
Defined in:
lib/lepus/producers/middlewares/instrumentation.rb

Overview

A middleware that emits instrumentation events via Lepus.instrument.

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ Instrumentation

Returns a new instance of Instrumentation.

Parameters:

  • opts (Hash)

    The options for the middleware.

Options Hash (**opts):

  • :event_name (String) — default: "publish"

    The event name suffix.



10
11
12
13
# File 'lib/lepus/producers/middlewares/instrumentation.rb', line 10

def initialize(**opts)
  super
  @event_name = opts.fetch(:event_name, "publish")
end

Instance Method Details

#call(message, app) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/lepus/producers/middlewares/instrumentation.rb', line 15

def call(message, app)
  exchange = message.delivery_info&.exchange
  routing_key = message.delivery_info&.routing_key

  Lepus.instrument(event_name, exchange: exchange, routing_key: routing_key, message: message) do
    app.call(message)
  end
end