newrelic_rpm 9.14.0 → 9.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +101 -5
  3. data/CONTRIBUTING.md +2 -2
  4. data/lib/boot/strap.rb +4 -3
  5. data/lib/new_relic/agent/agent.rb +4 -0
  6. data/lib/new_relic/agent/agent_helpers/connect.rb +3 -0
  7. data/lib/new_relic/agent/agent_helpers/harvest.rb +3 -0
  8. data/lib/new_relic/agent/agent_helpers/shutdown.rb +3 -0
  9. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +1 -0
  10. data/lib/new_relic/agent/agent_helpers/startup.rb +7 -0
  11. data/lib/new_relic/agent/aws.rb +6 -0
  12. data/lib/new_relic/agent/configuration/default_source.rb +258 -35
  13. data/lib/new_relic/agent/configuration/manager.rb +1 -1
  14. data/lib/new_relic/agent/configuration/yaml_source.rb +6 -1
  15. data/lib/new_relic/agent/database.rb +41 -1
  16. data/lib/new_relic/agent/distributed_tracing.rb +2 -2
  17. data/lib/new_relic/agent/health_check.rb +136 -0
  18. data/lib/new_relic/agent/instrumentation/active_record.rb +1 -8
  19. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +5 -1
  20. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +9 -16
  21. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +0 -2
  22. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +0 -2
  23. data/lib/new_relic/agent/instrumentation/async_http.rb +1 -2
  24. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/chain.rb +21 -0
  25. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/instrumentation.rb +66 -0
  26. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose/prepend.rb +15 -0
  27. data/lib/new_relic/agent/instrumentation/aws_sdk_firehose.rb +22 -0
  28. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/chain.rb +21 -0
  29. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/instrumentation.rb +91 -0
  30. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis/prepend.rb +15 -0
  31. data/lib/new_relic/agent/instrumentation/aws_sdk_kinesis.rb +22 -0
  32. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/chain.rb +33 -0
  33. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/instrumentation.rb +93 -0
  34. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda/prepend.rb +23 -0
  35. data/lib/new_relic/agent/instrumentation/aws_sdk_lambda.rb +23 -0
  36. data/lib/new_relic/agent/instrumentation/aws_sqs.rb +0 -2
  37. data/lib/new_relic/agent/instrumentation/bunny.rb +3 -4
  38. data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +0 -2
  39. data/lib/new_relic/agent/instrumentation/curb.rb +3 -4
  40. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +0 -4
  41. data/lib/new_relic/agent/instrumentation/dynamodb/instrumentation.rb +3 -4
  42. data/lib/new_relic/agent/instrumentation/dynamodb.rb +0 -2
  43. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +0 -2
  44. data/lib/new_relic/agent/instrumentation/ethon.rb +0 -4
  45. data/lib/new_relic/agent/instrumentation/fiber.rb +0 -2
  46. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +0 -3
  47. data/lib/new_relic/agent/instrumentation/grape.rb +1 -3
  48. data/lib/new_relic/agent/instrumentation/httpclient.rb +0 -1
  49. data/lib/new_relic/agent/instrumentation/httprb.rb +0 -1
  50. data/lib/new_relic/agent/instrumentation/httpx.rb +0 -4
  51. data/lib/new_relic/agent/instrumentation/logger.rb +1 -3
  52. data/lib/new_relic/agent/instrumentation/logstasher.rb +0 -2
  53. data/lib/new_relic/agent/instrumentation/memcache.rb +0 -1
  54. data/lib/new_relic/agent/instrumentation/opensearch.rb +0 -2
  55. data/lib/new_relic/agent/instrumentation/padrino.rb +3 -3
  56. data/lib/new_relic/agent/instrumentation/rake.rb +0 -1
  57. data/lib/new_relic/agent/instrumentation/rdkafka/chain.rb +2 -1
  58. data/lib/new_relic/agent/instrumentation/rdkafka/prepend.rb +2 -1
  59. data/lib/new_relic/agent/instrumentation/rdkafka.rb +0 -2
  60. data/lib/new_relic/agent/instrumentation/redis.rb +0 -1
  61. data/lib/new_relic/agent/instrumentation/resque.rb +7 -5
  62. data/lib/new_relic/agent/instrumentation/roda.rb +4 -4
  63. data/lib/new_relic/agent/instrumentation/ruby_kafka/prepend.rb +14 -4
  64. data/lib/new_relic/agent/instrumentation/ruby_kafka.rb +0 -2
  65. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +1 -1
  66. data/lib/new_relic/agent/instrumentation/sinatra.rb +3 -6
  67. data/lib/new_relic/agent/instrumentation/thread.rb +0 -2
  68. data/lib/new_relic/agent/instrumentation/tilt.rb +0 -4
  69. data/lib/new_relic/agent/instrumentation/typhoeus.rb +0 -1
  70. data/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb +11 -8
  71. data/lib/new_relic/agent/instrumentation/view_component.rb +0 -2
  72. data/lib/new_relic/agent/local_log_decorator.rb +12 -2
  73. data/lib/new_relic/agent/log_event_aggregator.rb +28 -2
  74. data/lib/new_relic/agent/new_relic_service.rb +8 -2
  75. data/lib/new_relic/agent/span_event_primitive.rb +4 -2
  76. data/lib/new_relic/agent/threading/backtrace_node.rb +10 -1
  77. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -0
  78. data/lib/new_relic/agent.rb +2 -2
  79. data/lib/new_relic/control/frameworks/rails4.rb +1 -5
  80. data/lib/new_relic/dependency_detection.rb +11 -13
  81. data/lib/new_relic/environment_report.rb +1 -5
  82. data/lib/new_relic/helper.rb +15 -0
  83. data/lib/new_relic/language_support.rb +1 -5
  84. data/lib/new_relic/version.rb +1 -1
  85. data/lib/sequel/extensions/new_relic_instrumentation.rb +1 -1
  86. data/lib/tasks/instrumentation_generator/templates/dependency_detection.tt +9 -6
  87. data/newrelic.yml +135 -54
  88. data/test/agent_helper.rb +8 -1
  89. metadata +16 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b0ade9f1a1a36e6382100a271c5e54a2c426c27b95884a15eac8d6740dcee29b
4
- data.tar.gz: 18f728d4289bfda058bd54d7d7798a33c3a43d45de83f543b86dd573ff76283e
3
+ metadata.gz: c16c3149d187e88f60c408712fa5da2209c4cac08769477b951df4dfb780e95b
4
+ data.tar.gz: d6a0c36115e0b2f9db2ceeb806435737865615dc9043b669376bab20f443dce9
5
5
  SHA512:
6
- metadata.gz: a463e150f83291e4ef1c55e23b155621694dc5cf0a709d78bf7ebd10aee7b801afaa1e76a4fd6d12858fba7806368bad7e6b5ca53bd21273f68e1f995b524edd
7
- data.tar.gz: 9d0faa058f7810ce4edff5c91a57e584e1efaea99e6d4e533b2128727b0ccc7bb61dfa87ab0a82e134bce05010c7aec5ccef9b7960f72c502e68473885492434
6
+ metadata.gz: fc16046f04498bc268cfe08839f9a98580fede0d249c87bd9000d00a8560b0a99ffb2d504f018bc4a752a2008e1339a106a8dc38e46687ed2ddbf76aef839abf
7
+ data.tar.gz: 1b704cc45064a6ccbea20474f1537379b113bdf38788d2a0f7b283e885e0d9cc54c3ea5f935a8d41a81017a416f14adec7a814351c89dbf89d6072c044fb31ff
data/CHANGELOG.md CHANGED
@@ -1,8 +1,104 @@
1
1
  # New Relic Ruby Agent Release Notes
2
2
 
3
+ ## v9.17.0
4
+
5
+ - **Feature: Support Ruby 3.4.0**
6
+
7
+ The agent now supports Ruby 3.4.0. We've made incremental changes throughout the preview stage to reach compatibility. This release includes an update to the Thread Profiler for compatibility with Ruby 3.4.0's new backtrace format. [Issue#2992](https://github.com/newrelic/newrelic-ruby-agent/issues/2992) [PR#2997](https://github.com/newrelic/newrelic-ruby-agent/pull/2997)
8
+
9
+ - **Feature: Add instrumentation for aws-sdk-firehose**
10
+
11
+ The agent now has instrumentation for the [aws-sdk-firehose](https://rubygems.org/gems/aws-sdk-firehose) gem. [PR#2973](https://github.com/newrelic/newrelic-ruby-agent/pull/2973)
12
+
13
+ - **Feature: Kubernetes APM auto-attach - new agent version precedent**
14
+
15
+ Previously, when a customer installed the Ruby agent via [Kubernetes APM auto-attach](https://docs.newrelic.com/docs/kubernetes-pixie/kubernetes-integration/installation/k8s-agent-operator/) and also had the Ruby agent listed in their `Gemfile`, the agent version in `Gemfile` would take precedence. Now, the agent version installed by auto-attach takes priority. [PR#3018](https://github.com/newrelic/newrelic-ruby-agent/pull/3018)
16
+
17
+ - **Feature: Add health checks when the agent runs within Agent Control**
18
+
19
+ When the agent is started within an [Agent Control](https://docs-preview.newrelic.com/docs/new-relic-agent-control) environment, a health check file will be created at the configured file location for every agent process. By default, this location is: '/newrelic/apm/health'. The health check files will be updated at the configured frequency, which defaults to every five seconds. [PR#2995](https://github.com/newrelic/newrelic-ruby-agent/pull/2995)
20
+
21
+ - **Feature: Add Redshift as recognized ActiveRecord adapter**
22
+
23
+ When the agent does not recognize an ActiveRecord adapter, the host, port, and database name information is not added to the datastore span. Redshift will now be treated like PostgreSQL, and the agent will save the host, port, and database name on the span. [PR#3032](https://github.com/newrelic/newrelic-ruby-agent/pull/3032)
24
+
25
+ - **Feature: Add instrumentation for aws-sdk-kinesis**
26
+
27
+ The agent now has instrumentation for the [aws-sdk-kinesis](https://rubygems.org/gems/aws-sdk-kinesis) gem. It will record message broker segments for `get_records`, `put_record`, and `put_records` operations. All other operations will record standard segments. [PR#2974](https://github.com/newrelic/newrelic-ruby-agent/pull/2974)
28
+
29
+ - **Bugfix: Stop emitting inaccurate debug-level log about deprecated configuration options**
30
+
31
+ In the previous major release, we dropped support for `disable_<library_name>` configuration options in favor of `instrumentation.<library_name>`. Previously, a DEBUG level log warning appeared whenever `disable_*` options were set to `true`, even for libraries (e.g. Action Dispatch) without equivalent `instrumentation.*` options:
32
+
33
+ >DEBUG : [DEPRECATED] configuration disable_<library_name> for <library_name> will be removed in the next major release. Use instrumentation.<library_name> with one of ["auto", "disabled", "prepend", "chain"]
34
+
35
+ This inaccurate warning has been removed. If you are disabling instrumentation using `instrumentation.<library_name>: disabled` or `NEW_RELIC_INSTRUMENTATION_<LIBRARY_NAME>=disabled`, please verify the option exists by consulting our [configuration documentation](https://docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/#instrumentation). If the option does not exist, check the ['Disabling' section](https://docs.newrelic.com/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration/#disabling) to see if there is a related option. We apologize for the confusion. [PR#3005](https://github.com/newrelic/newrelic-ruby-agent/pull/3005)
36
+
37
+ - **Bugfix: Do not attempt to decorate logs with `nil` messages**
38
+
39
+ The agent no longer attempts to add New Relic linking metadata to logs with `nil` messages. Thank you, [@arlando](https://github.com/arlando) for bringing this to our attention! [Issue#2985](https://github.com/newrelic/newrelic-ruby-agent/issues/2985) [PR#2986](https://github.com/newrelic/newrelic-ruby-agent/pull/2986)
40
+
41
+ - **Bugfix: Stop renaming final Grape segment**
42
+
43
+ Previously, the agent renamed the final segment in Grape transactions to `"Middleware/Grape/#{class_name}/call"`. This was a part of an old instrumentation pattern that is no longer relevant. Many thanks to [@seriousdev-gh](https://github.com/seriousdev-gh) for bringing this issue to our attention and along with a great reproduction and suggested fix. [PR#2987](https://github.com/newrelic/newrelic-ruby-agent/pull/2987).
44
+
45
+ ## v9.16.1
46
+
47
+ - **Bugfix: Add support for Trilogy database adapter**
48
+
49
+ The agent now fully supports Trilogy, a client library for MySQL-compatible database servers, and correctly lists MySQL as the corresponding database in the UI. [PR#2966](https://github.com/newrelic/newrelic-ruby-agent/pull/2966).
50
+
51
+ ## v9.16.0
52
+
53
+ Version 9.16.0 introduces the following features and bug fixes:
54
+
55
+ - **Feature: Instrumentation for aws-sdk-lambda**
56
+
57
+ When the aws-sdk-lambda gem is available and used to invoke remote AWS Lambda functions, the timing and error details of the invocations will be reported to New Relic. [PR#2926](https://github.com/newrelic/newrelic-ruby-agent/pull/2926).
58
+
59
+ - **Feature: Add new configuration options to attach custom tags (labels) to logs**
60
+
61
+ The Ruby agent now allows you to opt-in to adding your custom tags (labels) to agent-forwarded logs. With custom tags on logs, platform engineers can easily filter, search, and correlate log data for faster and more efficient troubleshooting, improved performance, and optimized resource utilization. [PR#2925](https://github.com/newrelic/newrelic-ruby-agent/pull/2925)
62
+
63
+ - **Feature: Update View Component instrumentation+**
64
+
65
+ The `.identifier` method will be formally exposed as part of the View Component public API. The agent will now use this method for building metric names when available, ensuring ongoing compatibility with all View Component versions. [PR#2956](https://github.com/newrelic/newrelic-ruby-agent/pull/2956)
66
+
67
+ - **Bugfix: Record explain plan traces on Rails 7.2+**
68
+
69
+ Rails 7.2 removed adapter-specific connection methods (ex. `ActiveRecord::Base.postgresql_connection`) and replaced them with `ActiveRecord::Base.with_connection`. Our explain plan feature relies on making a connection to the database to create an explain plan trace. Due to a bug in our tests, we missed this regression. Now, the agent uses the new method to fetch explain plans on Rails 7.2+. Thank you, [@gsar](https://github.com/gsar) and [@gstark](https://github.com/gstark) for bringing this to our attention! [Issue#2922](https://github.com/newrelic/newrelic-ruby-agent/issues/2922) [PR#2940](https://github.com/newrelic/newrelic-ruby-agent/pull/2940)
70
+
71
+ ## v9.15.0
72
+
73
+ Version 9.15.0 updates View Component instrumentation to use a default metric name when one is unavailable, adds a configuration option to associate the AWS account ID with the DynamoDB calls from the AWS SDK, resolves a bug in rdkafka instrumentation when using the karafka-rdkafka gem, resolves a bug in the ruby-kafka instrumentation, fixes a bug with Grape instrumentation, and addresses a bug preventing the agent from running in serverless mode in an AWS Lambda layer.
74
+
75
+ - **Feature: New configuration option cloud.aws.account_id**
76
+
77
+ A new configuration option has been added, `cloud.aws.account_id`, that will allow New Relic to provide more details about certain calls made using the AWS SDK. For example, relationships between AWS services instrumented with New Relic's CloudWatch Metric Streams will have relationships formed in the service map with APM applications. Currently, the DynamoDB instrumentation is the only instrumentation that will make use of this configuration option, but this will be used in future instrumentation as well. [PR#2904](https://github.com/newrelic/newrelic-ruby-agent/pull/2904)
78
+
79
+ - **Feature: Use default `View/component` metric name for unidentified View Components**
80
+
81
+ Previously, when a View Component metric name could not be identified, the agent would set the name as `nil`. Now, the agent defaults to using `View/component` as the metric name when one can not be identified. [PR#2907](https://github.com/newrelic/newrelic-ruby-agent/pull/2907)
82
+
83
+ - **Bugfix: Instrumentation errors when using the karafka-rdkafka gem**
84
+
85
+ Due to version differences between the rdkafka gem and karafka-rdkafka gem, the agent could encounter an error when it tried to install rdkafka instrumentation. This has now been resolved. Thank you to @krisdigital for bringing this issue to our attention. [PR#2880](https://github.com/newrelic/newrelic-ruby-agent/pull/2880)
86
+
87
+ - **Bugfix: Stop calling deprecated all_specs method to check for the presence of newrelic-grape**
88
+
89
+ In 9.14.0, we released a fix for calls to the deprecated `Bundler.rubygems.all_specs`, but the fix fell short for the agent's Grape instrumentation and deprecation warnings could still be raised. The condition has been simplified and deprecation warnings should no longer be raised. Thank you, [@excelsior](https://github.com/excelsior) for bringing this to our attention. [Issue#2885](https://github.com/newrelic/newrelic-ruby-agent/issues/2885) [PR#2906](https://github.com/newrelic/newrelic-ruby-agent/pull/2906)
90
+
91
+ - **Bugfix: Instrumentation errors when using the ruby-kafka gem**
92
+
93
+ Kafka::Consumer#each_message takes keyword arguments, while the prepended method is defined with a single splat positional argument. In Ruby >= 3.0, this signature mismatch raises an ArgumentError. Thank you [@patrickarnett](https://github.com/patrickarnett) for providing this bugfix. [PR#2915](https://github.com/newrelic/newrelic-ruby-agent/pull/2915)
94
+
95
+ - **Bugfix: Restore AWS Lambda layer operational functionality**
96
+
97
+ Version 9.14.0 of the agent introduced an optimization related to how the agent handles boolean configuration parameters which inadvertently caused the agent to stop operating properly in an AWS Lambda layer context. [Issue#2919](https://github.com/newrelic/newrelic-ruby-agent/issues/2919)[PR#2920](https://github.com/newrelic/newrelic-ruby-agent/pull/2920)
98
+
3
99
  ## v9.14.0
4
100
 
5
- Version 9.14.0 adds Apache Kafka instrumentation for the rdkafka and ruby-kafka gems, introduces a configuration-based, automatic way to add custom instrumentation method tracers, correctly captures MIME type for AcionDispatch 7.0+ requests, properly handles Boolean coercion for `newrelic.yml` configuration, fixes a JRuby bug in the configuration manager, fixes a bug related to `Bundler.rubygems.installed_specs`, and fixes a bug to make the agent compatible with ViewComponent v3.15.0+.
101
+ Version 9.14.0 adds Apache Kafka instrumentation for the rdkafka and ruby-kafka gems, introduces a configuration-based, automatic way to add custom instrumentation method tracers, correctly captures MIME type for ActionDispatch 7.0+ requests, properly handles Boolean coercion for `newrelic.yml` configuration, fixes a JRuby bug in the configuration manager, fixes a bug related to `Bundler.rubygems.installed_specs`, and fixes a bug to make the agent compatible with ViewComponent v3.15.0+.
6
102
 
7
103
  - **Feature: Add Apache Kafka instrumentation for the rdkafka and ruby-kafka gems**
8
104
 
@@ -42,13 +138,13 @@ Version 9.14.0 adds Apache Kafka instrumentation for the rdkafka and ruby-kafka
42
138
  - MyCompany::User.notify
43
139
  ```
44
140
 
45
- That configuration example uses YAML array syntax to specify both methods. Alternatively, a comma-delimited string can be used instead:
141
+ That configuration example uses YAML array syntax to specify both methods. Alternatively, you can use a comma-delimited string:
46
142
 
47
143
  ```
48
144
  automatic_custom_instrumentation_method_list: 'MyCompany::Image#render_png, MyCompany::User.notify'
49
145
  ```
50
146
 
51
- Whitespace around the comma(s) in the list is optional. When configuring the agent with a list of methods via the `NEW_RELIC_AUTOMATIC_CUSTOM_INSTRUMENTATION_METHOD_LIST` environment variable, this comma-delimited string format should be used:
147
+ Whitespace around the comma(s) in the list is optional. When configuring the agent with a list of methods via the `NEW_RELIC_AUTOMATIC_CUSTOM_INSTRUMENTATION_METHOD_LIST` environment variable, use this comma-delimited string format:
52
148
 
53
149
  ```
54
150
  export NEW_RELIC_AUTOMATIC_CUSTOM_INSTRUMENTATION_METHOD_LIST='MyCompany::Image#render_png, MyCompany::User.notify'
@@ -56,7 +152,7 @@ Version 9.14.0 adds Apache Kafka instrumentation for the rdkafka and ruby-kafka
56
152
 
57
153
  [PR#2851](https://github.com/newrelic/newrelic-ruby-agent/pull/2851)
58
154
 
59
- - **Feature: Collect just MIME type for AcionDispatch 7.0+ requests**
155
+ - **Feature: Collect just MIME type for ActionDispatch 7.0+ requests**
60
156
 
61
157
  Rails 7.0 [introduced changes](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#actiondispatch-request-content-type-now-returns-content-type-header-as-it-is) to the behavior of `ActionDispatch::Request#content_type`, adding extra request-related details the agent wasn't expecting to collect. Additionally, the agent's use of `content_type ` was triggering deprecation warnings. The agent now uses `ActionDispatch::Request#media_type` to capture the MIME type. Thanks to [@internethostage](https://github.com/internethostage) for letting us know about this change. [Issue#2500](https://github.com/newrelic/newrelic-ruby-agent/issues/2500) [PR#2855](https://github.com/newrelic/newrelic-ruby-agent/pull/2855)
62
158
 
@@ -550,7 +646,7 @@ Version 9.3.0 of the agent adds log-level filtering, adds custom attributes for
550
646
  | --------------------------- | ------- | ------------------------------------------------------ | ------ |
551
647
  | `application_logging.forwarding.log_level` | `debug` | Sets the minimum log level for events forwarded to New Relic | `debug`, `info`, `warn`, `error`, `fatal`, `unknown` |
552
648
 
553
- This setting uses [Ruby's Logger::Severity constants integer values](https://github.com/ruby/ruby/blob/master/lib/logger/severity.rb#L6-L17) to determine precedence.
649
+ This setting uses [Ruby's Logger::Severity constants integer values](https://github.com/ruby/logger/blob/113b82a06b3076b93a71cd467e1605b23afb3088/lib/logger/severity.rb#L6-L17) to determine precedence.
554
650
 
555
651
  - **Feature: Custom attributes for logs**
556
652
 
data/CONTRIBUTING.md CHANGED
@@ -184,9 +184,9 @@ New Relic hosts and moderates an online forum where customers can interact with
184
184
  New Relic employees as well as other customers to get help and share best
185
185
  practices. Like all official New Relic open source projects, there's a related
186
186
  Community topic in the New Relic Explorers Hub. You can find this project's
187
- topic/threads here:
187
+ topic/threads under the "Ruby Agent" category here:
188
188
 
189
- [Explorer's Hub](https://discuss.newrelic.com/tags/rubyagent)
189
+ [Explorer's Hub](https://forum.newrelic.com/s/category/Category__c/Default)
190
190
 
191
191
  ## And Finally...
192
192
 
data/lib/boot/strap.rb CHANGED
@@ -44,14 +44,15 @@ module NRBundlerPatch
44
44
  NR_AGENT_GEM = 'newrelic_rpm'
45
45
 
46
46
  def require(*_groups)
47
- super
48
-
49
47
  require_newrelic
48
+
49
+ super
50
50
  end
51
51
 
52
52
  def require_newrelic
53
53
  lib = File.expand_path('../..', __FILE__)
54
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
54
+ $LOAD_PATH.reject! { |path| path.include?('newrelic_rpm') }
55
+ $LOAD_PATH.unshift(lib)
55
56
  Kernel.require NR_AGENT_GEM
56
57
  end
57
58
  end
@@ -13,6 +13,7 @@ require 'new_relic/traced_thread'
13
13
  require 'new_relic/coerce'
14
14
  require 'new_relic/agent/autostart'
15
15
  require 'new_relic/agent/harvester'
16
+ require 'new_relic/agent/health_check'
16
17
  require 'new_relic/agent/hostname'
17
18
  require 'new_relic/agent/new_relic_service'
18
19
  require 'new_relic/agent/pipe_service'
@@ -88,6 +89,7 @@ module NewRelic
88
89
  end
89
90
 
90
91
  def init_components
92
+ @health_check = HealthCheck.new
91
93
  @service = NewRelicService.new
92
94
  @events = EventListener.new
93
95
  @stats_engine = StatsEngine.new
@@ -139,6 +141,8 @@ module NewRelic
139
141
  # Holds all the methods defined on NewRelic::Agent::Agent
140
142
  # instances
141
143
  module InstanceMethods
144
+ # the agent control health check file generator
145
+ attr_reader :health_check
142
146
  # the statistics engine that holds all the timeslice data
143
147
  attr_reader :stats_engine
144
148
  # the transaction sampler that handles recording transactions
@@ -68,6 +68,7 @@ module NewRelic
68
68
  def handle_license_error(error)
69
69
  ::NewRelic::Agent.logger.error(error.message,
70
70
  'Visit newrelic.com to obtain a valid license key, or to upgrade your account.')
71
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::INVALID_LICENSE_KEY)
71
72
  disconnect
72
73
  end
73
74
 
@@ -191,6 +192,7 @@ module NewRelic
191
192
  @connected_pid = $$
192
193
  @connect_state = :connected
193
194
  signal_connected
195
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::HEALTHY)
194
196
  rescue NewRelic::Agent::ForceDisconnectException => e
195
197
  handle_force_disconnect(e)
196
198
  rescue NewRelic::Agent::LicenseException => e
@@ -198,6 +200,7 @@ module NewRelic
198
200
  rescue NewRelic::Agent::UnrecoverableAgentException => e
199
201
  handle_unrecoverable_agent_error(e)
200
202
  rescue StandardError, Timeout::Error, NewRelic::Agent::ServerConnectionException => e
203
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::FAILED_TO_CONNECT)
201
204
  retry if retry_from_error?(e, opts)
202
205
  rescue Exception => e
203
206
  ::NewRelic::Agent.logger.error('Exception of unexpected type during Agent#connect():', e)
@@ -119,6 +119,7 @@ module NewRelic
119
119
  rescue UnrecoverableServerException => e
120
120
  NewRelic::Agent.logger.warn("#{endpoint} data was rejected by remote service, discarding. Error: ", e)
121
121
  rescue ServerConnectionException => e
122
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::FAILED_TO_CONNECT)
122
123
  log_remote_unavailable(endpoint, e)
123
124
  container.merge!(payload)
124
125
  rescue => e
@@ -133,9 +134,11 @@ module NewRelic
133
134
  rescue ForceRestartException, ForceDisconnectException
134
135
  raise
135
136
  rescue UnrecoverableServerException => e
137
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::FAILED_TO_CONNECT)
136
138
  NewRelic::Agent.logger.warn('get_agent_commands message was rejected by remote service, discarding. ' \
137
139
  'Error: ', e)
138
140
  rescue ServerConnectionException => e
141
+ NewRelic::Agent.health_check.update_status(NewRelic::Agent::HealthCheck::FAILED_TO_CONNECT)
139
142
  log_remote_unavailable(:get_agent_commands, e)
140
143
  rescue => e
141
144
  NewRelic::Agent.logger.info('Error during check_for_and_handle_agent_commands, will retry later: ', e)
@@ -19,6 +19,9 @@ module NewRelic
19
19
  revert_to_default_configuration
20
20
 
21
21
  @started = nil
22
+
23
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::SHUTDOWN) if NewRelic::Agent.agent.health_check.healthy?
24
+
22
25
  Control.reset
23
26
  end
24
27
 
@@ -86,6 +86,7 @@ module NewRelic
86
86
  # is the worker thread that gathers data and talks to the
87
87
  # server.
88
88
  def handle_force_disconnect(error)
89
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::FORCED_DISCONNECT)
89
90
  ::NewRelic::Agent.logger.warn('Agent received a ForceDisconnectException from the server, disconnecting. ' \
90
91
  "(#{error.message})")
91
92
  disconnect
@@ -36,6 +36,9 @@ module NewRelic
36
36
  # setting up the worker thread and the exit handler to shut
37
37
  # down the agent
38
38
  def check_config_and_start_agent
39
+ # some health statuses, such as invalid license key, are ran before
40
+ # the agent officially starts
41
+ @health_check.create_and_run_health_check_loop
39
42
  return unless monitoring? && has_correct_license_key?
40
43
  return if using_forking_dispatcher?
41
44
 
@@ -129,6 +132,7 @@ module NewRelic
129
132
  if Agent.config[:monitor_mode]
130
133
  true
131
134
  else
135
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::AGENT_DISABLED)
132
136
  ::NewRelic::Agent.logger.warn('Agent configured not to send data in this environment.')
133
137
  false
134
138
  end
@@ -140,6 +144,7 @@ module NewRelic
140
144
  if Agent.config[:license_key] && Agent.config[:license_key].length > 0
141
145
  true
142
146
  else
147
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::MISSING_LICENSE_KEY)
143
148
  ::NewRelic::Agent.logger.warn('No license key found. ' +
144
149
  'This often means your newrelic.yml file was not found, or it lacks a section for the running ' \
145
150
  "environment, '#{NewRelic::Control.instance.env}'. You may also want to try linting your newrelic.yml " \
@@ -160,6 +165,7 @@ module NewRelic
160
165
  if key.length == 40
161
166
  true
162
167
  else
168
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::INVALID_LICENSE_KEY)
163
169
  ::NewRelic::Agent.logger.error("Invalid license key: #{key}")
164
170
  false
165
171
  end
@@ -180,6 +186,7 @@ module NewRelic
180
186
  end
181
187
 
182
188
  unless app_name_configured?
189
+ NewRelic::Agent.agent.health_check.update_status(NewRelic::Agent::HealthCheck::MISSING_APP_NAME)
183
190
  NewRelic::Agent.logger.error('No application name configured.',
184
191
  'The agent cannot start without at least one. Please check your ',
185
192
  'newrelic.yml and ensure that it is valid and has at least one ',
@@ -9,12 +9,18 @@ module NewRelic
9
9
  HEX_MASK = '7fffffffff80'
10
10
 
11
11
  def self.create_arn(service, resource, region, account_id)
12
+ # if any of the values are nil, we can't create an ARN
13
+ return unless service && resource && region && account_id
14
+
12
15
  "arn:aws:#{service}:#{region}:#{account_id}:#{resource}"
13
16
  rescue => e
14
17
  NewRelic::Agent.logger.warn("Failed to create ARN: #{e}")
15
18
  end
16
19
 
17
20
  def self.get_account_id(config)
21
+ # if it is set in the agent config, use that first
22
+ return NewRelic::Agent.config[:'cloud.aws.account_id'] if NewRelic::Agent.config[:'cloud.aws.account_id']
23
+
18
24
  access_key_id = config.credentials.credentials.access_key_id if config&.credentials&.credentials&.respond_to?(:access_key_id)
19
25
  return unless access_key_id
20
26