Class: Vault::Tracing::SidekiqClient

Inherits:
Object
  • Object
show all
Defined in:
lib/vault-tools/tracing/sidekiq_client.rb

Overview

Tracing info for sidekiq, adding them as params This was lifted straight out of heroku/coal_car

Instance Method Summary collapse

Instance Method Details

#call(worker_class, job, _queue, _redis_pool) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vault-tools/tracing/sidekiq_client.rb', line 16

def call(worker_class, job, _queue, _redis_pool)
  trace_id = ::ZipkinTracer::TraceGenerator.new.next_trace_id
  ::ZipkinTracer::TraceContainer.with_trace_id(trace_id) do
    job["zipkin_trace_information"] = trace_information(trace_id)
    if trace_id.sampled?
      ::Trace.tracer.with_new_span(trace_id, "sidekiq") do |span|
        local_endpoint = Trace.default_endpoint
        klass = job["wrapped".freeze] || worker_class
        span.record_tag("job_class",
                        klass,
                        ::Trace::BinaryAnnotation::Type::STRING,
                        local_endpoint)
        yield
      end
    else
      yield
    end
  end
end

#trace_information(trace_id) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/vault-tools/tracing/sidekiq_client.rb', line 6

def trace_information(trace_id)
  {
    "trace_id"  => trace_id.trace_id,
    "parent_id" => trace_id.parent_id,
    "span_id"   => trace_id.span_id,
    "sampled"   => trace_id.sampled,
    "flags"     => trace_id.flags
  }
end