Skip to content

Commit

Permalink
feat: Rails Rack Events
Browse files Browse the repository at this point in the history
This PR makes it possible for users to toggle between using the Rack Events and Middleware based instrumentation

See open-telemetry#341
Depends on open-telemetry#342
  • Loading branch information
arielvalentin committed Mar 5, 2023
1 parent 3aee1c3 commit 0a3b7c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions instrumentation/action_pack/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ gemspec

group :test do
gem 'opentelemetry-instrumentation-base', path: '../../instrumentation/base'
gem 'opentelemetry-instrumentation-rack', path: '../../instrumentation/rack'
gem 'pry-byebug'
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Railtie < ::Rails::Railtie

app.middleware.insert_before(
0,
OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
*OpenTelemetry::Instrumentation::Rack::Instrumentation.instance.middleware_args
)
end
end
Expand Down
7 changes: 6 additions & 1 deletion instrumentation/action_pack/test/test_helpers/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ def initialize_app(use_exceptions_app: false, remove_rack_tracer_middleware: fal
new_app.config.eager_load = false

# Prevent tests from creating log/*.log
use_stderr = ENV.fetch('RAILS_LOG_STDERR', 'false') == 'true'
io_stream = use_stderr ? $stderr : File::NULL
level = ENV.fetch('OTEL_LOG_LEVEL', 'fatal').to_sym
new_app.config.logger = Logger.new($stderr, level: level)
new_app.config.logger = Logger.new(io_stream, level: level)
new_app.config.log_level = level

new_app.config.filter_parameters = [:param_to_be_filtered]
Expand Down Expand Up @@ -53,6 +55,9 @@ def remove_rack_middleware(application)
application.middleware.delete(
OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
)
application.middleware.delete(
Rack::Events
)
end

def add_exceptions_app(application)
Expand Down

0 comments on commit 0a3b7c7

Please sign in to comment.