tcell_agent 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tcell_agent +10 -2
- data/lib/tcell_agent.rb +3 -3
- data/lib/tcell_agent/agent.rb +42 -52
- data/lib/tcell_agent/agent/event_processor.rb +129 -162
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
- data/lib/tcell_agent/agent/policy_manager.rb +83 -104
- data/lib/tcell_agent/agent/policy_types.rb +24 -29
- data/lib/tcell_agent/agent/route_manager.rb +36 -46
- data/lib/tcell_agent/agent/static_agent.rb +19 -21
- data/lib/tcell_agent/api.rb +23 -28
- data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
- data/lib/tcell_agent/authlogic.rb +7 -7
- data/lib/tcell_agent/cmdi.rb +22 -23
- data/lib/tcell_agent/config/unknown_options.rb +71 -69
- data/lib/tcell_agent/configuration.rb +187 -191
- data/lib/tcell_agent/devise.rb +13 -15
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrumentation.rb +120 -124
- data/lib/tcell_agent/logger.rb +29 -45
- data/lib/tcell_agent/patches.rb +5 -5
- data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
- data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
- data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +24 -29
- data/lib/tcell_agent/rails.rb +2 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
- data/lib/tcell_agent/rails/auth/devise.rb +2 -2
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
- data/lib/tcell_agent/rails/better_ip.rb +12 -16
- data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
- data/lib/tcell_agent/rails/dlp.rb +208 -107
- data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
- data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
- data/lib/tcell_agent/rails/on_start.rb +5 -5
- data/lib/tcell_agent/rails/responses.rb +7 -9
- data/lib/tcell_agent/rails/routes.rb +62 -81
- data/lib/tcell_agent/rails/routes/grape.rb +25 -30
- data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
- data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
- data/lib/tcell_agent/routes/table.rb +31 -33
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +32 -37
- data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +101 -104
- data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
- data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
- data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
- data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
- data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
- data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
- data/lib/tcell_agent/sensor_events/patches.rb +10 -12
- data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
- data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
- data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
- data/lib/tcell_agent/servers/passenger.rb +5 -9
- data/lib/tcell_agent/servers/puma.rb +18 -27
- data/lib/tcell_agent/servers/rails_server.rb +5 -9
- data/lib/tcell_agent/servers/thin.rb +2 -4
- data/lib/tcell_agent/servers/unicorn.rb +18 -27
- data/lib/tcell_agent/servers/webrick.rb +2 -4
- data/lib/tcell_agent/settings_reporter.rb +126 -0
- data/lib/tcell_agent/sinatra.rb +24 -26
- data/lib/tcell_agent/start_background_thread.rb +21 -142
- data/lib/tcell_agent/system_info.rb +4 -3
- data/lib/tcell_agent/tcell_context.rb +150 -0
- data/lib/tcell_agent/userinfo.rb +3 -3
- data/lib/tcell_agent/utils/io.rb +19 -24
- data/lib/tcell_agent/utils/params.rb +9 -15
- data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
- data/lib/tcell_agent/utils/strings.rb +4 -6
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
- data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
- data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
- data/spec/lib/tcell_agent/patches_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
- data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
- data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
- data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
- data/lib/tcell_agent/patches/meta_data.rb +0 -59
- data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
@@ -1,6 +1,6 @@
|
|
1
1
|
# See the file "LICENSE" for the full license governing this code.
|
2
2
|
|
3
|
-
#require 'tcell_agent/authlogic' if defined?(Authlogic)
|
3
|
+
# require 'tcell_agent/authlogic' if defined?(Authlogic)
|
4
4
|
|
5
5
|
require 'rails'
|
6
6
|
|
@@ -12,7 +12,7 @@ require 'tcell_agent/rails/dlp/process_request'
|
|
12
12
|
TCellAgent::Instrumentation::Rails.send_language_info
|
13
13
|
TCellAgent::Instrumentation::Rails.send_framework_info
|
14
14
|
|
15
|
-
if
|
15
|
+
if Rails.application
|
16
16
|
if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument?
|
17
17
|
TCellAgent::Instrumentation::Rails.send_settings(Rails.application)
|
18
18
|
end
|
@@ -20,17 +20,17 @@ if (Rails.application)
|
|
20
20
|
else
|
21
21
|
module TCellAgent
|
22
22
|
class MyRailtie < Rails::Railtie
|
23
|
-
initializer 'activeservice.autoload', :after => :set_autoload_paths do |
|
23
|
+
initializer 'activeservice.autoload', :after => :set_autoload_paths do |_app|
|
24
24
|
Rails.application.config.to_prepare do
|
25
25
|
require 'tcell_agent/devise' if defined?(Devise)
|
26
26
|
require 'tcell_agent/rails/auth/devise' if defined?(Devise)
|
27
27
|
require 'tcell_agent/authlogic' if defined?(Authlogic)
|
28
|
-
require 'tcell_agent/rails/auth/authlogic'
|
28
|
+
require 'tcell_agent/rails/auth/authlogic' if defined?(Authlogic)
|
29
29
|
require 'tcell_agent/rails/auth/doorkeeper'
|
30
30
|
end
|
31
31
|
|
32
32
|
# TODO: will this get run ever?
|
33
|
-
if
|
33
|
+
if TCellAgent.configuration.enabled
|
34
34
|
Rails.application.config.after_initialize do
|
35
35
|
TCellAgent::Instrumentation::Rails.send_settings(Rails.application)
|
36
36
|
end
|
@@ -1,26 +1,24 @@
|
|
1
1
|
module TCellAgent
|
2
2
|
module Utils
|
3
3
|
module Rails
|
4
|
-
|
5
4
|
STATUSES_MISSING_CONTENT_LENGTH = Set.new((100..199).to_a + [204, 205, 304])
|
6
5
|
|
7
6
|
def self.empty_content?(status_code, headers)
|
8
|
-
|
9
|
-
(
|
7
|
+
STATUSES_MISSING_CONTENT_LENGTH.include?(status_code.to_i) ||
|
8
|
+
(headers['Content-Length'] && headers['Content-Length'].to_i.zero?)
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.processable_response?(response_headers)
|
13
12
|
content_disposition = response_headers['Content-Disposition']
|
14
|
-
is_attachment = content_disposition &&
|
13
|
+
is_attachment = content_disposition && content_disposition =~ /^attachment/i
|
15
14
|
|
16
15
|
content_type = response_headers['Content-Type']
|
17
16
|
applicable_content_type = content_type &&
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
(content_type =~ %r{application/json}i ||
|
18
|
+
content_type =~ %r{application/xml}i ||
|
19
|
+
content_type =~ /^text/i)
|
20
|
+
!is_attachment && applicable_content_type
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'tcell_agent/configuration'
|
2
2
|
require 'tcell_agent/patches'
|
3
|
-
require 'tcell_agent/patches/meta_data'
|
4
3
|
require 'tcell_agent/rails/routes/grape'
|
5
4
|
require 'tcell_agent/rails/routes/route_id'
|
6
5
|
|
@@ -8,9 +7,7 @@ require 'json'
|
|
8
7
|
|
9
8
|
module TCellAgent
|
10
9
|
module Instrumentation
|
11
|
-
|
12
10
|
module Rails
|
13
|
-
|
14
11
|
class TCellRoute
|
15
12
|
attr_reader :route_id, :route_path, :route_path_raw, :route_destination
|
16
13
|
|
@@ -21,17 +18,15 @@ module TCellAgent
|
|
21
18
|
@route_path = nil
|
22
19
|
@route_destination = nil
|
23
20
|
|
24
|
-
|
25
|
-
@route_path_raw = route.path.spec.to_s
|
21
|
+
return unless route
|
26
22
|
|
27
|
-
|
28
|
-
@route_path = @route_path_raw.chomp("(.:format)")
|
23
|
+
@route_path_raw = route.path.spec.to_s
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
@route_path = @route_path_raw
|
26
|
+
@route_path = @route_path_raw.chomp('(.:format)')
|
27
|
+
|
28
|
+
@route_destination = nil
|
29
|
+
@route_destination = JSON.dump(@route.defaults) if @route.defaults
|
35
30
|
end
|
36
31
|
|
37
32
|
def report?
|
@@ -43,32 +38,29 @@ module TCellAgent
|
|
43
38
|
end
|
44
39
|
|
45
40
|
def grape_route?
|
46
|
-
TCellAgent::Instrumentation
|
41
|
+
TCellAgent::Instrumentation.grape_route?(@route)
|
47
42
|
end
|
48
|
-
|
49
43
|
end
|
50
44
|
|
51
45
|
class TCellRoute5 < TCellRoute
|
52
|
-
|
53
46
|
def report?
|
54
47
|
TCellAgent::Utils::Strings.present?(@route.verb) || grape_route?
|
55
48
|
end
|
56
49
|
|
57
50
|
def route_methods
|
58
|
-
(@route.verb ||
|
51
|
+
(@route.verb || '').split('|')
|
59
52
|
end
|
60
53
|
|
61
54
|
def grape_routes
|
62
55
|
@route.app.app.routes
|
63
56
|
end
|
64
|
-
|
65
57
|
end
|
66
58
|
|
67
59
|
class TCellRoute4 < TCellRoute
|
68
|
-
METHODS = %w[DELETE GET HEAD OPTIONS PATCH POST PUT TRACE CONNECT]
|
60
|
+
METHODS = %w[DELETE GET HEAD OPTIONS PATCH POST PUT TRACE CONNECT].freeze
|
69
61
|
|
70
62
|
def report?
|
71
|
-
@route.constraints.
|
63
|
+
@route.constraints.key?(:request_method) || grape_route?
|
72
64
|
end
|
73
65
|
|
74
66
|
def route_methods
|
@@ -85,49 +77,44 @@ module TCellAgent
|
|
85
77
|
end
|
86
78
|
|
87
79
|
def self.create_tcell_route(route)
|
88
|
-
if route
|
89
|
-
|
90
|
-
return TCellRoute5.new(route)
|
91
|
-
elsif ::Rails::VERSION::MAJOR < 5
|
92
|
-
return TCellRoute4.new(route)
|
93
|
-
end
|
94
|
-
end
|
80
|
+
return TCellRoute5.new(route) if route && ::Rails::VERSION::MAJOR == 5
|
81
|
+
return TCellRoute4.new(route) if route && ::Rails::VERSION::MAJOR < 5
|
95
82
|
|
96
83
|
TCellRoute.new
|
97
84
|
end
|
98
85
|
|
99
86
|
def self.instrument_routes
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
87
|
+
return unless ::Rails.application
|
88
|
+
|
89
|
+
::Rails.application.routes.routes.each do |route|
|
90
|
+
instrument_route(route)
|
104
91
|
end
|
105
92
|
end
|
106
93
|
|
107
94
|
def self.instrument_route(route)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
95
|
+
return unless TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument?
|
96
|
+
|
97
|
+
tcell_route = create_tcell_route(route)
|
98
|
+
|
99
|
+
return unless tcell_route.report?
|
100
|
+
|
101
|
+
if tcell_route.grape_route?
|
102
|
+
TCellAgent::Instrumentation.instrument_grape_api(tcell_route.route_path, tcell_route.grape_routes)
|
103
|
+
|
104
|
+
else
|
105
|
+
tcell_route.route_methods.each do |route_method|
|
106
|
+
route_id =
|
107
|
+
TCellAgent::SensorEvents::Util.calculate_route_id(route_method, tcell_route.route_path_raw)
|
108
|
+
TCellAgent.send_event(
|
109
|
+
TCellAgent::SensorEvents::AppRoutesSensorEvent.new(
|
110
|
+
tcell_route.route_path, route_method, route_id, nil, tcell_route.route_destination
|
111
|
+
)
|
112
|
+
)
|
126
113
|
end
|
127
114
|
end
|
128
115
|
end
|
129
116
|
|
130
|
-
if
|
117
|
+
if ::Rails::VERSION::MAJOR == 3
|
131
118
|
ActionDispatch::Routing::RouteSet.class_eval do
|
132
119
|
alias_method :tcell_add_route, :add_route
|
133
120
|
def add_route(app, conditions = {}, requirements = {}, defaults = {}, name = nil, anchor = true)
|
@@ -141,46 +128,42 @@ module TCellAgent
|
|
141
128
|
|
142
129
|
ActiveSupport.on_load(:action_controller) do
|
143
130
|
ActionController::Base.class_eval do
|
144
|
-
|
145
|
-
if (::Rails::VERSION::MAJOR == 5)
|
131
|
+
if ::Rails::VERSION::MAJOR == 5
|
146
132
|
prepend_around_action :tcell_around_filter_routes
|
147
|
-
elsif
|
133
|
+
elsif ::Rails::VERSION::MAJOR < 5
|
148
134
|
prepend_around_filter :tcell_around_filter_routes
|
149
135
|
end
|
150
136
|
def tcell_around_filter_routes
|
151
|
-
|
137
|
+
if TCellAgent.configuration.enabled &&
|
138
|
+
TCellAgent.configuration.should_instrument? &&
|
139
|
+
TCellAgent.configuration.should_intercept_requests?
|
140
|
+
TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
|
141
|
+
_match, parameters, route = ::Rails.application.routes.router.recognize(request) { |r, _| r }.first
|
152
142
|
|
153
|
-
|
154
|
-
|
155
|
-
TCellAgent.configuration.should_intercept_requests?
|
156
|
-
TCellAgent::Instrumentation.safe_block("Determining Rails Route ID") do
|
157
|
-
match, parameters, route = ::Rails.application.routes.router.recognize(request) { |r, _| r }.first
|
158
|
-
|
159
|
-
TCellAgent::Instrumentation::RouteId.update_context(env, parameters, route)
|
160
|
-
end
|
161
|
-
|
162
|
-
if TCellAgent::Instrumentation::Patches.block?(request)
|
163
|
-
return head(403)
|
164
|
-
end
|
143
|
+
TCellAgent::Instrumentation::RouteId.update_context(env, parameters, route)
|
144
|
+
end
|
165
145
|
|
166
|
-
|
146
|
+
if TCellAgent::Instrumentation::Patches.block?(request)
|
147
|
+
return head(403)
|
167
148
|
end
|
168
149
|
|
169
|
-
|
150
|
+
TCellAgent::DLP.handle_request_dlp_parameters(request)
|
170
151
|
end
|
152
|
+
|
153
|
+
yield
|
171
154
|
end
|
172
155
|
end
|
173
156
|
end
|
174
157
|
|
175
158
|
end
|
176
159
|
|
177
|
-
if
|
160
|
+
if ::Rails::VERSION::MAJOR == 4
|
178
161
|
ActionDispatch::Journey::Routes.class_eval do
|
179
162
|
alias_method :tcell_add_route, :add_route
|
180
163
|
def add_route(app, path, conditions, defaults, name = nil)
|
181
164
|
route = tcell_add_route(app, path, conditions, defaults, name)
|
182
165
|
|
183
|
-
TCellAgent::Instrumentation.safe_block(
|
166
|
+
TCellAgent::Instrumentation.safe_block('Reporting new route') do
|
184
167
|
TCellAgent::Instrumentation::Rails.instrument_route(route)
|
185
168
|
end
|
186
169
|
|
@@ -189,13 +172,13 @@ module TCellAgent
|
|
189
172
|
end
|
190
173
|
end
|
191
174
|
|
192
|
-
if
|
175
|
+
if ::Rails::VERSION::MAJOR == 5
|
193
176
|
ActionDispatch::Journey::Routes.class_eval do
|
194
177
|
alias_method :tcell_add_route, :add_route
|
195
178
|
def add_route(name, mapping)
|
196
179
|
route = tcell_add_route(name, mapping)
|
197
180
|
|
198
|
-
TCellAgent::Instrumentation.safe_block(
|
181
|
+
TCellAgent::Instrumentation.safe_block('Reporting new route') do
|
199
182
|
TCellAgent::Instrumentation::Rails.instrument_route(route)
|
200
183
|
end
|
201
184
|
|
@@ -204,14 +187,14 @@ module TCellAgent
|
|
204
187
|
end
|
205
188
|
end
|
206
189
|
|
207
|
-
if
|
190
|
+
if ::Rails::VERSION::MAJOR == 5 || (::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR >= 2)
|
208
191
|
ActionDispatch::Journey::Router.class_eval do
|
209
192
|
alias_method :tcell_serve, :serve
|
210
193
|
def serve(req)
|
211
194
|
if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument? &&
|
212
|
-
|
213
|
-
TCellAgent::Instrumentation.safe_block(
|
214
|
-
|
195
|
+
TCellAgent.configuration.should_intercept_requests?
|
196
|
+
TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
|
197
|
+
_match, parameters, route = find_routes(req).first
|
215
198
|
|
216
199
|
TCellAgent::Instrumentation::RouteId.update_context(req.env, parameters, route)
|
217
200
|
end
|
@@ -225,11 +208,10 @@ module TCellAgent
|
|
225
208
|
|
226
209
|
tcell_serve(req)
|
227
210
|
end
|
228
|
-
|
229
211
|
end
|
230
212
|
end
|
231
213
|
|
232
|
-
if
|
214
|
+
if ::Rails::VERSION::MAJOR == 4 && ::Rails::VERSION::MINOR < 2
|
233
215
|
require 'action_dispatch/journey/router/utils'
|
234
216
|
|
235
217
|
ActionDispatch::Journey::Router.class_eval do
|
@@ -238,9 +220,9 @@ module TCellAgent
|
|
238
220
|
env['PATH_INFO'] = ActionDispatch::Journey::Router::Utils.normalize_path(env['PATH_INFO'])
|
239
221
|
|
240
222
|
if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument? &&
|
241
|
-
|
242
|
-
TCellAgent::Instrumentation.safe_block(
|
243
|
-
|
223
|
+
TCellAgent.configuration.should_intercept_requests?
|
224
|
+
TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
|
225
|
+
_match, parameters, route = find_routes(env).first
|
244
226
|
|
245
227
|
TCellAgent::Instrumentation::RouteId.update_context(env, parameters, route)
|
246
228
|
end
|
@@ -258,7 +240,6 @@ module TCellAgent
|
|
258
240
|
end
|
259
241
|
end
|
260
242
|
end
|
261
|
-
|
262
243
|
end
|
263
244
|
end
|
264
245
|
end
|
@@ -2,7 +2,6 @@ require 'tcell_agent/configuration'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Instrumentation
|
5
|
-
|
6
5
|
def self.grape_route?(route)
|
7
6
|
if defined?(Grape::API)
|
8
7
|
begin
|
@@ -15,7 +14,8 @@ module TCellAgent
|
|
15
14
|
end
|
16
15
|
|
17
16
|
return true
|
18
|
-
rescue StandardError
|
17
|
+
rescue StandardError # rubocop:disable Lint/HandleExceptions
|
18
|
+
# do nothing
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -23,26 +23,26 @@ module TCellAgent
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.instrument_grape_api(grape_mount_endpoint, routes)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
return unless routes
|
27
|
+
|
28
|
+
routes.each do |route|
|
29
|
+
route_info = grape_route_info(route)
|
30
|
+
|
31
|
+
route_path = "#{grape_mount_endpoint}#{route_info[:path]}"
|
32
|
+
route_method = route_info[:method]
|
33
|
+
|
34
|
+
route_id = TCellAgent::SensorEvents::Util.calculate_route_id(route_method, route_path)
|
35
|
+
TCellAgent.send_event(
|
36
|
+
TCellAgent::SensorEvents::AppRoutesSensorEvent.new(
|
37
|
+
route_path, route_method, route_id, nil, nil
|
38
38
|
)
|
39
|
-
|
39
|
+
)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.grape_route_info(route)
|
44
|
-
major, minor,
|
45
|
-
if major.to_i
|
44
|
+
major, minor, _tiny = Gem.loaded_specs['grape'].version.to_s.split('.')
|
45
|
+
if major.to_i.zero? && minor.to_i < 16
|
46
46
|
{
|
47
47
|
:method => route.route_method,
|
48
48
|
:path => route.route_path
|
@@ -56,8 +56,8 @@ module TCellAgent
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def self.grape_route_params(route)
|
59
|
-
major, minor,
|
60
|
-
if major.to_i
|
59
|
+
major, minor, _tiny = Gem.loaded_specs['grape'].version.to_s.split('.')
|
60
|
+
if major.to_i.zero? && minor.to_i < 16
|
61
61
|
route.route_params
|
62
62
|
else
|
63
63
|
route.params
|
@@ -68,25 +68,21 @@ module TCellAgent
|
|
68
68
|
def self.grape_path_params(env, route)
|
69
69
|
all_params = Grape::Request.new(env).params
|
70
70
|
|
71
|
-
|
71
|
+
grape_route_params(route).keys.each_with_object({}) do |key, memo|
|
72
72
|
memo[key] = all_params[key]
|
73
|
-
|
74
|
-
memo
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
76
|
Grape::Endpoint.class_eval do
|
79
|
-
|
80
77
|
alias_method :tcell_call!, :call!
|
81
78
|
def call!(env)
|
82
79
|
if TCellAgent.configuration.enabled &&
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
TCellAgent::Instrumentation.safe_block("Determining Rails Route ID") do
|
80
|
+
TCellAgent.configuration.should_instrument? &&
|
81
|
+
TCellAgent.configuration.should_intercept_requests?
|
87
82
|
|
83
|
+
TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
|
88
84
|
tcell_context = env[TCellAgent::Instrumentation::TCELL_ID]
|
89
|
-
if tcell_context && tcell_context.grape_mount_endpoint &&
|
85
|
+
if tcell_context && tcell_context.grape_mount_endpoint && respond_to?(:routes)
|
90
86
|
route = routes.first
|
91
87
|
|
92
88
|
if route
|
@@ -96,7 +92,7 @@ module TCellAgent
|
|
96
92
|
if route_path
|
97
93
|
tcell_context.path_parameters = TCellAgent::Instrumentation.grape_path_params(env, route)
|
98
94
|
tcell_context.route_id =
|
99
|
-
TCellAgent::SensorEvents::Util.
|
95
|
+
TCellAgent::SensorEvents::Util.calculate_route_id(tcell_context.request_method, route_path)
|
100
96
|
end
|
101
97
|
end
|
102
98
|
end
|
@@ -108,6 +104,5 @@ module TCellAgent
|
|
108
104
|
end
|
109
105
|
|
110
106
|
end
|
111
|
-
|
112
107
|
end
|
113
108
|
end
|