newrelic_rpm 6.13.1 → 7.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +247 -0
- data/CONTRIBUTING.md +13 -2
- data/README.md +2 -2
- data/lib/new_relic/agent.rb +6 -8
- data/lib/new_relic/agent/agent.rb +4 -5
- 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 +462 -221
- data/lib/new_relic/agent/configuration/manager.rb +3 -3
- data/lib/new_relic/agent/connect/request_builder.rb +4 -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/error_collector.rb +52 -37
- data/lib/new_relic/agent/error_filter.rb +167 -0
- 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/active_record_subscriber.rb +1 -3
- 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/controller_instrumentation.rb +1 -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 +44 -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 +58 -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 +37 -0
- data/lib/new_relic/agent/instrumentation/rake.rb +13 -188
- 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 +12 -186
- 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 +21 -32
- data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -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 +124 -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/javascript_instrumentor.rb +12 -7
- data/lib/new_relic/agent/method_tracer.rb +6 -16
- data/lib/new_relic/agent/new_relic_service.rb +16 -13
- 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 +3 -3
- 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/message_broker_segment.rb +1 -0
- 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 +4 -8
- data/lib/new_relic/supportability_helper.rb +3 -2
- data/lib/new_relic/version.rb +3 -3
- data/lib/tasks/config.html.erb +14 -25
- data/lib/tasks/config.rake +8 -7
- data/newrelic_rpm.gemspec +2 -2
- data/test/agent_helper.rb +1 -0
- metadata +56 -32
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/config.yml +0 -5
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
- data/.github/actions/annotate/README.md +0 -79
- data/.github/actions/annotate/action.yml +0 -6
- data/.github/actions/annotate/dist/index.js +0 -433
- data/.github/actions/annotate/index.js +0 -25
- data/.github/actions/annotate/package-lock.json +0 -172
- data/.github/actions/annotate/package.json +0 -30
- data/.github/actions/annotate/pre-commit +0 -5
- data/.github/actions/build-ruby/README.md +0 -79
- data/.github/actions/build-ruby/action.yml +0 -15
- data/.github/actions/build-ruby/dist/index.js +0 -52683
- data/.github/actions/build-ruby/index.js +0 -514
- data/.github/actions/build-ruby/package-lock.json +0 -581
- data/.github/actions/build-ruby/package.json +0 -32
- data/.github/actions/build-ruby/pre-commit +0 -5
- data/.github/pull_request_template.md +0 -16
- data/.github/workflows/ci.yml +0 -212
- data/.github/workflows/pr_review_checklist.yml +0 -22
- data/.github/workflows/release.yml +0 -78
- data/.github/workflows/scripts/rubygems-authenticate.py +0 -13
- data/.github/workflows/scripts/rubygems-publish.rb +0 -32
- data/.github/workflows/snyk.yml +0 -27
- data/.github/workflows/stale.yml +0 -21
- 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
@@ -0,0 +1,34 @@
|
|
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
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module NewRelic::Agent::Instrumentation
|
7
|
+
module Redis
|
8
|
+
module Chain
|
9
|
+
def self.instrument!
|
10
|
+
::Redis::Client.class_eval do
|
11
|
+
include NewRelic::Agent::Instrumentation::Redis
|
12
|
+
|
13
|
+
alias_method :call_without_new_relic, :call
|
14
|
+
|
15
|
+
def call(*args, &block)
|
16
|
+
call_with_tracing(args[0]) { call_without_new_relic(*args, &block) }
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :call_pipeline_without_new_relic, :call_pipeline
|
20
|
+
|
21
|
+
def call_pipeline(*args, &block)
|
22
|
+
call_pipeline_with_tracing(args[0]) { call_pipeline_without_new_relic(*args, &block) }
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :connect_without_new_relic, :connect
|
26
|
+
|
27
|
+
def connect(*args, &block)
|
28
|
+
connect_with_tracing { connect_without_new_relic(*args, &block) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module NewRelic::Agent::Instrumentation
|
7
|
+
module Redis
|
8
|
+
PRODUCT_NAME = 'Redis'
|
9
|
+
CONNECT = 'connect'
|
10
|
+
UNKNOWN = "unknown"
|
11
|
+
LOCALHOST = "localhost"
|
12
|
+
MULTI_OPERATION = 'multi'
|
13
|
+
PIPELINE_OPERATION = 'pipeline'
|
14
|
+
|
15
|
+
def call_with_tracing command, &block
|
16
|
+
operation = command[0]
|
17
|
+
statement = ::NewRelic::Agent::Datastores::Redis.format_command(command)
|
18
|
+
|
19
|
+
with_tracing(operation, statement) { yield }
|
20
|
+
end
|
21
|
+
|
22
|
+
def call_pipeline_with_tracing pipeline
|
23
|
+
operation = pipeline.is_a?(::Redis::Pipeline::Multi) ? MULTI_OPERATION : PIPELINE_OPERATION
|
24
|
+
statement = ::NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline.commands)
|
25
|
+
|
26
|
+
with_tracing(operation, statement) { yield }
|
27
|
+
end
|
28
|
+
|
29
|
+
def connect_with_tracing
|
30
|
+
with_tracing(CONNECT) { yield }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def with_tracing operation, statement=nil
|
36
|
+
segment = NewRelic::Agent::Tracer.start_datastore_segment(
|
37
|
+
product: PRODUCT_NAME,
|
38
|
+
operation: operation,
|
39
|
+
host: _nr_hostname,
|
40
|
+
port_path_or_id: _nr_port_path_or_id,
|
41
|
+
database_name: db
|
42
|
+
)
|
43
|
+
begin
|
44
|
+
segment.notice_nosql_statement(statement) if statement
|
45
|
+
NewRelic::Agent::Tracer.capture_segment_error(segment) { yield }
|
46
|
+
ensure
|
47
|
+
segment.finish if segment
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def _nr_hostname
|
52
|
+
self.path ? LOCALHOST : self.host
|
53
|
+
rescue => e
|
54
|
+
NewRelic::Agent.logger.debug "Failed to retrieve Redis host: #{e}"
|
55
|
+
UNKNOWN
|
56
|
+
end
|
57
|
+
|
58
|
+
def _nr_port_path_or_id
|
59
|
+
self.path || self.port
|
60
|
+
rescue => e
|
61
|
+
NewRelic::Agent.logger.debug "Failed to retrieve Redis port_path_or_id: #{e}"
|
62
|
+
UNKNOWN
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
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
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module NewRelic::Agent::Instrumentation
|
7
|
+
module Redis
|
8
|
+
module Prepend
|
9
|
+
include NewRelic::Agent::Instrumentation::Redis
|
10
|
+
|
11
|
+
def call *args, &block
|
12
|
+
call_with_tracing(args[0]) { super }
|
13
|
+
end
|
14
|
+
|
15
|
+
def call_pipeline *args, &block
|
16
|
+
call_pipeline_with_tracing(args[0]) { super }
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect *args, &block
|
20
|
+
connect_with_tracing { super }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -2,6 +2,10 @@
|
|
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
|
+
require_relative 'resque/instrumentation'
|
6
|
+
require_relative 'resque/chain'
|
7
|
+
require_relative 'resque/prepend'
|
8
|
+
|
5
9
|
DependencyDetection.defer do
|
6
10
|
@name = :resque
|
7
11
|
|
@@ -9,6 +13,11 @@ DependencyDetection.defer do
|
|
9
13
|
defined?(::Resque::Job) && !NewRelic::Agent.config[:disable_resque]
|
10
14
|
end
|
11
15
|
|
16
|
+
# Airbrake uses method chaining on Resque::Job on versions < 11.0.3
|
17
|
+
conflicts_with_prepend do
|
18
|
+
defined?(::Airbrake) && defined?(::Airbrake::AIRBRAKE_VERSION) && ::Gem::Version.create(::Airbrake::AIRBRAKE_VERSION) < ::Gem::Version.create('11.0.3')
|
19
|
+
end
|
20
|
+
|
12
21
|
executes do
|
13
22
|
::NewRelic::Agent.logger.info 'Installing Resque instrumentation'
|
14
23
|
end
|
@@ -22,37 +31,13 @@ DependencyDetection.defer do
|
|
22
31
|
end
|
23
32
|
|
24
33
|
executes do
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
alias_method :perform_without_instrumentation, :perform
|
30
|
-
|
31
|
-
def perform
|
32
|
-
begin
|
33
|
-
perform_action_with_newrelic_trace(
|
34
|
-
:name => 'perform',
|
35
|
-
:class_name => self.payload_class,
|
36
|
-
:category => 'OtherTransaction/ResqueJob') do
|
37
|
-
|
38
|
-
NewRelic::Agent::Transaction.merge_untrusted_agent_attributes(
|
39
|
-
args,
|
40
|
-
:'job.resque.args',
|
41
|
-
NewRelic::Agent::AttributeFilter::DST_NONE)
|
42
|
-
|
43
|
-
perform_without_instrumentation
|
44
|
-
end
|
45
|
-
ensure
|
46
|
-
# Stopping the event loop before flushing the pipe.
|
47
|
-
# The goal is to avoid conflict during write.
|
48
|
-
NewRelic::Agent.agent.stop_event_loop
|
49
|
-
NewRelic::Agent.agent.flush_pipe_data
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
34
|
+
if use_prepend?
|
35
|
+
prepend_instrument ::Resque::Job, NewRelic::Agent::Instrumentation::Resque::Prepend
|
36
|
+
else
|
37
|
+
chain_instrument NewRelic::Agent::Instrumentation::Resque::Chain
|
53
38
|
end
|
54
39
|
|
55
|
-
if NewRelic::
|
40
|
+
if NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job?
|
56
41
|
::Resque.before_first_fork do
|
57
42
|
NewRelic::Agent.manual_start(:dispatcher => :resque,
|
58
43
|
:sync_startup => true,
|
@@ -60,9 +45,7 @@ DependencyDetection.defer do
|
|
60
45
|
end
|
61
46
|
|
62
47
|
::Resque.before_fork do |job|
|
63
|
-
|
64
|
-
NewRelic::Agent.register_report_channel(job.object_id)
|
65
|
-
end
|
48
|
+
NewRelic::Agent.register_report_channel(job.object_id)
|
66
49
|
end
|
67
50
|
|
68
51
|
::Resque.after_fork do |job|
|
@@ -71,6 +54,12 @@ DependencyDetection.defer do
|
|
71
54
|
NewRelic::Agent.after_fork(:report_to_channel => job.object_id,
|
72
55
|
:report_instance_busy => false)
|
73
56
|
end
|
57
|
+
else
|
58
|
+
::Resque.before_first_fork do
|
59
|
+
NewRelic::Agent.manual_start(:dispatcher => :resque,
|
60
|
+
:sync_startup => true,
|
61
|
+
:start_channel_listener => false)
|
62
|
+
end
|
74
63
|
end
|
75
64
|
end
|
76
65
|
end
|
@@ -0,0 +1,22 @@
|
|
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 Chain
|
9
|
+
def self.instrument!
|
10
|
+
::Resque::Job.class_eval do
|
11
|
+
include NewRelic::Agent::Instrumentation::Resque
|
12
|
+
|
13
|
+
alias_method :perform_without_instrumentation, :perform
|
14
|
+
|
15
|
+
def perform
|
16
|
+
with_tracing { perform_without_instrumentation }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
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
|
6
|
+
module Agent
|
7
|
+
module Instrumentation
|
8
|
+
module Resque
|
9
|
+
module Helper
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def resque_fork_per_job?
|
13
|
+
ENV["FORK_PER_JOB"] != 'false' && NewRelic::LanguageSupport.can_fork?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module NewRelic::Agent::Instrumentation
|
7
|
+
module Resque
|
8
|
+
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
|
9
|
+
|
10
|
+
def with_tracing
|
11
|
+
begin
|
12
|
+
perform_action_with_newrelic_trace(
|
13
|
+
:name => 'perform',
|
14
|
+
:class_name => self.payload_class,
|
15
|
+
:category => 'OtherTransaction/ResqueJob') do
|
16
|
+
|
17
|
+
NewRelic::Agent::Transaction.merge_untrusted_agent_attributes(
|
18
|
+
args,
|
19
|
+
:'job.resque.args',
|
20
|
+
NewRelic::Agent::AttributeFilter::DST_NONE)
|
21
|
+
|
22
|
+
yield
|
23
|
+
end
|
24
|
+
ensure
|
25
|
+
# Stopping the event loop before flushing the pipe.
|
26
|
+
# The goal is to avoid conflict during write.
|
27
|
+
if NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job?
|
28
|
+
NewRelic::Agent.agent.stop_event_loop
|
29
|
+
NewRelic::Agent.agent.flush_pipe_data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -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
|