diff --git a/instrumentation/action_pack/Appraisals b/instrumentation/action_pack/Appraisals index 018ce75b2..895a185d4 100644 --- a/instrumentation/action_pack/Appraisals +++ b/instrumentation/action_pack/Appraisals @@ -4,6 +4,10 @@ # # SPDX-License-Identifier: Apache-2.0 +appraise 'rails-6.0' do + gem 'rails', '~> 6.0.0' +end + appraise 'rails-6.1' do gem 'rails', '~> 6.1.0' end diff --git a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb index dc5a8a308..15d54a5bb 100644 --- a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb +++ b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/handlers/action_controller.rb @@ -24,15 +24,18 @@ def initialize(config) def start(_name, _id, payload) rack_span = OpenTelemetry::Instrumentation::Rack.current_span - # from rails 6.1, the request is added to payload - rack_span.name = "#{payload[:controller]}##{payload[:action]}" unless payload[:request].env['action_dispatch.exception'] + # from rails 6.1, the request will be added to payload + request = payload[:request] + request = payload[:headers].instance_variable_get(:@req) if ::ActionPack.version < Gem::Version.new('6.1.0') + + rack_span.name = "#{payload[:controller]}##{payload[:action]}" unless request.env['action_dispatch.exception'] attributes_to_append = { OpenTelemetry::SemanticConventions::Trace::CODE_NAMESPACE => String(payload[:controller]), OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => String(payload[:action]) } - attributes_to_append[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = payload[:request].filtered_path if payload[:request].filtered_path != payload[:request].fullpath + attributes_to_append[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath rack_span.add_attributes(attributes_to_append) rescue StandardError => e diff --git a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb index cad8a14a4..896bf4621 100644 --- a/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb +++ b/instrumentation/action_pack/lib/opentelemetry/instrumentation/action_pack/instrumentation.rb @@ -9,7 +9,7 @@ module Instrumentation module ActionPack # The Instrumentation class contains logic to detect and install the ActionPack instrumentation class Instrumentation < OpenTelemetry::Instrumentation::Base - MINIMUM_VERSION = Gem::Version.new('6.1.0') + MINIMUM_VERSION = Gem::Version.new('6.0.0') install do |_config| require_railtie diff --git a/instrumentation/action_pack/test/test_helpers/app_config.rb b/instrumentation/action_pack/test/test_helpers/app_config.rb index 8874d61e2..b62d198de 100644 --- a/instrumentation/action_pack/test/test_helpers/app_config.rb +++ b/instrumentation/action_pack/test/test_helpers/app_config.rb @@ -28,6 +28,8 @@ def initialize_app(use_exceptions_app: false, remove_rack_tracer_middleware: fal new_app.config.filter_parameters = [:param_to_be_filtered] case Rails.version + when /^6\.0/ + apply_rails_6_0_configs(new_app) when /^6\.1/ apply_rails_6_1_configs(new_app) when /^7\./ @@ -71,6 +73,13 @@ def add_middlewares(application) ) end + def apply_rails_6_0_configs(application) + # Required in Rails 6 + application.config.hosts << 'example.org' + # Creates a lot of deprecation warnings on subsequent app initializations if not explicitly set. + application.config.action_view.finalize_compiled_template_methods = ActionView::Railtie::NULL_OPTION + end + def apply_rails_6_1_configs(application) # Required in Rails 6 application.config.hosts << 'example.org'