Skip to content

Commit

Permalink
wip: fixing up railtie middleware install
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter-splunk committed May 26, 2022
1 parent 86b20a5 commit e75e6d9
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ gem "rack-test", "~> 1.1"

# for testing the rack middleware
gem "opentelemetry-instrumentation-rack", "0.20.2"
gem "opentelemetry-instrumentation-action_pack", "0.1.4"
10 changes: 10 additions & 0 deletions lib/splunk/otel/instrumentation/action_pack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# frozen_string_literal: true

module Splunk
module Otel
module Instrumentation
# Contains the RUM instrumentation for the ActionPack gem
module ActionPack
end
end
end
end

require_relative "./action_pack/railtie"
36 changes: 36 additions & 0 deletions lib/splunk/otel/instrumentation/action_pack/instrumentation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Splunk
module Otel
module ActionPack
# The Instrumentation class contains logic to detect and install the ActionPack instrumentation
class Instrumentation < OpenTelemetry::Instrumentation::Base
MINIMUM_VERSION = Gem::Version.new('5.2.0')

install do |_config|
require_railtie
end

present do
defined?(::ActionController)
end

compatible do
gem_version >= MINIMUM_VERSION
end

option :enable_recognize_route, default: false, validate: :boolean

private

def gem_version
::ActionPack.version
end

def require_railtie
require_relative 'railtie'
end
end
end
end
end
18 changes: 10 additions & 8 deletions lib/splunk/otel/instrumentation/action_pack/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

module Splunk
module Otel
module ActionPack
# Install the Rack middleware for RUM responses
class Railtie < ::Rails::Railtie
config.before_initialize do |app|
app.middleware.insert_before(
0,
Splunk::Otel::Rack::RumMiddleware
)
module Instrumentation
module ActionPack
# Install the Rack middleware for RUM responses
class Railtie < ::Rails::Railtie
config.before_initialize do |app|
app.middleware.insert_before(
0,
Splunk::Otel::Rack::RumMiddleware
)
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/splunk/otel/instrumentation/action_pack/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Splunk
module Otel
module ActionPack
VERSION = '0.1.0'
end
end
end
6 changes: 5 additions & 1 deletion test/splunk/instrumentation/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
require "test_helper"
require "opentelemetry/sdk"
require "opentelemetry/instrumentation/rack"
require "opentelemetry/instrumentation/action_pack"
require "splunk/otel"
require "splunk/otel/instrumentation/rack"
require "splunk/otel/instrumentation/action_pack"
require "splunk/otel/instrumentation/action_pack/railtie"
require "rack/test"
require 'test_helpers/app_config.rb'

Expand All @@ -20,7 +23,8 @@ class RumRailsTest < Test::Unit::TestCase
def setup
with_env("OTEL_SERVICE_NAME" => "test-service") do
Splunk::Otel.configure do |c|
c.use 'OpenTelemetry::Instrumentation::ActionPack'
c.use "OpenTelemetry::Instrumentation::ActionPack"
# c.use "Splunk::Otel::Instrumentation::ActionPack"
end
end
end
Expand Down

0 comments on commit e75e6d9

Please sign in to comment.