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

Methods included from Patcher

included

Class Method Details

.add_middleware(app) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 39

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



59
60
61
62
63
64
65
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 59

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



30
31
32
33
34
35
36
37
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 30

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

.patchObject



19
20
21
22
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 19

def patch
  patch_before_intialize
  patch_after_intialize
end

.patch_after_intializeObject



53
54
55
56
57
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 53

def patch_after_intialize
  ::ActiveSupport.on_load(:after_initialize) do
    Datadog::Contrib::Rails::Patcher.after_intialize(self)
  end
end

.patch_before_intializeObject



24
25
26
27
28
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 24

def patch_before_intialize
  ::ActiveSupport.on_load(:before_initialize) do
    Datadog::Contrib::Rails::Patcher.before_intialize(self)
  end
end

.setup_tracerObject

Configure Rails tracing with settings



68
69
70
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 68

def setup_tracer
  Datadog::Contrib::Rails::Framework.setup
end

.target_versionObject



15
16
17
# File 'lib/ddtrace/contrib/rails/patcher.rb', line 15

def target_version
  Integration.version
end