newrelic_rpm 6.12.0.367 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +269 -8
- data/CONTRIBUTING.md +54 -11
- data/README.md +40 -16
- data/ROADMAP.md +24 -0
- data/lib/new_relic/agent.rb +3 -10
- data/lib/new_relic/agent/agent.rb +6 -4
- data/lib/new_relic/agent/audit_logger.rb +10 -0
- data/lib/new_relic/agent/autostart.rb +1 -2
- data/lib/new_relic/agent/configuration/default_source.rb +294 -102
- data/lib/new_relic/agent/configuration/manager.rb +2 -2
- data/lib/new_relic/agent/database_adapter.rb +33 -0
- data/lib/new_relic/agent/datastores/redis.rb +0 -4
- data/lib/new_relic/agent/distributed_tracing.rb +0 -66
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +2 -2
- data/lib/new_relic/agent/http_clients/uri_util.rb +8 -8
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -5
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +21 -68
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
- data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +23 -57
- data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -15
- data/lib/new_relic/agent/instrumentation/bunny.rb +10 -196
- data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
- data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
- data/lib/new_relic/agent/instrumentation/curb.rb +9 -259
- data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
- data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
- data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
- data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
- data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
- data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -84
- data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
- data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
- data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
- data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
- data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
- data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
- data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
- data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
- data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
- data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
- data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
- data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
- data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
- data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -10
- data/lib/new_relic/agent/instrumentation/mongo.rb +7 -0
- data/lib/new_relic/agent/instrumentation/net_http.rb +39 -0
- data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
- data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino.rb +18 -75
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
- data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
- data/lib/new_relic/agent/instrumentation/rack.rb +29 -160
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +57 -0
- data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
- data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +36 -0
- data/lib/new_relic/agent/instrumentation/rake.rb +13 -187
- data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
- data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
- data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
- data/lib/new_relic/agent/instrumentation/redis.rb +10 -188
- data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
- data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
- data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
- data/lib/new_relic/agent/instrumentation/resque.rb +8 -28
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +33 -0
- data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -198
- data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +118 -0
- data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
- data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
- data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
- data/lib/new_relic/agent/method_tracer.rb +6 -16
- data/lib/new_relic/agent/new_relic_service.rb +19 -5
- data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
- data/lib/new_relic/agent/span_event_primitive.rb +10 -8
- data/lib/new_relic/agent/sql_sampler.rb +1 -1
- data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
- data/lib/new_relic/agent/transaction.rb +1 -4
- data/lib/new_relic/agent/transaction/abstract_segment.rb +1 -1
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +12 -6
- data/lib/new_relic/agent/transaction/external_request_segment.rb +2 -2
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
- data/lib/new_relic/agent/transaction/segment.rb +9 -5
- data/lib/new_relic/agent/vm/mri_vm.rb +6 -4
- data/lib/new_relic/cli/commands/deployments.rb +0 -1
- data/lib/new_relic/constants.rb +4 -0
- data/lib/new_relic/control/frameworks/rails.rb +11 -9
- data/lib/new_relic/control/instance_methods.rb +1 -0
- data/lib/new_relic/dependency_detection.rb +119 -9
- data/lib/new_relic/environment_report.rb +1 -7
- data/lib/new_relic/noticed_error.rb +1 -5
- data/lib/new_relic/supportability_helper.rb +3 -2
- data/lib/new_relic/version.rb +2 -2
- data/lib/tasks/multiverse.rb +9 -0
- data/newrelic_rpm.gemspec +2 -3
- data/test/agent_helper.rb +7 -0
- metadata +55 -12
- data/.travis.yml +0 -240
- data/CODE_OF_CONDUCT.md +0 -46
- data/cert/cacert.pem +0 -1177
- data/lib/new_relic/agent/instrumentation/http.rb +0 -49
- data/lib/new_relic/agent/instrumentation/net.rb +0 -87
- data/lib/new_relic/metrics.rb +0 -13
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
|
+
|
5
|
+
|
6
|
+
module NewRelic::Agent::Instrumentation
|
7
|
+
module Resque
|
8
|
+
module Prepend
|
9
|
+
include NewRelic::Agent::Instrumentation::Resque
|
10
|
+
|
11
|
+
def perform
|
12
|
+
with_tracing { super }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -46,7 +46,7 @@ DependencyDetection.defer do
|
|
46
46
|
end
|
47
47
|
class Client
|
48
48
|
def call(_worker_class, job, *_)
|
49
|
-
job[NewRelic::NEWRELIC_KEY]
|
49
|
+
job[NewRelic::NEWRELIC_KEY] ||= distributed_tracing_headers if ::NewRelic::Agent.config[:'distributed_tracing.enabled']
|
50
50
|
yield
|
51
51
|
end
|
52
52
|
|
@@ -2,45 +2,33 @@
|
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require_relative 'sinatra/transaction_namer'
|
6
|
+
require_relative 'sinatra/ignorer'
|
7
|
+
require_relative 'sinatra/instrumentation'
|
8
|
+
require_relative 'sinatra/chain'
|
9
|
+
require_relative 'sinatra/prepend'
|
9
10
|
|
10
11
|
DependencyDetection.defer do
|
11
|
-
|
12
|
+
named :sinatra
|
12
13
|
|
13
|
-
depends_on
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Sinatra::Base.private_method_defined?(:process_route) &&
|
18
|
-
Sinatra::Base.private_method_defined?(:route_eval)
|
19
|
-
end
|
14
|
+
depends_on { defined?(::Sinatra) && defined?(::Sinatra::Base) }
|
15
|
+
depends_on { Sinatra::Base.private_method_defined?(:dispatch!) }
|
16
|
+
depends_on { Sinatra::Base.private_method_defined?(:process_route) }
|
17
|
+
depends_on { Sinatra::Base.private_method_defined?(:route_eval) }
|
20
18
|
|
21
19
|
executes do
|
22
20
|
::NewRelic::Agent.logger.info 'Installing Sinatra instrumentation'
|
23
21
|
end
|
24
22
|
|
25
23
|
executes do
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
alias dispatch! dispatch_with_newrelic
|
31
|
-
|
32
|
-
alias process_route_without_newrelic process_route
|
33
|
-
alias process_route process_route_with_newrelic
|
34
|
-
|
35
|
-
alias route_eval_without_newrelic route_eval
|
36
|
-
alias route_eval route_eval_with_newrelic
|
37
|
-
|
38
|
-
register NewRelic::Agent::Instrumentation::Sinatra::Ignorer
|
24
|
+
if use_prepend?
|
25
|
+
prepend_instrument ::Sinatra::Base, NewRelic::Agent::Instrumentation::Sinatra::Prepend
|
26
|
+
else
|
27
|
+
chain_instrument NewRelic::Agent::Instrumentation::Sinatra::Chain
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
30
|
+
::Sinatra::Base.class_eval { register ::NewRelic::Agent::Instrumentation::Sinatra::Ignorer }
|
31
|
+
::Sinatra.module_eval { register NewRelic::Agent::Instrumentation::Sinatra::Ignorer }
|
44
32
|
end
|
45
33
|
|
46
34
|
executes do
|
@@ -49,179 +37,13 @@ DependencyDetection.defer do
|
|
49
37
|
# we can't be sure that rack is available when this file is first required.
|
50
38
|
require 'new_relic/rack/agent_hooks'
|
51
39
|
require 'new_relic/rack/browser_monitoring'
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
alias build build_with_newrelic
|
57
|
-
end
|
40
|
+
if use_prepend?
|
41
|
+
prepend_instrument ::Sinatra::Base.singleton_class, NewRelic::Agent::Instrumentation::Sinatra::Build::Prepend
|
42
|
+
else
|
43
|
+
chain_instrument NewRelic::Agent::Instrumentation::Sinatra::Build::Chain
|
58
44
|
end
|
59
45
|
else
|
60
46
|
::NewRelic::Agent.logger.info("Skipping auto-injection of middleware for Sinatra - requires Sinatra 1.2.1+")
|
61
47
|
end
|
62
48
|
end
|
63
49
|
end
|
64
|
-
|
65
|
-
module NewRelic
|
66
|
-
module Agent
|
67
|
-
module Instrumentation
|
68
|
-
# NewRelic instrumentation for Sinatra applications. Sinatra actions will
|
69
|
-
# appear in the UI similar to controller actions, and have breakdown charts
|
70
|
-
# and transaction traces.
|
71
|
-
#
|
72
|
-
# The actions in the UI will correspond to the pattern expression used
|
73
|
-
# to match them, not directly to full URL's.
|
74
|
-
module Sinatra
|
75
|
-
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
76
|
-
|
77
|
-
# Expected method for supporting ControllerInstrumentation
|
78
|
-
def newrelic_request_headers(_)
|
79
|
-
request.env
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.included(clazz)
|
83
|
-
clazz.extend(ClassMethods)
|
84
|
-
end
|
85
|
-
|
86
|
-
module ClassMethods
|
87
|
-
def newrelic_middlewares
|
88
|
-
middlewares = [NewRelic::Rack::BrowserMonitoring]
|
89
|
-
if NewRelic::Rack::AgentHooks.needed?
|
90
|
-
middlewares << NewRelic::Rack::AgentHooks
|
91
|
-
end
|
92
|
-
middlewares
|
93
|
-
end
|
94
|
-
|
95
|
-
if RUBY_VERSION < "2.7.0"
|
96
|
-
def build_with_newrelic(*args, &block)
|
97
|
-
unless NewRelic::Agent.config[:disable_sinatra_auto_middleware]
|
98
|
-
newrelic_middlewares.each do |middleware_class|
|
99
|
-
try_to_use(self, middleware_class)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
build_without_newrelic(*args, &block)
|
103
|
-
end
|
104
|
-
else
|
105
|
-
def build_with_newrelic(*args, **kwargs, &block)
|
106
|
-
unless NewRelic::Agent.config[:disable_sinatra_auto_middleware]
|
107
|
-
newrelic_middlewares.each do |middleware_class|
|
108
|
-
try_to_use(self, middleware_class)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
build_without_newrelic(*args, **kwargs, &block)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def try_to_use(app, clazz)
|
116
|
-
has_middleware = app.middleware.any? { |info| info[0] == clazz }
|
117
|
-
app.use(clazz) unless has_middleware
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Capture last route we've seen. Will set for transaction on route_eval
|
122
|
-
if RUBY_VERSION < "2.7.0"
|
123
|
-
def process_route_with_newrelic(*args, &block)
|
124
|
-
begin
|
125
|
-
env["newrelic.last_route"] = args[0]
|
126
|
-
rescue => e
|
127
|
-
::NewRelic::Agent.logger.debug("Failed determining last route in Sinatra", e)
|
128
|
-
end
|
129
|
-
|
130
|
-
process_route_without_newrelic(*args, &block)
|
131
|
-
end
|
132
|
-
else
|
133
|
-
def process_route_with_newrelic(*args, **kwargs, &block)
|
134
|
-
begin
|
135
|
-
env["newrelic.last_route"] = args[0]
|
136
|
-
rescue => e
|
137
|
-
::NewRelic::Agent.logger.debug("Failed determining last route in Sinatra", e)
|
138
|
-
end
|
139
|
-
|
140
|
-
process_route_without_newrelic(*args, **kwargs, &block)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
# If a transaction name is already set, this call will tromple over it.
|
145
|
-
# This is intentional, as typically passing to a separate route is like
|
146
|
-
# an entirely separate transaction, so we pick up the new name.
|
147
|
-
#
|
148
|
-
# If we're ignored, this remains safe, since set_transaction_name
|
149
|
-
# care for the gating on the transaction's existence for us.
|
150
|
-
if RUBY_VERSION < "2.7.0"
|
151
|
-
def route_eval_with_newrelic(*args, &block)
|
152
|
-
begin
|
153
|
-
txn_name = TransactionNamer.transaction_name_for_route(env, request)
|
154
|
-
unless txn_name.nil?
|
155
|
-
::NewRelic::Agent::Transaction.set_default_transaction_name(
|
156
|
-
"#{self.class.name}/#{txn_name}", :sinatra)
|
157
|
-
end
|
158
|
-
rescue => e
|
159
|
-
::NewRelic::Agent.logger.debug("Failed during route_eval to set transaction name", e)
|
160
|
-
end
|
161
|
-
|
162
|
-
route_eval_without_newrelic(*args, &block)
|
163
|
-
end
|
164
|
-
else
|
165
|
-
def route_eval_with_newrelic(*args, **kwargs, &block)
|
166
|
-
begin
|
167
|
-
txn_name = TransactionNamer.transaction_name_for_route(env, request)
|
168
|
-
unless txn_name.nil?
|
169
|
-
::NewRelic::Agent::Transaction.set_default_transaction_name(
|
170
|
-
"#{self.class.name}/#{txn_name}", :sinatra)
|
171
|
-
end
|
172
|
-
rescue => e
|
173
|
-
::NewRelic::Agent.logger.debug("Failed during route_eval to set transaction name", e)
|
174
|
-
end
|
175
|
-
|
176
|
-
route_eval_without_newrelic(*args, **kwargs, &block)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def dispatch_with_newrelic #THREAD_LOCAL_ACCESS
|
181
|
-
request_params = get_request_params
|
182
|
-
filtered_params = ParameterFiltering::apply_filters(request.env, request_params || {})
|
183
|
-
|
184
|
-
name = TransactionNamer.initial_transaction_name(request)
|
185
|
-
perform_action_with_newrelic_trace(:category => :sinatra,
|
186
|
-
:name => name,
|
187
|
-
:params => filtered_params) do
|
188
|
-
dispatch_and_notice_errors_with_newrelic
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def get_request_params
|
193
|
-
begin
|
194
|
-
@request.params
|
195
|
-
rescue => e
|
196
|
-
NewRelic::Agent.logger.debug("Failed to get params from Rack request.", e)
|
197
|
-
nil
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def dispatch_and_notice_errors_with_newrelic
|
202
|
-
dispatch_without_newrelic
|
203
|
-
ensure
|
204
|
-
# Will only see an error raised if :show_exceptions is true, but
|
205
|
-
# will always see them in the env hash if they occur
|
206
|
-
had_error = env.has_key?('sinatra.error')
|
207
|
-
::NewRelic::Agent.notice_error(env['sinatra.error']) if had_error
|
208
|
-
end
|
209
|
-
|
210
|
-
def do_not_trace?
|
211
|
-
Ignorer.should_ignore?(self, :routes)
|
212
|
-
end
|
213
|
-
|
214
|
-
# Overrides ControllerInstrumentation implementation
|
215
|
-
def ignore_apdex?
|
216
|
-
Ignorer.should_ignore?(self, :apdex)
|
217
|
-
end
|
218
|
-
|
219
|
-
# Overrides ControllerInstrumentation implementation
|
220
|
-
def ignore_enduser?
|
221
|
-
Ignorer.should_ignore?(self, :enduser)
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
|
+
|
5
|
+
module NewRelic::Agent::Instrumentation
|
6
|
+
module Sinatra
|
7
|
+
module Chain
|
8
|
+
def self.instrument!
|
9
|
+
::Sinatra::Base.class_eval do
|
10
|
+
include ::NewRelic::Agent::Instrumentation::Sinatra::Tracer
|
11
|
+
|
12
|
+
def dispatch_with_newrelic
|
13
|
+
dispatch_with_tracing { dispatch_without_newrelic }
|
14
|
+
end
|
15
|
+
alias dispatch_without_newrelic dispatch!
|
16
|
+
alias dispatch! dispatch_with_newrelic
|
17
|
+
|
18
|
+
def process_route_with_newrelic(*args, &block)
|
19
|
+
process_route_with_tracing(*args) do
|
20
|
+
process_route_without_newrelic(*args, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
alias process_route_without_newrelic process_route
|
24
|
+
alias process_route process_route_with_newrelic
|
25
|
+
|
26
|
+
def route_eval_with_newrelic(*args, &block)
|
27
|
+
route_eval_with_tracing(*args) do
|
28
|
+
route_eval_without_newrelic(*args, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias route_eval_without_newrelic route_eval
|
32
|
+
alias route_eval route_eval_with_newrelic
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Build
|
38
|
+
module Chain
|
39
|
+
def self.instrument!
|
40
|
+
::Sinatra::Base.class_eval do
|
41
|
+
class << self
|
42
|
+
def build_with_newrelic(*args, &block)
|
43
|
+
build_with_tracing(*args) do
|
44
|
+
build_without_newrelic(*args, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
alias build_without_newrelic build
|
48
|
+
alias build build_with_newrelic
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -2,49 +2,44 @@
|
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
4
|
|
5
|
-
module NewRelic
|
6
|
-
module
|
7
|
-
module
|
8
|
-
module Sinatra
|
9
|
-
module Ignorer
|
5
|
+
module NewRelic::Agent::Instrumentation
|
6
|
+
module Sinatra
|
7
|
+
module Ignorer
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
def self.should_ignore?(app, type)
|
10
|
+
return false if !app.settings.respond_to?(:newrelic_ignores)
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def newrelic_ignore(*routes)
|
20
|
-
set_newrelic_ignore(:routes, *routes)
|
21
|
-
end
|
12
|
+
app.settings.newrelic_ignores[type].any? do |pattern|
|
13
|
+
pattern.match(app.request.path_info)
|
14
|
+
end
|
15
|
+
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
def newrelic_ignore(*routes)
|
18
|
+
set_newrelic_ignore(:routes, *routes)
|
19
|
+
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
21
|
+
def newrelic_ignore_apdex(*routes)
|
22
|
+
set_newrelic_ignore(:apdex, *routes)
|
23
|
+
end
|
30
24
|
|
31
|
-
|
25
|
+
def newrelic_ignore_enduser(*routes)
|
26
|
+
set_newrelic_ignore(:enduser, *routes)
|
27
|
+
end
|
32
28
|
|
33
|
-
|
34
|
-
# Important to default this in the context of the actual app
|
35
|
-
# If it's done at register time, ignores end up shared between apps.
|
36
|
-
set :newrelic_ignores, Hash.new([]) if !respond_to?(:newrelic_ignores)
|
29
|
+
private
|
37
30
|
|
38
|
-
|
39
|
-
|
31
|
+
def set_newrelic_ignore(type, *routes)
|
32
|
+
# Important to default this in the context of the actual app
|
33
|
+
# If it's done at register time, ignores end up shared between apps.
|
34
|
+
set :newrelic_ignores, Hash.new([]) if !respond_to?(:newrelic_ignores)
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
# exactly Sinatra's mapping of route text to regex
|
44
|
-
Array(send(:compile, r)).first
|
45
|
-
end
|
46
|
-
end
|
36
|
+
# If we call an ignore without a route, it applies to the whole app
|
37
|
+
routes = ["*"] if routes.empty?
|
47
38
|
|
39
|
+
settings.newrelic_ignores[type] += routes.map do |r|
|
40
|
+
# Ugly sending to private Base#compile, but we want to mimic
|
41
|
+
# exactly Sinatra's mapping of route text to regex
|
42
|
+
Array(send(:compile, r)).first
|
48
43
|
end
|
49
44
|
end
|
50
45
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
|
4
|
+
|
5
|
+
# NewRelic instrumentation for Sinatra applications. Sinatra actions will
|
6
|
+
# appear in the UI similar to controller actions, and have breakdown charts
|
7
|
+
# and transaction traces.
|
8
|
+
#
|
9
|
+
# The actions in the UI will correspond to the pattern expression used
|
10
|
+
# to match them, not directly to full URL's.
|
11
|
+
module NewRelic::Agent::Instrumentation
|
12
|
+
module Sinatra
|
13
|
+
module Tracer
|
14
|
+
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
15
|
+
|
16
|
+
def self.included(clazz)
|
17
|
+
clazz.extend(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Expected method for supporting ControllerInstrumentation
|
21
|
+
def newrelic_request_headers(_)
|
22
|
+
request.env
|
23
|
+
end
|
24
|
+
|
25
|
+
def newrelic_middlewares
|
26
|
+
middlewares = [NewRelic::Rack::BrowserMonitoring]
|
27
|
+
if NewRelic::Rack::AgentHooks.needed?
|
28
|
+
middlewares << NewRelic::Rack::AgentHooks
|
29
|
+
end
|
30
|
+
middlewares
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_with_tracing(*args, &block)
|
34
|
+
unless NewRelic::Agent.config[:disable_sinatra_auto_middleware]
|
35
|
+
newrelic_middlewares.each do |middleware_class|
|
36
|
+
try_to_use(self, middleware_class)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
yield
|
40
|
+
end
|
41
|
+
|
42
|
+
def try_to_use(app, clazz)
|
43
|
+
has_middleware = app.middleware.any? { |info| info[0] == clazz }
|
44
|
+
app.use(clazz) unless has_middleware
|
45
|
+
end
|
46
|
+
|
47
|
+
# Capture last route we've seen. Will set for transaction on route_eval
|
48
|
+
def process_route_with_tracing(*args)
|
49
|
+
begin
|
50
|
+
env["newrelic.last_route"] = args[0]
|
51
|
+
rescue => e
|
52
|
+
::NewRelic::Agent.logger.debug("Failed determining last route in Sinatra", e)
|
53
|
+
end
|
54
|
+
yield
|
55
|
+
end
|
56
|
+
|
57
|
+
# If a transaction name is already set, this call will tromple over it.
|
58
|
+
# This is intentional, as typically passing to a separate route is like
|
59
|
+
# an entirely separate transaction, so we pick up the new name.
|
60
|
+
#
|
61
|
+
# If we're ignored, this remains safe, since set_transaction_name
|
62
|
+
# care for the gating on the transaction's existence for us.
|
63
|
+
def route_eval_with_tracing(*args)
|
64
|
+
begin
|
65
|
+
if txn_name = TransactionNamer.transaction_name_for_route(env, request)
|
66
|
+
::NewRelic::Agent::Transaction.set_default_transaction_name(
|
67
|
+
"#{self.class.name}/#{txn_name}", :sinatra)
|
68
|
+
end
|
69
|
+
rescue => e
|
70
|
+
::NewRelic::Agent.logger.debug("Failed during route_eval to set transaction name", e)
|
71
|
+
end
|
72
|
+
yield
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_request_params
|
76
|
+
begin
|
77
|
+
@request.params
|
78
|
+
rescue => e
|
79
|
+
NewRelic::Agent.logger.debug("Failed to get params from Rack request.", e)
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def dispatch_with_tracing
|
85
|
+
request_params = get_request_params
|
86
|
+
filtered_params = ::NewRelic::Agent::ParameterFiltering::apply_filters(request.env, request_params || {})
|
87
|
+
|
88
|
+
name = TransactionNamer.initial_transaction_name(request)
|
89
|
+
perform_action_with_newrelic_trace(:category => :sinatra,
|
90
|
+
:name => name,
|
91
|
+
:params => filtered_params) do
|
92
|
+
begin
|
93
|
+
yield
|
94
|
+
ensure
|
95
|
+
# Will only see an error raised if :show_exceptions is true, but
|
96
|
+
# will always see them in the env hash if they occur
|
97
|
+
had_error = env.has_key?('sinatra.error')
|
98
|
+
::NewRelic::Agent.notice_error(env['sinatra.error']) if had_error
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def do_not_trace?
|
104
|
+
Ignorer.should_ignore?(self, :routes)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Overrides ControllerInstrumentation implementation
|
108
|
+
def ignore_apdex?
|
109
|
+
Ignorer.should_ignore?(self, :apdex)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Overrides ControllerInstrumentation implementation
|
113
|
+
def ignore_enduser?
|
114
|
+
Ignorer.should_ignore?(self, :enduser)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|