newrelic_rpm 6.1.0.352 → 6.6.0.358

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +34 -96
  4. data/CHANGELOG.md +139 -0
  5. data/lib/new_relic/agent/agent.rb +51 -134
  6. data/lib/new_relic/agent/commands/agent_command_router.rb +2 -21
  7. data/lib/new_relic/agent/configuration/default_source.rb +53 -41
  8. data/lib/new_relic/agent/configuration/environment_source.rb +4 -2
  9. data/lib/new_relic/agent/configuration/event_harvest_config.rb +39 -0
  10. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  11. data/lib/new_relic/agent/configuration/manager.rb +13 -1
  12. data/lib/new_relic/agent/configuration/server_source.rb +34 -1
  13. data/lib/new_relic/agent/connect/request_builder.rb +69 -0
  14. data/lib/new_relic/agent/connect/response_handler.rb +61 -0
  15. data/lib/new_relic/agent/error_collector.rb +2 -2
  16. data/lib/new_relic/agent/error_event_aggregator.rb +2 -1
  17. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  18. data/lib/new_relic/agent/event_aggregator.rb +26 -32
  19. data/lib/new_relic/agent/hostname.rb +1 -1
  20. data/lib/new_relic/agent/inbound_request_monitor.rb +2 -2
  21. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +24 -42
  22. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +46 -74
  23. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +70 -53
  24. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +168 -0
  25. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +41 -48
  26. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +4 -4
  27. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  28. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +76 -0
  29. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_cable.rb +5 -6
  30. data/lib/new_relic/agent/instrumentation/{rails5 → rails_notifications}/action_controller.rb +3 -3
  31. data/lib/new_relic/agent/instrumentation/{rails4 → rails_notifications}/action_view.rb +3 -3
  32. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  33. data/lib/new_relic/agent/new_relic_service.rb +0 -4
  34. data/lib/new_relic/agent/new_relic_service/json_marshaller.rb +0 -1
  35. data/lib/new_relic/agent/parameter_filtering.rb +18 -5
  36. data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -0
  37. data/lib/new_relic/agent/span_event_aggregator.rb +2 -5
  38. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -3
  39. data/lib/new_relic/agent/threading/thread_profile.rb +9 -23
  40. data/lib/new_relic/agent/transaction.rb +0 -2
  41. data/lib/new_relic/agent/transaction/trace.rb +3 -8
  42. data/lib/new_relic/agent/transaction/trace_builder.rb +0 -1
  43. data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
  44. data/lib/new_relic/agent/transaction_sampler.rb +1 -5
  45. data/lib/new_relic/agent/transaction_time_aggregator.rb +19 -4
  46. data/lib/new_relic/control/class_methods.rb +7 -1
  47. data/lib/new_relic/control/frameworks/{rails5.rb → rails_notifications.rb} +1 -1
  48. data/lib/new_relic/rack/browser_monitoring.rb +10 -8
  49. data/lib/new_relic/version.rb +1 -1
  50. data/lib/tasks/config.rake +1 -2
  51. data/newrelic_rpm.gemspec +2 -9
  52. data/test/agent_helper.rb +18 -5
  53. metadata +18 -51
  54. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  55. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  56. data/lib/new_relic/agent/instrumentation/active_record_4.rb +0 -42
  57. data/lib/new_relic/agent/instrumentation/active_record_5.rb +0 -41
  58. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +0 -104
  59. data/lib/new_relic/agent/instrumentation/rails4/action_controller.rb +0 -32
  60. data/lib/new_relic/agent/instrumentation/rails5/action_view.rb +0 -27
  61. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
  62. data/lib/new_relic/control/frameworks/rails6.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73929ba01fea0db2f54b9977a41dfc7b710d51f38b9d07a8f0d96e8525a8574a
4
- data.tar.gz: cb28508e22221fe2c0869a247ee9796ea9a07f595ca51679eee9fd5b75027d1a
3
+ metadata.gz: 6d39324de06656b928892edc72296e459eb2737929e20f054514c2ddc980bfb0
4
+ data.tar.gz: 3752b1d5dbcd79b38a808460c68141926ae627f0c50ec8cc6ded103285719844
5
5
  SHA512:
6
- metadata.gz: 0e8c015d61f300f5460a8c2a4e38d8baf74917529d4f17bc8218114e2a71b6b8cb9cdc520b68e301f2a6733b8026f6bf4815709374ba6c7de6fc60ec622d9775
7
- data.tar.gz: d61094c98597fe88fb0d947b9ab6ea68f450e89dc592ab29116a000f06ca2acea7958a7d130619eecad1e94b908fd201e811cd6a27e5936db65876dcaaa489cf
6
+ metadata.gz: 6f277cc9660dde4ef818de176ad156202ad1993594416882e678b31786386f547b200a96444be1a84bfa53e8385700f07b837d3c500a1e8529d2e4c5d9bbf3ab
7
+ data.tar.gz: 258bd06b3feaf43c29e8007a6d97003d2d7879b719fc818ba1a374a2167f336f1b4b4352b31d938af24afb0c917751649e62eddaaab41a7955ef55e10f56e84d
data/.gitignore CHANGED
@@ -25,4 +25,5 @@ lib/new_relic/build.rb
25
25
  .bundle
26
26
  .yardoc
27
27
  artifacts/
28
+ test/performance/log/
28
29
  test/performance/script/log/
@@ -10,15 +10,16 @@ sudo: required
10
10
 
11
11
  before_install:
12
12
  # RUBY-2072 Prevent Travis setup failure before our test even starts
13
+ - jdk_switcher use oraclejdk8
13
14
  - sudo rm -f /etc/apt/sources.list.d/travis_ci_zeromq3.list
14
15
  - gem --version
15
16
  - ./test/script/before_install/update_rubygems.sh
16
- - gem uninstall bundler -a -x
17
+ - rvm @global do gem uninstall bundler --all --executables || true
17
18
  - gem install bundler -v=1.17.3
18
19
  - ./test/script/before_install/gemstash_mirror.sh
19
- - bundle _1.17.3_ --version
20
+ - bundle --version
20
21
 
21
- install: bundle _1.17.3_ install
22
+ install: bundle install
22
23
 
23
24
  addons:
24
25
  apt:
@@ -39,16 +40,11 @@ branches:
39
40
  - dev
40
41
  - release
41
42
 
42
- notifications:
43
- webhooks: http://notifitron.herokuapp.com/
44
- on_success: always
45
- on_failure: always
46
-
47
43
  rvm:
48
44
  # Run slowest builds first to try and optimize overall cycle time.
49
- - jruby-9.1.13.0
50
- - 2.6.0
51
- - 2.5.0
45
+ - jruby-9.2.6.0
46
+ - 2.6.1
47
+ - 2.5.3
52
48
  - 2.4.2
53
49
  - 2.3.5
54
50
  - 2.2.8
@@ -66,11 +62,6 @@ env:
66
62
  - TESTOPTS="-v"
67
63
  - VERBOSE = 1
68
64
  matrix:
69
- # RUBY-1668 rails21, rails22, and rails23 are all excluded below
70
- - TYPE=UNIT ENVIRONMENT=rails21
71
- - TYPE=UNIT ENVIRONMENT=rails22
72
- - TYPE=UNIT ENVIRONMENT=rails23
73
-
74
65
  - TYPE=UNIT ENVIRONMENT=rails30
75
66
  - TYPE=UNIT ENVIRONMENT=rails31
76
67
  - TYPE=UNIT ENVIRONMENT=rails32
@@ -79,6 +70,7 @@ env:
79
70
  - TYPE=UNIT ENVIRONMENT=rails42
80
71
  - TYPE=UNIT ENVIRONMENT=rails50
81
72
  - TYPE=UNIT ENVIRONMENT=rails51
73
+ - TYPE=UNIT ENVIRONMENT=rails60
82
74
  - TYPE=UNIT ENVIRONMENT=norails
83
75
  - TYPE=FUNCTIONAL GROUP=agent
84
76
  - TYPE=FUNCTIONAL GROUP=api
@@ -97,48 +89,30 @@ matrix:
97
89
  exclude:
98
90
  # Unsupported Rails/Ruby combinations
99
91
  # 2.6
100
- - rvm: 2.6.0
101
- env: TYPE=UNIT ENVIRONMENT=rails21
102
- - rvm: 2.6.0
103
- env: TYPE=UNIT ENVIRONMENT=rails22
104
- - rvm: 2.6.0
105
- env: TYPE=UNIT ENVIRONMENT=rails23
106
- - rvm: 2.6.0
92
+ - rvm: 2.6.1
107
93
  env: TYPE=UNIT ENVIRONMENT=rails30
108
- - rvm: 2.6.0
94
+ - rvm: 2.6.1
109
95
  env: TYPE=UNIT ENVIRONMENT=rails31
110
- - rvm: 2.6.0
96
+ - rvm: 2.6.1
111
97
  env: TYPE=UNIT ENVIRONMENT=rails32
112
- - rvm: 2.6.0
98
+ - rvm: 2.6.1
113
99
  env: TYPE=UNIT ENVIRONMENT=rails40
114
- - rvm: 2.6.0
100
+ - rvm: 2.6.1
115
101
  env: TYPE=UNIT ENVIRONMENT=rails41
116
102
 
117
103
  # 2.5
118
- - rvm: 2.5.0
119
- env: TYPE=UNIT ENVIRONMENT=rails21
120
- - rvm: 2.5.0
121
- env: TYPE=UNIT ENVIRONMENT=rails22
122
- - rvm: 2.5.0
123
- env: TYPE=UNIT ENVIRONMENT=rails23
124
- - rvm: 2.5.0
104
+ - rvm: 2.5.3
125
105
  env: TYPE=UNIT ENVIRONMENT=rails30
126
- - rvm: 2.5.0
106
+ - rvm: 2.5.3
127
107
  env: TYPE=UNIT ENVIRONMENT=rails31
128
- - rvm: 2.5.0
108
+ - rvm: 2.5.3
129
109
  env: TYPE=UNIT ENVIRONMENT=rails32
130
- - rvm: 2.5.0
110
+ - rvm: 2.5.3
131
111
  env: TYPE=UNIT ENVIRONMENT=rails40
132
- - rvm: 2.5.0
112
+ - rvm: 2.5.3
133
113
  env: TYPE=UNIT ENVIRONMENT=rails41
134
114
 
135
115
  # 2.4
136
- - rvm: 2.4.2
137
- env: TYPE=UNIT ENVIRONMENT=rails21
138
- - rvm: 2.4.2
139
- env: TYPE=UNIT ENVIRONMENT=rails22
140
- - rvm: 2.4.2
141
- env: TYPE=UNIT ENVIRONMENT=rails23
142
116
  - rvm: 2.4.2
143
117
  env: TYPE=UNIT ENVIRONMENT=rails30
144
118
  - rvm: 2.4.2
@@ -149,79 +123,43 @@ matrix:
149
123
  env: TYPE=UNIT ENVIRONMENT=rails40
150
124
  - rvm: 2.4.2
151
125
  env: TYPE=UNIT ENVIRONMENT=rails41
126
+ - rvm: 2.4.2
127
+ env: TYPE=UNIT ENVIRONMENT=rails60
152
128
 
153
129
  # 2.3
154
130
  - rvm: 2.3.5
155
- env: TYPE=UNIT ENVIRONMENT=rails21
156
- - rvm: 2.3.5
157
- env: TYPE=UNIT ENVIRONMENT=rails22
158
- - rvm: 2.3.5
159
- env: TYPE=UNIT ENVIRONMENT=rails23
131
+ env: TYPE=UNIT ENVIRONMENT=rails60
160
132
 
161
133
  # 2.2
162
134
  - rvm: 2.2.8
163
- env: TYPE=UNIT ENVIRONMENT=rails21
164
- - rvm: 2.2.8
165
- env: TYPE=UNIT ENVIRONMENT=rails22
166
- - rvm: 2.2.8
167
- env: TYPE=UNIT ENVIRONMENT=rails23
135
+ env: TYPE=UNIT ENVIRONMENT=rails60
168
136
 
169
137
  # 2.1
170
- - rvm: 2.1.10
171
- env: TYPE=UNIT ENVIRONMENT=rails21
172
- - rvm: 2.1.10
173
- env: TYPE=UNIT ENVIRONMENT=rails22
174
- - rvm: 2.1.10
175
- env: TYPE=UNIT ENVIRONMENT=rails23
176
138
  - rvm: 2.1.10
177
139
  env: TYPE=UNIT ENVIRONMENT=rails50
178
140
  - rvm: 2.1.10
179
141
  env: TYPE=UNIT ENVIRONMENT=rails51
142
+ - rvm: 2.1.10
143
+ env: TYPE=UNIT ENVIRONMENT=rails60
180
144
 
181
145
  # 2.0
182
- - rvm: 2.0.0-p648
183
- env: TYPE=UNIT ENVIRONMENT=rails21
184
- - rvm: 2.0.0-p648
185
- env: TYPE=UNIT ENVIRONMENT=rails22
186
- - rvm: 2.0.0-p648
187
- env: TYPE=UNIT ENVIRONMENT=rails23
188
146
  - rvm: 2.0.0-p648
189
147
  env: TYPE=UNIT ENVIRONMENT=rails50
190
148
  - rvm: 2.0.0-p648
191
149
  env: TYPE=UNIT ENVIRONMENT=rails51
150
+ - rvm: 2.0.0-p648
151
+ env: TYPE=UNIT ENVIRONMENT=rails60
192
152
 
193
- # jruby 9.0
194
- - rvm: jruby-9.1.13.0
195
- env: TYPE=UNIT ENVIRONMENT=rails21
196
- - rvm: jruby-9.1.13.0
197
- env: TYPE=UNIT ENVIRONMENT=rails22
198
- - rvm: jruby-9.1.13.0
199
- env: TYPE=UNIT ENVIRONMENT=rails23
200
- - rvm: jruby-9.1.13.0
153
+ # jruby 9.2.6.0 (Compatible with MRI 2.5)
154
+ - rvm: jruby-9.2.6.0
201
155
  env: TYPE=UNIT ENVIRONMENT=rails30
202
- - rvm: jruby-9.1.13.0
156
+ - rvm: jruby-9.2.6.0
203
157
  env: TYPE=UNIT ENVIRONMENT=rails31
204
- - rvm: jruby-9.1.13.0
158
+ - rvm: jruby-9.2.6.0
205
159
  env: TYPE=UNIT ENVIRONMENT=rails32
206
-
207
- # Travis (and only Travis) has been throwing difficult-to-reproduce
208
- # errors in various JRuby tests. These appeared after a build image
209
- # update, and they seem to be unrelated to any agent code changes.
210
- # So, we'll allow these specific test runs to fail while we track
211
- # the issue (RUBY-1869).
212
- #
213
- allow_failures:
214
- - rvm: jruby-9.1.13.0
160
+ - rvm: jruby-9.2.6.0
215
161
  env: TYPE=UNIT ENVIRONMENT=rails40
216
- - rvm: jruby-9.1.13.0
162
+ - rvm: jruby-9.2.6.0
217
163
  env: TYPE=UNIT ENVIRONMENT=rails41
218
- - rvm: jruby-9.1.13.0
219
- env: TYPE=UNIT ENVIRONMENT=rails42
220
- - rvm: jruby-9.1.13.0
221
- env: TYPE=UNIT ENVIRONMENT=rails50
222
- - rvm: jruby-9.1.13.0
223
- env: TYPE=UNIT ENVIRONMENT=rails51
224
- - rvm: jruby-9.1.13.0
225
- env: TYPE=UNIT ENVIRONMENT=norails
226
- - rvm: jruby-9.1.13.0
227
- env: TYPE=FUNCTIONAL GROUP=background_2
164
+ - rvm: jruby-9.2.6.0
165
+ env: TYPE=UNIT ENVIRONMENT=rails60
@@ -1,5 +1,144 @@
1
1
  # New Relic Ruby Agent Release Notes #
2
2
 
3
+ ## v6.6.0
4
+
5
+ * **Bugfix for ActionCable Instrumentation**
6
+
7
+ Previous versions of the agent sometimes caused application crashes with some versions
8
+ of ActionCable. The application would exit quickly after startup with the error:
9
+ `uninitialized constant ActionCable::Engine`.
10
+
11
+ Version 6.6.0 of the agent no longer crashes in this way.
12
+
13
+
14
+ * **Handling of disabling Error Collection**
15
+
16
+ When the agent first starts, it begins collecting Error Events and Traces before
17
+ fetching configuration from New Relic. In previous versions of the agent, those
18
+ events or traces would be sent to New Relic, even if _Error Collection_ is disabled in
19
+ the application's server-side configuration.
20
+
21
+ Version 6.6.0 of the agent drops all collected Error Events and Traces if the
22
+ configuration from the server disables _Error Collection_.
23
+
24
+ ## v6.5.0
25
+
26
+ * **Change to default setting for ActiveRecord connection resolution**
27
+
28
+ Due to incompatibilities between the faster ActiveRecord connection resolution
29
+ released in v6.3.0 of the agent and other gems which patch ActiveRecord,
30
+ `backport_fast_active_record_connection_lookup` will now be set to `false` by default.
31
+ Because it results in a significant performance improvement, we recommend customers
32
+ whose environments include ActiveRecord change this setting to `true`
33
+ _unless_ they are using other gems which measure ActiveRecord performance, which may
34
+ lose functionality when combined with this setting. If unsure whether to enable
35
+ `backport_fast_active_record_connection_lookup`, we recommend enabling it in a
36
+ development environment to make sure other gems which patch ActiveRecord are still
37
+ working as expected.
38
+
39
+ * **Bugfix for ActiveStorage instrumentation error**
40
+
41
+ Version 6.4.0 of the agent introduced a bug that interfered with ActiveStorage
42
+ callbacks, resulting in the agent being unable to instrument ActiveStorage operations.
43
+ ActiveStorage segments are now correctly recorded.
44
+
45
+ * **Bugfix for ActiveRecord 4.1 and 4.2 exception logging**
46
+
47
+ Version 6.3.0 of the agent introduced a bug that prevented ActiveRecord versions 4.1
48
+ and 4.2 from logging exceptions that occurred within a database transaction. This
49
+ version of the agent restores the exception logging functionality from previous agent
50
+ versions.
51
+ Thanks to Oleksiy Kovyrin for the contribution!
52
+
53
+ ## v6.4.0
54
+
55
+ * **Custom Metadata Collection**
56
+
57
+ The agent now collects environment variables prefixed by `NEW_RELIC_METADATA_`. These
58
+ may be added to transaction events to provide context between your Kubernetes cluster
59
+ and your services. For details on the behavior, see
60
+ [this blog post](https://blog.newrelic.com/engineering/monitoring-application-performance-in-kubernetes/).
61
+
62
+ * **Bugfix for faster ActiveRecord connection resolution**
63
+
64
+ Version 6.3.0 of the agent backported the faster ActiveRecord connection resolution
65
+ from Rails 6.0 to previous versions, but the implementation caused certain other gems
66
+ which measured ActiveRecord performance to stop working. This version of the agent
67
+ changes the implementation of this performance improvement so no such conflicts occur.
68
+
69
+ * **Bugfix for Grape instrumentation error**
70
+
71
+ Previous versions of the agent would fail to install Grape instrumentation in Grape
72
+ versions 1.2.0 and up if the API being instrumented subclassed `Grape::API::Instance`
73
+ rather than `Grape::API`. A warning would also print to the newrelic_agent log:
74
+ ```
75
+ WARN : Error in Grape instrumentation
76
+ WARN : NoMethodError: undefined method `name' for nil:NilClass
77
+ ```
78
+
79
+ This version of the agent successfully installs instrumentation for subclasses
80
+ of `Grape::API::Instance`, and these log messages should no longer appear.
81
+
82
+ * **Bugfix for streaming responses**
83
+
84
+ Previous versions of the agent would attempt to insert JavaScript instrumentation into
85
+ any streaming response that did not make use of `ActionController::Live`. This resulted
86
+ in an empty, non-streamed response being sent to the client.
87
+
88
+ This version of the agent will not attempt to insert JavaScript instrumentation into
89
+ a response which includes the header `Transfer-Encoding=chunked`, which indicates a
90
+ streaming response.
91
+
92
+ This should exclude JavaScript instrumentation for all streamed responses. To include
93
+ this instrumentation manually, see
94
+ [Manually instrument via agent API](https://docs.newrelic.com/docs/agents/ruby-agent/features/new-relic-browser-ruby-agent#manual_instrumentation)
95
+ in our documentation.
96
+
97
+ ## v6.3.0
98
+
99
+ * **Official Rails 6.0 support**
100
+
101
+ This version of the agent has been verified against the Rails 6.0.0 release.
102
+
103
+ As ActiveRecord 4, 5, and 6 use the same New Relic instrumentation, the
104
+ `disable_active_record_4` and `disable_active_record_5` settings in NewRelic.yml are being
105
+ deprecated in favor of the new `disable_active_record_notifications`. This new
106
+ setting will affect the instrumentation of ActiveRecord 4, 5, and 6. The deprecated settings
107
+ will be removed in a future release.
108
+
109
+ * **Bugfix for `newrelic deployments` script**
110
+
111
+ For applications housed in the EU, the `newrelic deployments` script included with previous
112
+ versions of the agent would fail with the following message: `Deployment not recorded:
113
+ Application does not exist.` This is because the script would attempt to send the deployment
114
+ notification to the US region. The deployment script now sends deployments to the correct region.
115
+
116
+ * **Faster ActiveRecord connection resolution**
117
+
118
+ This version of the agent uses the faster ActiveRecord connection resolution that Rails 6.0 uses, even on previous versions of Rails.
119
+ Thanks to Callum Jones for the contribution!
120
+
121
+ * **Support non-ascii characters in hostnames**
122
+
123
+ Previous versions of the agent would frequently log warnings like: `log writing failed. "\xE2" from ASCII-8BIT to UTF-8` if the hostname contained a non-ascii character. This version of the agent will no longer log these warnings.
124
+ Thanks to Rafael Petry for the contribution!
125
+
126
+ ## v6.2.0
127
+
128
+ * Bugfix for superfluous `Empty JSON response` error messages
129
+
130
+ Version 6.1.0 of the agent frequently logged error messages about an empty
131
+ JSON response, when no error had occurred. These logs no longer appear.
132
+
133
+ * Bugfix for `Unable to calculate elapsed transaction time` warning messages
134
+
135
+ Ruby Agent versions 5.4 through 6.1, when running in jruby without
136
+ ObjectSpace enabled, would occasionally log a warning indicating that the
137
+ agent was unable to calculate the elapsed transaction time. When this log
138
+ statement appeared, the affected transactions would not be included in the
139
+ data displayed on the capacity analysis page. These transactions are now
140
+ correctly recorded.
141
+
3
142
  ## v6.1.0
4
143
 
5
144
  * Performance monitoring on Kubernetes
@@ -30,6 +30,8 @@ require 'new_relic/agent/utilization_data'
30
30
  require 'new_relic/environment_report'
31
31
  require 'new_relic/agent/attribute_filter'
32
32
  require 'new_relic/agent/adaptive_sampler'
33
+ require 'new_relic/agent/connect/request_builder'
34
+ require 'new_relic/agent/connect/response_handler'
33
35
 
34
36
  module NewRelic
35
37
  module Agent
@@ -57,7 +59,7 @@ module NewRelic
57
59
  @cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events)
58
60
  @distributed_trace_monitor = NewRelic::Agent::DistributedTraceMonitor.new(@events)
59
61
  @synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events)
60
- @error_collector = NewRelic::Agent::ErrorCollector.new
62
+ @error_collector = NewRelic::Agent::ErrorCollector.new @events
61
63
  @transaction_rules = NewRelic::Agent::RulesEngine.new
62
64
  @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
63
65
  @monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new
@@ -68,13 +70,12 @@ module NewRelic
68
70
  @harvester = NewRelic::Agent::Harvester.new(@events)
69
71
  @after_fork_lock = Mutex.new
70
72
 
71
- @transaction_event_recorder = NewRelic::Agent::TransactionEventRecorder.new
72
- @custom_event_aggregator = NewRelic::Agent::CustomEventAggregator.new
73
- @span_event_aggregator = NewRelic::Agent::SpanEventAggregator.new
73
+ @transaction_event_recorder = NewRelic::Agent::TransactionEventRecorder.new @events
74
+ @custom_event_aggregator = NewRelic::Agent::CustomEventAggregator.new @events
75
+ @span_event_aggregator = NewRelic::Agent::SpanEventAggregator.new @events
74
76
 
75
77
  @connect_state = :pending
76
78
  @connect_attempts = 0
77
- @environment_report = nil
78
79
  @waited_on_connect = nil
79
80
  @connected_pid = nil
80
81
 
@@ -87,7 +88,7 @@ module NewRelic
87
88
  def setup_attribute_filter
88
89
  refresh_attribute_filter
89
90
 
90
- @events.subscribe(:finished_configuring) do
91
+ @events.subscribe(:initial_configuration_complete) do
91
92
  refresh_attribute_filter
92
93
  end
93
94
  end
@@ -136,7 +137,7 @@ module NewRelic
136
137
  # Transaction and metric renaming rules as provided by the
137
138
  # collector on connect. The former are applied during txns,
138
139
  # the latter during harvest.
139
- attr_reader :transaction_rules
140
+ attr_accessor :transaction_rules
140
141
  # Responsbile for restarting the harvest thread
141
142
  attr_reader :harvester
142
143
  # GC::Profiler.total_time is not monotonic so we wrap it.
@@ -155,6 +156,10 @@ module NewRelic
155
156
  @transaction_event_recorder.synthetics_event_aggregator
156
157
  end
157
158
 
159
+ def agent_id=(agent_id)
160
+ @service.agent_id = agent_id
161
+ end
162
+
158
163
  # This method should be called in a forked process after a fork.
159
164
  # It assumes the parent process initialized the agent, but does
160
165
  # not assume the agent started.
@@ -476,7 +481,6 @@ module NewRelic
476
481
  @harvester.mark_started
477
482
 
478
483
  unless in_resque_child_process?
479
- generate_environment_report
480
484
  install_exit_handler
481
485
  @harvest_samplers.load_samplers unless Agent.config[:disable_samplers]
482
486
  end
@@ -527,7 +531,7 @@ module NewRelic
527
531
  check_config_and_start_agent
528
532
  log_version_and_pid
529
533
 
530
- events.subscribe(:finished_configuring) do
534
+ events.subscribe(:initial_configuration_complete) do
531
535
  log_ignore_url_regexes
532
536
  end
533
537
  end
@@ -571,24 +575,6 @@ module NewRelic
571
575
  EventLoop.new
572
576
  end
573
577
 
574
- # Never allow any data type to be reported more frequently than once
575
- # per second.
576
- MIN_ALLOWED_REPORT_PERIOD = 1.0
577
-
578
- def report_period_for(method)
579
- config_key = "data_report_periods.#{method}".to_sym
580
- period = Agent.config[config_key]
581
- if !period
582
- period = Agent.config[:data_report_period]
583
- ::NewRelic::Agent.logger.warn("Could not find configured period for #{method}, falling back to data_report_period (#{period} s)")
584
- end
585
- if period < MIN_ALLOWED_REPORT_PERIOD
586
- ::NewRelic::Agent.logger.warn("Configured #{config_key} was #{period}, but minimum allowed is #{MIN_ALLOWED_REPORT_PERIOD}, using #{MIN_ALLOWED_REPORT_PERIOD}.")
587
- period = MIN_ALLOWED_REPORT_PERIOD
588
- end
589
- period
590
- end
591
-
592
578
  LOG_ONCE_KEYS_RESET_PERIOD = 60.0
593
579
 
594
580
  def create_and_run_event_loop
@@ -603,7 +589,7 @@ module NewRelic
603
589
  ::NewRelic::Agent.logger.clear_already_logged
604
590
  end
605
591
  @event_loop.fire_every(Agent.config[:data_report_period], :report_data)
606
- @event_loop.fire_every(report_period_for(:analytic_event_data), :report_event_data)
592
+ @event_loop.fire_every(Agent.config[:event_report_period], :report_event_data)
607
593
  @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
608
594
 
609
595
  @event_loop.run
@@ -768,10 +754,6 @@ module NewRelic
768
754
  shutdown
769
755
  end
770
756
 
771
- def generate_environment_report
772
- @environment_report = environment_for_connect
773
- end
774
-
775
757
  # Checks whether we should send environment info, and if so,
776
758
  # returns the snapshot from the local environment.
777
759
  # Generating the EnvironmentReport has the potential to trigger
@@ -781,93 +763,49 @@ module NewRelic
781
763
  Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
782
764
  end
783
765
 
784
- # We've seen objects in the environment report (Rails.env in
785
- # particular) that can't seralize to JSON. Cope with that here and
786
- # clear out so downstream code doesn't have to check again.
787
- def sanitize_environment_report
788
- if !@service.valid_to_marshal?(@environment_report)
789
- @environment_report = []
790
- end
766
+ # Constructs and memoizes an event_harvest_config hash to be used in
767
+ # the payload sent during connect (and reconnect)
768
+ def event_harvest_config
769
+ @event_harvest_config ||= Configuration::EventHarvestConfig.from_config(Agent.config)
791
770
  end
792
771
 
793
- # Initializes the hash of settings that we send to the
794
- # server. Returns a literal hash containing the options
795
- def connect_settings
796
- sanitize_environment_report
797
-
798
- {
799
- :pid => $$,
800
- :host => local_host,
801
- :display_host => Agent.config[:'process_host.display_name'],
802
- :app_name => Agent.config.app_names,
803
- :language => 'ruby',
804
- :labels => Agent.config.parsed_labels,
805
- :agent_version => NewRelic::VERSION::STRING,
806
- :environment => @environment_report,
807
- :settings => Agent.config.to_collector_hash,
808
- :high_security => Agent.config[:high_security],
809
- :utilization => UtilizationData.new.to_collector_hash,
810
- :identifier => "ruby:#{local_host}:#{Agent.config.app_names.sort.join(',')}"
811
- }
812
- end
813
-
814
- # Returns connect data passed back from the server
772
+ # Builds the payload to send to the connect service,
773
+ # connects, then configures the agent using the response from
774
+ # the connect service
815
775
  def connect_to_server
816
- @service.connect(connect_settings)
817
- end
776
+ request_builder = ::NewRelic::Agent::Connect::RequestBuilder.new \
777
+ @service,
778
+ Agent.config,
779
+ event_harvest_config
780
+ connect_response = @service.connect request_builder.connect_payload
818
781
 
819
- # apdex_f is always 4 times the apdex_t
820
- def apdex_f
821
- (4 * Agent.config[:apdex_t]).to_f
822
- end
782
+ response_handler = ::NewRelic::Agent::Connect::ResponseHandler.new(self, Agent.config)
783
+ response_handler.configure_agent(connect_response)
823
784
 
824
- # Sets the collector host and connects to the server, then
825
- # invokes the final configuration with the returned data
826
- def query_server_for_configuration
827
- finish_setup(connect_to_server)
785
+ log_connection connect_response if connect_response
786
+ connect_response
828
787
  end
829
788
 
830
- # Takes a hash of configuration data returned from the
831
- # server and uses it to set local variables and to
832
- # initialize various parts of the agent that are configured
833
- # separately.
834
- #
835
- # Can accommodate most arbitrary data - anything extra is
836
- # ignored unless we say to do something with it here.
837
- def finish_setup(config_data)
838
- return if config_data == nil
839
-
840
- @service.agent_id = config_data['agent_run_id']
841
-
842
- security_policies = config_data.delete('security_policies')
843
-
844
- add_server_side_config(config_data)
845
- add_security_policy_config(security_policies) if security_policies
846
-
847
- log_connection!(config_data)
848
- @transaction_rules = RulesEngine.create_transaction_rules(config_data)
849
- @stats_engine.metric_rules = RulesEngine.create_metric_rules(config_data)
850
-
851
- # If you're adding something else here to respond to the server-side config,
852
- # use Agent.instance.events.subscribe(:finished_configuring) callback instead!
789
+ # Logs when we connect to the server, for debugging purposes
790
+ # - makes sure we know if an agent has not connected
791
+ def log_connection(config_data)
792
+ ::NewRelic::Agent.logger.debug "Connected to NewRelic Service at #{@service.collector.name}"
793
+ ::NewRelic::Agent.logger.debug "Agent Run = #{@service.agent_id}."
794
+ ::NewRelic::Agent.logger.debug "Connection data = #{config_data.inspect}"
795
+ if config_data['messages'] && config_data['messages'].any?
796
+ log_collector_messages(config_data['messages'])
797
+ end
853
798
  end
854
799
 
855
- def add_server_side_config(config_data)
856
- if config_data['agent_config']
857
- ::NewRelic::Agent.logger.debug "Using config from server"
800
+ def log_collector_messages(messages)
801
+ messages.each do |message|
802
+ ::NewRelic::Agent.logger.send(message['level'].downcase, message['message'])
858
803
  end
859
-
860
- ::NewRelic::Agent.logger.debug "Server provided config: #{config_data.inspect}"
861
- server_config = NewRelic::Agent::Configuration::ServerSource.new(config_data, Agent.config)
862
- Agent.config.replace_or_add_config(server_config)
863
804
  end
864
805
 
865
- def add_security_policy_config(security_policies)
866
- ::NewRelic::Agent.logger.info 'Installing security policies'
867
- security_policy_source = NewRelic::Agent::Configuration::SecurityPolicySource.new(security_policies)
868
- Agent.config.replace_or_add_config(security_policy_source)
869
- # drop data collected before applying security policies
870
- drop_buffered_data
806
+ # apdex_f is always 4 times the apdex_t
807
+ def apdex_f
808
+ (4 * Agent.config[:apdex_t]).to_f
871
809
  end
872
810
 
873
811
  class WaitOnConnectTimeout < StandardError
@@ -899,22 +837,6 @@ module NewRelic
899
837
  end
900
838
  end
901
839
 
902
- # Logs when we connect to the server, for debugging purposes
903
- # - makes sure we know if an agent has not connected
904
- def log_connection!(config_data)
905
- ::NewRelic::Agent.logger.debug "Connected to NewRelic Service at #{@service.collector.name}"
906
- ::NewRelic::Agent.logger.debug "Agent Run = #{@service.agent_id}."
907
- ::NewRelic::Agent.logger.debug "Connection data = #{config_data.inspect}"
908
- if config_data['messages'] && config_data['messages'].any?
909
- log_collector_messages(config_data['messages'])
910
- end
911
- end
912
-
913
- def log_collector_messages(messages)
914
- messages.each do |message|
915
- ::NewRelic::Agent.logger.send(message['level'].downcase, message['message'])
916
- end
917
- end
918
840
  end
919
841
  include Connect
920
842
 
@@ -974,7 +896,7 @@ module NewRelic
974
896
  return unless should_connect?(opts[:force_reconnect])
975
897
 
976
898
  ::NewRelic::Agent.logger.debug "Connecting Process to New Relic: #$0"
977
- query_server_for_configuration
899
+ connect_to_server
978
900
  @connected_pid = $$
979
901
  @connect_state = :connected
980
902
  signal_connected
@@ -998,15 +920,6 @@ module NewRelic
998
920
  raise
999
921
  end
1000
922
 
1001
- # Who am I? Well, this method can tell you your hostname.
1002
- def determine_host
1003
- NewRelic::Agent::Hostname.get
1004
- end
1005
-
1006
- def local_host
1007
- @local_host ||= determine_host
1008
- end
1009
-
1010
923
  # Delegates to the control class to determine the root
1011
924
  # directory of this project
1012
925
  def determine_home_directory
@@ -1107,7 +1020,10 @@ module NewRelic
1107
1020
  harvest_and_send_from_container(transaction_event_aggregator, :analytic_event_data)
1108
1021
  harvest_and_send_from_container(synthetics_event_aggregator, :analytic_event_data)
1109
1022
  harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1110
- harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1023
+ end
1024
+
1025
+ def harvest_and_send_span_event_data
1026
+ harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1111
1027
  end
1112
1028
 
1113
1029
  def harvest_and_send_error_event_data
@@ -1167,6 +1083,7 @@ module NewRelic
1167
1083
  harvest_and_send_transaction_traces
1168
1084
  harvest_and_send_slowest_sql
1169
1085
  harvest_and_send_timeslice_data
1086
+ harvest_and_send_span_event_data
1170
1087
 
1171
1088
  check_for_and_handle_agent_commands
1172
1089
  harvest_and_send_for_agent_commands