Module: TCellAgent::Instrumentation::Rails

Defined in:
lib/tcell_agent/rails/routes.rb,
lib/tcell_agent/rails/dlp_handler.rb,
lib/tcell_agent/rails/js_agent_insert.rb,
lib/tcell_agent/rails/tcell_body_proxy.rb,
lib/tcell_agent/rails/settings_reporter.rb,
lib/tcell_agent/rails/middleware/global_middleware.rb,
lib/tcell_agent/rails/middleware/context_middleware.rb,
lib/tcell_agent/rails/middleware/headers_middleware.rb,
lib/tcell_agent/rails/middleware/body_filter_middleware.rb

Defined Under Namespace

Modules: DLPHandler, JSAgent, Middleware Classes: TCellBodyProxy, TCellRoute, TCellRoute4, TCellRoute5

Class Method Summary collapse

Class Method Details

.create_tcell_route(route) ⇒ Object



79
80
81
82
83
84
# File 'lib/tcell_agent/rails/routes.rb', line 79

def self.create_tcell_route(route)
  return TCellRoute5.new(route) if route && ::Rails::VERSION::MAJOR >= 5
  return TCellRoute4.new(route) if route && ::Rails::VERSION::MAJOR < 5

  TCellRoute.new
end

.instrument_route(route) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/tcell_agent/rails/routes.rb', line 96

def self.instrument_route(route)
  return unless TCellAgent.configuration.should_instrument?

  tcell_route = create_tcell_route(route)

  return unless tcell_route.report?

  if tcell_route.grape_route?
    TCellAgent::Instrumentation.instrument_grape_api(tcell_route.route_path, tcell_route.grape_routes)

  else
    tcell_route.route_methods.each do |route_method|
      route_id =
        TCellAgent::SensorEvents::Util.calculate_route_id(route_method, tcell_route.route_path_raw)
      TCellAgent.send_event(
        TCellAgent::SensorEvents::AppRoutesSensorEvent.new(
          tcell_route.route_path, route_method, route_id, nil, tcell_route.route_destination
        )
      )
    end
  end
end

.instrument_routesObject



86
87
88
89
90
91
92
93
94
# File 'lib/tcell_agent/rails/routes.rb', line 86

def self.instrument_routes
  return unless TCellAgent.configuration.should_instrument?

  return unless ::Rails.application

  ::Rails.application.routes.routes.each do |route|
    instrument_route(route)
  end
end

.send_framework_infoObject



9
10
11
12
13
14
15
# File 'lib/tcell_agent/rails/settings_reporter.rb', line 9

def self.send_framework_info
  TCellAgent.send_event(
    TCellAgent::SensorEvents::ServerAgentAppFrameworkEvent.new(
      'Rails', ::Rails.version
    )
  )
end

.send_settingsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tcell_agent/rails/settings_reporter.rb', line 17

def self.send_settings
  TCellAgent::Instrumentation.safe_block('Reporting Rails settings') do
    rails_config = ::Rails.application.config

    # Defaults to true
    csrf_protection = rails_config.action_controller.allow_forgery_protection || true
    TCellAgent.send_event(
      TCellAgent::SensorEvents::AppConfigSettingEvent.new(
        'Rails', 'core', '', 'csrf_protection', csrf_protection
      )
    )

    # Defaults to false if nil
    mass_assignment_allowed = rails_config.action_controller.permit_all_parameters || false
    TCellAgent.send_event(
      TCellAgent::SensorEvents::AppConfigSettingEvent.new(
        'Rails', 'core', '', 'mass_assignment_allowed', mass_assignment_allowed
      )
    )

    # Defaults to never
    session_expire = rails_config.session_options[:expire_after] || -1
    TCellAgent.send_event(
      TCellAgent::SensorEvents::AppConfigSettingEvent.new(
        'Rails', 'session', '', 'timeout', session_expire
      )
    )
  end
end