Class: ActionSubscriber::OpenTracing::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/action_subscriber/opentracing/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
# File 'lib/action_subscriber/opentracing/middleware.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/action_subscriber/opentracing/middleware.rb', line 12

def call(env)
  operation = "Subscriber #{env.subscriber}##{env.action}"
  parent = ::OpenTracing.extract(::OpenTracing::FORMAT_TEXT_MAP, env.headers)
  published_at = env.headers["published_at"]

  options = {}
  options[:references] = [::OpenTracing::Reference.follows_from(parent)] if parent
  options[:tags] = {
    "span.kind" => "consumer",
    "component" => "ActionSubscriber",
    "message_bus.destination" => env.routing_key,
    "message_bus.processed_at" => Time.now.strftime("%F %T.%3N %Z")
  }

  options[:tags]["message_bus.published_at"] = published_at if published_at

  result = nil
  ::OpenTracing.start_active_span(operation, options) do
    result = @app.call(env)
  end
  result
end