Class: OpenTelemetry::Instrumentation::Sinatra::Middlewares::TracerMiddleware
- Inherits:
-
Object
- Object
- OpenTelemetry::Instrumentation::Sinatra::Middlewares::TracerMiddleware
- Defined in:
- lib/opentelemetry/instrumentation/sinatra/middlewares/tracer_middleware.rb
Overview
Middleware to trace Sinatra requests
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ TracerMiddleware
constructor
A new instance of TracerMiddleware.
- #trace_response(env, response) ⇒ Object
Constructor Details
#initialize(app) ⇒ TracerMiddleware
Returns a new instance of TracerMiddleware.
14 15 16 |
# File 'lib/opentelemetry/instrumentation/sinatra/middlewares/tracer_middleware.rb', line 14 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 |
# File 'lib/opentelemetry/instrumentation/sinatra/middlewares/tracer_middleware.rb', line 18 def call(env) response = @app.call(env) ensure trace_response(env, response) end |
#trace_response(env, response) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/opentelemetry/instrumentation/sinatra/middlewares/tracer_middleware.rb', line 24 def trace_response(env, response) span = OpenTelemetry::Instrumentation::Rack.current_span return unless span.recording? span.set_attribute('http.route', env['sinatra.route'].split.last) if env['sinatra.route'] span.name = env['sinatra.route'] if env['sinatra.route'] return if response.nil? sinatra_response = ::Sinatra::Response.new([], response.first) return unless sinatra_response.server_error? span.record_exception(env['sinatra.error']) if env['sinatra.error'] span.status = OpenTelemetry::Trace::Status.error end |