Module: Datadog::Contrib::Rails::Patcher
- Includes:
- Patcher
- Defined in:
- lib/ddtrace/contrib/rails/patcher.rb
Overview
Patcher enables patching of ‘rails’ module.
Class Method Summary collapse
- .add_middleware(app) ⇒ Object
- .after_intialize(app) ⇒ Object
- .before_intialize(app) ⇒ Object
- .patch ⇒ Object
- .patch_after_intialize ⇒ Object
- .patch_before_intialize ⇒ Object
- .patched? ⇒ Boolean
-
.setup_tracer ⇒ Object
Configure Rails tracing with settings.
Methods included from Patcher
Class Method Details
.add_middleware(app) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 43 def add_middleware(app) # Add trace middleware app.middleware.insert_before(0, Datadog::Contrib::Rack::TraceMiddleware) # Insert right after Rails exception handling middleware, because if it's before, # it catches and swallows the error. If it's too far after, custom middleware can find itself # between, and raise exceptions that don't end up getting tagged on the request properly. # e.g lost stack trace. app.middleware.insert_after( ActionDispatch::ShowExceptions, Datadog::Contrib::Rails::ExceptionMiddleware ) end |
.after_intialize(app) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 63 def after_intialize(app) 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 end end |
.before_intialize(app) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 34 def before_intialize(app) 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 |
.patch ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 19 def patch do_once(:rails) do patch_before_intialize patch_after_intialize end rescue => e Datadog::Tracer.log.error("Unable to apply Rails integration: #{e}") end |
.patch_after_intialize ⇒ Object
57 58 59 60 61 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 57 def patch_after_intialize ::ActiveSupport.on_load(:after_initialize) do Datadog::Contrib::Rails::Patcher.after_intialize(self) end end |
.patch_before_intialize ⇒ Object
28 29 30 31 32 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 28 def patch_before_intialize ::ActiveSupport.on_load(:before_initialize) do Datadog::Contrib::Rails::Patcher.before_intialize(self) end end |
.patched? ⇒ Boolean
15 16 17 |
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 15 def patched? done?(:rails) end |