Skip to content

Commit

Permalink
feat: add rails 6.0 back
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Oct 20, 2023
1 parent 68a9404 commit 6dc9184
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions instrumentation/action_pack/Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions instrumentation/action_pack/test/test_helpers/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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\./
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 6dc9184

Please sign in to comment.