class ZipkinTracer::RackHandler
This middleware reads Zipkin headers from the request and sets/creates a Trace.id
usable by the rest of the app It will also send the trace to the Zipkin service using one of the methods configured.
Constants
- PATH_INFO
the following constants are defined only from rack 1.6
- REQUEST_METHOD
- SERVER_RECV_TAGS
Public Class Methods
new(app, config = nil)
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 14 def initialize(app, config = nil) @app = app @config = Config.new(app, config).freeze @tracer = TracerFactory.new.tracer(@config) end
Public Instance Methods
call(env)
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 20 def call(env) zipkin_env = ZipkinEnv.new(env, @config) trace_id = zipkin_env.trace_id TraceContainer.with_trace_id(trace_id) do if !trace_id.sampled? @app.call(env) else @tracer.with_new_span(trace_id, span_name(env)) do |span| span.kind = Trace::Span::Kind::SERVER trace!(span, zipkin_env) { @app.call(env) } end end end end
Private Instance Methods
annotate_plugin(span, env, status, response_headers, response_body)
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 46 def annotate_plugin(span, env, status, response_headers, response_body) @config.annotate_plugin.call(span, env, status, response_headers, response_body) if @config.annotate_plugin end
span_name(env)
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 42 def span_name(env) "#{env[REQUEST_METHOD].to_s.downcase} #{Application.route(env)}".strip end
trace!(span, zipkin_env) { || ... }
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 50 def trace!(span, zipkin_env, &block) status, headers, body = yield ensure trace_server_information(span, zipkin_env, status) annotate_plugin(span, zipkin_env.env, status, headers, body) end
trace_server_information(span, zipkin_env, status)
click to toggle source
# File lib/zipkin-tracer/rack/zipkin-tracer.rb, line 58 def trace_server_information(span, zipkin_env, status) span.record_status(status) SERVER_RECV_TAGS.each { |annotation_key, env_key| span.record_tag(annotation_key, zipkin_env.env[env_key]) } end