Class: ZipkinTracer::RackHandler
- Inherits:
-
Object
- Object
- ZipkinTracer::RackHandler
- Defined in:
- lib/zipkin-tracer/rack/zipkin-tracer.rb
Overview
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.
Constant Summary collapse
- PATH_INFO =
the following constants are defined only from rack 1.6
Rack::PATH_INFO rescue 'PATH_INFO'.freeze
- REQUEST_METHOD =
Rack::REQUEST_METHOD rescue 'REQUEST_METHOD'.freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config = nil) ⇒ RackHandler
constructor
A new instance of RackHandler.
Constructor Details
#initialize(app, config = nil) ⇒ RackHandler
Returns a new instance of RackHandler.
14 15 16 17 18 |
# 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 |
Instance Method Details
#call(env) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |