Skip to content

Commit

Permalink
Changed: Only apply Rails #initialize hooks once per app.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Nov 27, 2018
1 parent 5b6bfe1 commit f7d805b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/ddtrace/contrib/rails/patcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def patch_before_intialize
end

def before_intialize(app)
# Middleware must be added before the application is initialized.
# Otherwise the middleware stack will be frozen.
# Sometimes we don't want to activate middleware e.g. OpenTracing, etc.
add_middleware(app) if Datadog.configuration[:rails][:middleware]
do_once(:rails_before_initialize, for: app) do
# Middleware must be added before the application is initialized.
# Otherwise the middleware stack will be frozen.
# Sometimes we don't want to activate middleware e.g. OpenTracing, etc.
add_middleware(app) if Datadog.configuration[:rails][:middleware]
end
end

def add_middleware(app)
Expand All @@ -59,10 +61,12 @@ def patch_after_intialize
end

def after_intialize(app)
# Finish configuring the tracer after the application is initialized.
# We need to wait for some things, like application name, middleware stack, etc.
setup_tracer
instrument_rails
do_once(:rails_after_initialize, for: app) do
# Finish configuring the tracer after the application is initialized.
# We need to wait for some things, like application name, middleware stack, etc.
setup_tracer
instrument_rails
end
end

# Configure Rails tracing with settings
Expand Down

0 comments on commit f7d805b

Please sign in to comment.