newrelic_rpm 6.13.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +231 -0
  4. data/CONTRIBUTING.md +13 -2
  5. data/README.md +2 -2
  6. data/lib/new_relic/agent.rb +5 -8
  7. data/lib/new_relic/agent/agent.rb +4 -5
  8. data/lib/new_relic/agent/audit_logger.rb +10 -0
  9. data/lib/new_relic/agent/autostart.rb +1 -2
  10. data/lib/new_relic/agent/configuration/default_source.rb +412 -220
  11. data/lib/new_relic/agent/configuration/manager.rb +2 -2
  12. data/lib/new_relic/agent/database_adapter.rb +33 -0
  13. data/lib/new_relic/agent/datastores/redis.rb +0 -4
  14. data/lib/new_relic/agent/distributed_tracing.rb +0 -66
  15. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +2 -2
  16. data/lib/new_relic/agent/http_clients/uri_util.rb +1 -1
  17. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +4 -5
  18. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +21 -68
  19. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
  20. data/lib/new_relic/agent/instrumentation/active_record_prepend.rb +23 -57
  21. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
  22. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +0 -15
  23. data/lib/new_relic/agent/instrumentation/bunny.rb +10 -196
  24. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  25. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
  26. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  27. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
  28. data/lib/new_relic/agent/instrumentation/curb.rb +9 -259
  29. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  30. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  31. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  32. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  33. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  34. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  35. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -84
  36. data/lib/new_relic/agent/instrumentation/excon.rb +2 -1
  37. data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
  38. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  39. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  40. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  41. data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
  42. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  43. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  44. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  45. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  46. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  47. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  48. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  49. data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
  50. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  51. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
  52. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  53. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  54. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  55. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +4 -10
  56. data/lib/new_relic/agent/instrumentation/mongo.rb +7 -0
  57. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  58. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  59. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +40 -0
  60. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  61. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +1 -1
  62. data/lib/new_relic/agent/instrumentation/padrino.rb +18 -75
  63. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  64. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  65. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  66. data/lib/new_relic/agent/instrumentation/rack.rb +29 -160
  67. data/lib/new_relic/agent/instrumentation/rack/chain.rb +57 -0
  68. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  69. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  70. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +36 -0
  71. data/lib/new_relic/agent/instrumentation/rake.rb +13 -188
  72. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  73. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  74. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  75. data/lib/new_relic/agent/instrumentation/redis.rb +12 -186
  76. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  77. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  78. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  79. data/lib/new_relic/agent/instrumentation/resque.rb +21 -32
  80. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  81. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  82. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
  83. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  84. data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -1
  85. data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -198
  86. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  87. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
  88. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
  89. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  90. data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
  91. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  92. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  93. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  94. data/lib/new_relic/agent/javascript_instrumentor.rb +12 -7
  95. data/lib/new_relic/agent/method_tracer.rb +6 -16
  96. data/lib/new_relic/agent/new_relic_service.rb +16 -13
  97. data/lib/new_relic/agent/samplers/memory_sampler.rb +1 -1
  98. data/lib/new_relic/agent/span_event_primitive.rb +10 -8
  99. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  100. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -1
  101. data/lib/new_relic/agent/transaction.rb +1 -4
  102. data/lib/new_relic/agent/transaction/abstract_segment.rb +1 -1
  103. data/lib/new_relic/agent/transaction/distributed_tracer.rb +12 -6
  104. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
  105. data/lib/new_relic/agent/vm/mri_vm.rb +6 -4
  106. data/lib/new_relic/cli/commands/deployments.rb +0 -1
  107. data/lib/new_relic/constants.rb +4 -0
  108. data/lib/new_relic/control/frameworks/rails.rb +11 -9
  109. data/lib/new_relic/control/instance_methods.rb +1 -0
  110. data/lib/new_relic/dependency_detection.rb +119 -9
  111. data/lib/new_relic/environment_report.rb +1 -7
  112. data/lib/new_relic/noticed_error.rb +1 -5
  113. data/lib/new_relic/supportability_helper.rb +3 -2
  114. data/lib/new_relic/version.rb +2 -2
  115. data/lib/tasks/config.html.erb +14 -25
  116. data/lib/tasks/config.rake +8 -7
  117. data/newrelic_rpm.gemspec +2 -2
  118. data/test/agent_helper.rb +1 -0
  119. metadata +55 -32
  120. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  121. data/.github/ISSUE_TEMPLATE/config.yml +0 -5
  122. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -24
  123. data/.github/actions/annotate/README.md +0 -79
  124. data/.github/actions/annotate/action.yml +0 -6
  125. data/.github/actions/annotate/dist/index.js +0 -433
  126. data/.github/actions/annotate/index.js +0 -25
  127. data/.github/actions/annotate/package-lock.json +0 -172
  128. data/.github/actions/annotate/package.json +0 -30
  129. data/.github/actions/annotate/pre-commit +0 -5
  130. data/.github/actions/build-ruby/README.md +0 -79
  131. data/.github/actions/build-ruby/action.yml +0 -15
  132. data/.github/actions/build-ruby/dist/index.js +0 -52683
  133. data/.github/actions/build-ruby/index.js +0 -514
  134. data/.github/actions/build-ruby/package-lock.json +0 -581
  135. data/.github/actions/build-ruby/package.json +0 -32
  136. data/.github/actions/build-ruby/pre-commit +0 -5
  137. data/.github/pull_request_template.md +0 -16
  138. data/.github/workflows/ci.yml +0 -212
  139. data/.github/workflows/pr_review_checklist.yml +0 -22
  140. data/.github/workflows/release.yml +0 -78
  141. data/.github/workflows/scripts/rubygems-authenticate.py +0 -13
  142. data/.github/workflows/scripts/rubygems-publish.rb +0 -32
  143. data/.github/workflows/snyk.yml +0 -27
  144. data/.github/workflows/stale.yml +0 -21
  145. data/cert/cacert.pem +0 -1177
  146. data/lib/new_relic/agent/instrumentation/http.rb +0 -49
  147. data/lib/new_relic/agent/instrumentation/net.rb +0 -87
@@ -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
17
+ conflicts_with_prepend do
18
+ defined?(::Airbrake)
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
- module ::Resque
26
- class Job
27
- include NewRelic::Agent::Instrumentation::ControllerInstrumentation
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::LanguageSupport.can_fork?
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
- if ENV['FORK_PER_JOB'] != 'false'
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] = distributed_tracing_headers if ::NewRelic::Agent.config[:'distributed_tracing.enabled']
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
- require 'new_relic/agent/instrumentation/controller_instrumentation'
6
- require 'new_relic/agent/instrumentation/sinatra/transaction_namer'
7
- require 'new_relic/agent/instrumentation/sinatra/ignorer'
8
- require 'new_relic/agent/parameter_filtering'
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
- @name = :sinatra
12
+ named :sinatra
12
13
 
13
- depends_on do
14
- !NewRelic::Agent.config[:disable_sinatra] &&
15
- defined?(::Sinatra) && defined?(::Sinatra::Base) &&
16
- Sinatra::Base.private_method_defined?(:dispatch!) &&
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
- ::Sinatra::Base.class_eval do
27
- include NewRelic::Agent::Instrumentation::Sinatra
28
-
29
- alias dispatch_without_newrelic dispatch!
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
- module ::Sinatra
42
- register NewRelic::Agent::Instrumentation::Sinatra::Ignorer
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
- ::Sinatra::Base.class_eval do
54
- class << self
55
- alias build_without_newrelic build
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