summaryrefslogtreecommitdiff
path: root/lib/gitlab/tracing/sidekiq/client_middleware.rb
blob: 96d9696ed08db5bc76902e76222a90ce28ab52f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

require 'opentracing'

module Gitlab
  module Tracing
    module Sidekiq
      class ClientMiddleware
        include SidekiqCommon

        def call(worker_class, job, queue, redis_pool)
          start_active_span(
            operation_name: job['class'],
            tags: tags_from_job(job, 'client')) do |span|
            # Inject the details directly into the job
            tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
            yield
          end
        end
      end
    end
  end
end