lib/opentelemetry/instrumentation/rails/patches/action_controller/metal.rb in opentelemetry-instrumentation-rails-0.16.0 vs lib/opentelemetry/instrumentation/rails/patches/action_controller/metal.rb in opentelemetry-instrumentation-rails-0.17.0

- old
+ new

@@ -12,10 +12,24 @@ # Module to prepend to ActionController::Metal for instrumentation module Metal def dispatch(name, request, response) rack_span = OpenTelemetry::Instrumentation::Rack.current_span rack_span.name = "#{self.class.name}##{name}" if rack_span.context.valid? && !request.env['action_dispatch.exception'] + + add_rails_route(rack_span, request) if instrumentation_config[:enable_recognize_route] super(name, request, response) + end + + private + + def add_rails_route(rack_span, request) + ::Rails.application.routes.router.recognize(request) do |route, _params| + rack_span.set_attribute('http.route', route.path.spec.to_s) + end + end + + def instrumentation_config + Rails::Instrumentation.instance.config end end end end end