diff --git a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb index 2a2ca47434..35701f8274 100644 --- a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb +++ b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb @@ -28,8 +28,8 @@ def render(_engine, data, *) end end end - app.use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args) - app.use(Middlewares::TracerMiddleware) + + Instrumentation.instance.install_middleware(app) end end end diff --git a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/instrumentation.rb b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/instrumentation.rb index b7127838e3..100e92a31d 100644 --- a/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/instrumentation.rb +++ b/instrumentation/sinatra/lib/opentelemetry/instrumentation/sinatra/instrumentation.rb @@ -12,15 +12,22 @@ module Sinatra # The Instrumentation class contains logic to detect and install the Sinatra # instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base - install do |_| - OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.install({}) + install do |config| + OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.install({}) if config[:install_rack] ::Sinatra::Base.register Extensions::TracerExtension end + option :install_rack, true, validate: :boolean + present do defined?(::Sinatra) end + + def install_middleware(app) + app.use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args) if config[:install_rack] + app.use(Middlewares::TracerMiddleware) + end end end end