Module: TCellAgent::Instrumentation
- Defined in:
- lib/tcell_agent/patches.rb,
lib/tcell_agent/rails/routes.rb,
lib/tcell_agent/instrumentation.rb,
lib/tcell_agent/rails/dlp_handler.rb,
lib/tcell_agent/rails/routes/grape.rb,
lib/tcell_agent/instrumentation/lfi.rb,
lib/tcell_agent/rails/js_agent_insert.rb,
lib/tcell_agent/rails/routes/route_id.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: Lfi, Patches, Rails, RouteId
Classes: ContextFilter, TCellData
Constant Summary
collapse
- TCELL_ID =
'tcell.request_data'.freeze
Class Method Summary
collapse
Class Method Details
.get_safe_block_logger ⇒ Object
225
226
227
228
229
230
231
|
# File 'lib/tcell_agent/instrumentation.rb', line 225
def self.get_safe_block_logger
unless defined?(@safe_block_logger)
@safe_block_logger = TCellAgent::ModuleLogger.new(TCellAgent.logger, name)
end
@safe_block_logger
end
|
.grape_path_params(env, route) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/tcell_agent/rails/routes/grape.rb', line 63
def self.grape_path_params(env, route)
all_params = Grape::Request.new(env).params
grape_route_params(route).keys.each_with_object({}) do |key, memo|
memo[key] = all_params[key]
end
end
|
.grape_route?(route) ⇒ Boolean
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/tcell_agent/rails/routes/grape.rb', line 5
def self.grape_route?(route)
if defined?(Grape::API)
begin
return route.app < Grape::API if ::Rails::VERSION::MAJOR == 4 &&
::Rails::VERSION::MINOR < 2
return route.app.app < Grape::API
rescue StandardError
end
end
false
end
|
.grape_route_info(route) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/tcell_agent/rails/routes/grape.rb', line 38
def self.grape_route_info(route)
major, minor, _tiny = Gem.loaded_specs['grape'].version.to_s.split('.')
if major.to_i.zero? && minor.to_i < 16
{
:method => route.route_method,
:path => route.route_path
}
else
{
:method => route.request_method,
:path => route.path
}
end
end
|
.grape_route_params(route) ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/tcell_agent/rails/routes/grape.rb', line 53
def self.grape_route_params(route)
major, minor, _tiny = Gem.loaded_specs['grape'].version.to_s.split('.')
if major.to_i.zero? && minor.to_i < 16
route.route_params
else
route.params
end
end
|
.instrument_grape_api(grape_mount_endpoint, routes) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/tcell_agent/rails/routes/grape.rb', line 20
def self.instrument_grape_api(grape_mount_endpoint, routes)
return unless routes
routes.each do |route|
route_info = grape_route_info(route)
route_path = "#{grape_mount_endpoint}#{route_info[:path]}"
route_method = route_info[:method]
route_id = TCellAgent::SensorEvents::Util.calculate_route_id(route_method, route_path)
TCellAgent.send_event(
TCellAgent::SensorEvents::AppRoutesSensorEvent.new(
route_path, route_method, route_id, nil, nil
)
)
end
end
|
.safe_block(message, &block) ⇒ Object
233
234
235
236
237
238
239
|
# File 'lib/tcell_agent/instrumentation.rb', line 233
def self.safe_block(message, &block)
block.call
rescue StandardError => e
logger = get_safe_block_logger
logger.error("Error #{message} (#{e.class}): #{e.message}")
logger.exception(e)
end
|
.safe_block_no_log(_message, &block) ⇒ Object
241
242
243
244
245
|
# File 'lib/tcell_agent/instrumentation.rb', line 241
def self.safe_block_no_log(_message, &block)
block.call
rescue StandardError
end
|