Class: Sidekiq::Tracer::ServerMiddleware

Inherits:
Object
  • Object
show all
Includes:
Commons
Defined in:
lib/sidekiq/tracer/server_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commons

#operation_name, #tags

Constructor Details

#initialize(tracer, active_span, after_trace) ⇒ ServerMiddleware

Returns a new instance of ServerMiddleware.



10
11
12
13
14
# File 'lib/sidekiq/tracer/server_middleware.rb', line 10

def initialize(tracer, active_span, after_trace)
  @tracer = tracer
  @active_span = active_span
  @after_trace = after_trace
end

Instance Attribute Details

#active_spanObject (readonly)

Returns the value of attribute active_span.



8
9
10
# File 'lib/sidekiq/tracer/server_middleware.rb', line 8

def active_span
  @active_span
end

#after_traceObject (readonly)

Returns the value of attribute after_trace.



8
9
10
# File 'lib/sidekiq/tracer/server_middleware.rb', line 8

def after_trace
  @after_trace
end

#tracerObject (readonly)

Returns the value of attribute tracer.



8
9
10
# File 'lib/sidekiq/tracer/server_middleware.rb', line 8

def tracer
  @tracer
end

Instance Method Details

#call(_worker, job, _queue) ⇒ Object

rubocop:disable Metrics/MethodLength



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq/tracer/server_middleware.rb', line 17

def call(_worker, job, _queue)
  tracer.start_active_span(operation_name(job),
                           ignore_active_scope: true,
                           tags: tags(job, "consumer")) do |scope|
    begin
      yield
    rescue StandardError => e
      tag_errors(scope.span, e) if scope.span
      raise
    ensure
      after_trace&.call(scope.span) if scope.span
    end
  end
end