Sha256: 27e626106a9eea8e6e8a274c24a37850d29943d19db09af292f6e8ba0b2350a9

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module ActionPack
      module Patches
        module ActionController
          # 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
              ActionPack::Instrumentation.instance.config
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-action_pack-0.1.3 lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb
opentelemetry-instrumentation-action_pack-0.1.2 lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb
opentelemetry-instrumentation-action_pack-0.1.1 lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb
opentelemetry-instrumentation-action_pack-0.1.0 lib/opentelemetry/instrumentation/action_pack/patches/action_controller/metal.rb