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: nil, opts: {}) ⇒ ServerMiddleware

Returns a new instance of ServerMiddleware.



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

def initialize(tracer: nil, opts: {})
  @tracer = tracer
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



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

def opts
  @opts
end

#tracerObject (readonly)

Returns the value of attribute tracer.



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

def tracer
  @tracer
end

Instance Method Details

#call(worker, job, queue) ⇒ Object



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

def call(worker, job, queue)
  parent_span_context = extract(job) if opts.fetch(:propagate_context, true)

  scope = tracer.start_active_span(
    operation_name(job),
    child_of: parent_span_context,
    tags: tags(job, 'server')
  )

  yield
rescue Exception => e
  if scope
    scope.span.set_tag('error', true)
    scope.span.log_kv(event: 'error', :'error.object' => e)
  end
  raise
ensure
  scope.close if scope
end