Class: DHC::Zipkin

Inherits:
Interceptor show all
Defined in:
lib/dhc/interceptors/zipkin.rb

Constant Summary collapse

B3_HEADERS =
{
  trace_id: 'X-B3-TraceId',
  parent_id: 'X-B3-ParentSpanId',
  span_id: 'X-B3-SpanId',
  sampled: 'X-B3-Sampled',
  flags: 'X-B3-Flags'
}.freeze
TRUE =

true in binary annotation

'1'

Instance Attribute Summary

Attributes inherited from Interceptor

#request

Instance Method Summary collapse

Methods inherited from Interceptor

#after_request, #all_interceptor_classes, #before_init, #before_response, dup, #initialize, #response

Constructor Details

This class inherits a constructor from DHC::Interceptor

Instance Method Details

#after_responseObject



23
24
25
26
27
# File 'lib/dhc/interceptors/zipkin.rb', line 23

def after_response
  # only sample the current call if we're instructed to do so
  return unless dependencies? && trace_id.sampled?
  end_trace!
end

#before_requestObject



13
14
15
16
17
18
19
20
21
# File 'lib/dhc/interceptors/zipkin.rb', line 13

def before_request
  return if !dependencies? || !tracing?
  ZipkinTracer::TraceContainer.with_trace_id(trace_id) do
    # add headers even if the current trace_id should not be sampled
    B3_HEADERS.each { |method, header| request.headers[header] = trace_id.send(method).to_s }
    # only sample the current call if we're instructed to do so
    start_trace! if ::Trace.tracer && trace_id.sampled?
  end
end