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

require 'opentracing'

module Gitlab
  module Tracing
    module Sidekiq
      class ClientMiddleware
        include SidekiqCommon

        SPAN_KIND = 'client'

        def call(worker_class, job, queue, redis_pool)
          in_tracing_span(
            operation_name: "sidekiq:#{job['class']}",
            tags: tags_from_job(job, SPAN_KIND)) 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