Class: OpenTracing::Instrumentation::Rack::ExtractMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/opentracing/instrumentation/rack/extract_middleware.rb

Overview

ExtractMiddleware extract trace context and push it to scope manager.

Defined Under Namespace

Classes: FakeSpan

Instance Method Summary collapse

Constructor Details

#initialize(app, tracer: OpenTracing.global_tracer, logger: nil) ⇒ ExtractMiddleware

Returns a new instance of ExtractMiddleware.

Parameters:

  • app (RackApp)

    inner rack application

  • tracer (OpenTracing::Tracer) (defaults to: OpenTracing.global_tracer)
  • logger (Logger) (defaults to: nil)


22
23
24
25
26
27
28
29
30
# File 'lib/opentracing/instrumentation/rack/extract_middleware.rb', line 22

def initialize(
  app,
  tracer: OpenTracing.global_tracer,
  logger: nil
)
  @app = app
  @tracer = tracer
  @logger = logger
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash<String, String>)

    rack env



33
34
35
36
37
38
39
40
# File 'lib/opentracing/instrumentation/rack/extract_middleware.rb', line 33

def call(env)
  span_context = @tracer.extract(OpenTracing::FORMAT_RACK, env)
  return @app.call(env) unless span_context

  with_scope(span_context) do
    @app.call(env)
  end
end