lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb in opentelemetry-instrumentation-sinatra-0.23.5 vs lib/opentelemetry/instrumentation/sinatra/extensions/tracer_extension.rb in opentelemetry-instrumentation-sinatra-0.24.0

- old
+ new

@@ -11,26 +11,28 @@ module Sinatra module Extensions # Sinatra extension that installs TracerMiddleware and provides # tracing for template rendering module TracerExtension - # Sinatra hook after extension is registered - def self.registered(app) - # Create tracing `render` method - ::Sinatra::Base.module_eval do - def render(_engine, data, *) - template_name = data.is_a?(Symbol) ? data : :literal + # Contants patches for `render` method + module RenderPatches + def render(_engine, data, *) + template_name = data.is_a?(Symbol) ? data : :literal - Sinatra::Instrumentation.instance.tracer.in_span( - 'sinatra.render_template', - attributes: { 'sinatra.template_name' => template_name.to_s } - ) do - super - end + Sinatra::Instrumentation.instance.tracer.in_span( + 'sinatra.render_template', + attributes: { 'sinatra.template_name' => template_name.to_s } + ) do + super end end - app.use(*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args) - app.use(Middlewares::TracerMiddleware) + end + + # Sinatra hook after extension is registered + def self.registered(app) + # Create tracing `render` method + ::Sinatra::Base.prepend(RenderPatches) + Sinatra::Instrumentation.instance.install_middleware(app) end end end end end