Sha256: 2da9ba94ffc9e616c6e2ba0cf14b51cda9cb6a32a892d352e9db114d531c9b32

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic::Agent::Instrumentation
  module Roda
    module Tracer
      include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation

      INSTRUMENTATION_NAME = 'Roda'

      def self.included(clazz)
        clazz.extend(self)
      end

      def newrelic_middlewares
        middlewares = [NewRelic::Rack::BrowserMonitoring]
        if NewRelic::Rack::AgentHooks.needed?
          middlewares << NewRelic::Rack::AgentHooks
        end
        middlewares
      end

      def build_rack_app_with_tracing
        unless NewRelic::Agent.config[:disable_roda_auto_middleware]
          newrelic_middlewares.each do |middleware_class|
            self.use middleware_class
          end
        end
        yield
      end

      # Roda makes use of Rack, so we can get params from the request object
      def rack_request_params
        begin
          @_request.params
        rescue => e
          NewRelic::Agent.logger.debug('Failed to get params from Rack request.', e)
          NewRelic::EMPTY_HASH
        end
      end

      def _roda_handle_main_route_with_tracing(*args)
        NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

        perform_action_with_newrelic_trace(
          category: :roda,
          name: ::NewRelic::Agent::Instrumentation::Roda::TransactionNamer.transaction_name(request),
          params: ::NewRelic::Agent::ParameterFiltering::apply_filters(request.env, rack_request_params)
        ) do
          yield
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newrelic_rpm-9.5.0 lib/new_relic/agent/instrumentation/roda/instrumentation.rb