From b458fd26a6706dcce08c0b71ca0279b40179b4dc Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 20 Nov 2024 13:34:21 -0800 Subject: [PATCH 01/16] Sync changelog with docs editor updates --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d949a61c4..c53eca0518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,11 @@ ## v9.16.0 -Version 9.16.0 introduces instrumentation for the aws-sdk-lambda gem, allows users to opt-in to adding labels to logs, updates View Component instrumentation, and fixes a bug with explain plans on Rails 7.2+. +Version 9.16.0 introduces the following features and bug fixes: - **Feature: Instrumentation for aws-sdk-lambda** - If the aws-sdk-lambda gem is present and used to invoke remote AWS Lambda functions, timing and error details for the invocations will be reported to New Relic. [PR#2926](https://github.com/newrelic/newrelic-ruby-agent/pull/2926). + 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). - **Feature: Add new configuration options to attach custom tags (labels) to logs** From bb67223d7803ca6b74a7c01c7d726ed430e383bc Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:52:31 -0800 Subject: [PATCH 02/16] Map Trilogy -> MySQL (#2966) * Map Trilogy to MySQL Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ lib/new_relic/agent/database.rb | 3 +++ .../agent/instrumentation/active_record_helper.rb | 3 +++ test/new_relic/agent/database_test.rb | 7 +++++++ .../agent/instrumentation/active_record_helper_test.rb | 6 ++++++ 5 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c53eca0518..d549502914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # New Relic Ruby Agent Release Notes +## dev + +- **Feature: Add support for Trilogy database adapter** + + 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). + ## v9.16.0 Version 9.16.0 introduces the following features and bug fixes: diff --git a/lib/new_relic/agent/database.rb b/lib/new_relic/agent/database.rb index e7d9db9f40..174e364f7c 100644 --- a/lib/new_relic/agent/database.rb +++ b/lib/new_relic/agent/database.rb @@ -277,6 +277,7 @@ def append_sql(new_sql) MYSQL_PREFIX = 'mysql'.freeze MYSQL2_PREFIX = 'mysql2'.freeze SQLITE_PREFIX = 'sqlite'.freeze + TRILOGY_PREFIX = 'trilogy'.freeze def symbolized_adapter(adapter) if adapter.start_with?(POSTGRES_PREFIX) || adapter == POSTGIS_PREFIX @@ -289,6 +290,8 @@ def symbolized_adapter(adapter) :mysql2 elsif adapter.start_with?(SQLITE_PREFIX) :sqlite + elsif adapter == TRILOGY_PREFIX + :trilogy else adapter.to_sym end diff --git a/lib/new_relic/agent/instrumentation/active_record_helper.rb b/lib/new_relic/agent/instrumentation/active_record_helper.rb index 814668410c..8fa4939b56 100644 --- a/lib/new_relic/agent/instrumentation/active_record_helper.rb +++ b/lib/new_relic/agent/instrumentation/active_record_helper.rb @@ -170,6 +170,9 @@ def map_operation(raw_operation) 'sqlite3' => 'SQLite', + # https://rubygems.org/gems/trilogy + 'trilogy' => 'MySQL', + # https://rubygems.org/gems/activerecord-jdbcpostgresql-adapter 'jdbcmysql' => 'MySQL', diff --git a/test/new_relic/agent/database_test.rb b/test/new_relic/agent/database_test.rb index afac64f8a8..26179b5872 100644 --- a/test/new_relic/agent/database_test.rb +++ b/test/new_relic/agent/database_test.rb @@ -52,6 +52,13 @@ def test_adapter_from_config_string_postgis assert_equal(:postgres, statement.adapter) end + def test_adapter_from_config_trilogy + config = {:adapter => 'trilogy'} + statement = NewRelic::Agent::Database::Statement.new('some query', config) + + assert_equal(:trilogy, statement.adapter) + end + # An ActiveRecord::Result is what you get back when executing a # query using exec_query on the connection, which is what we're # doing now for explain plans in AR4 instrumentation diff --git a/test/new_relic/agent/instrumentation/active_record_helper_test.rb b/test/new_relic/agent/instrumentation/active_record_helper_test.rb index a53a559766..f524f73aa3 100644 --- a/test/new_relic/agent/instrumentation/active_record_helper_test.rb +++ b/test/new_relic/agent/instrumentation/active_record_helper_test.rb @@ -55,6 +55,12 @@ def test_product_operation_collection_for_with_product_name_from_adapter assert_equal 'Model', collection end + def test_product_operation_collection_for_with_product_name_from_adapter_trilogy + product, _operation, _collection = ActiveRecordHelper.product_operation_collection_for(nil, '', 'trilogy') + + assert_equal 'MySQL', product + end + def test_product_operation_collection_for_from_sql product, operation, collection = ActiveRecordHelper.product_operation_collection_for('invalid', 'SELECT * FROM boo', nil) From 657d95ba940330f2e95702e135e0db35dd0c8d12 Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Tue, 26 Nov 2024 16:20:44 -0800 Subject: [PATCH 03/16] Change agent status to debug not warn (#2975) * Change agent unavailable to `debug` --- lib/new_relic/agent.rb | 4 ++-- test/new_relic/agent_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/new_relic/agent.rb b/lib/new_relic/agent.rb index 888ce963ba..6bbdc4d58e 100644 --- a/lib/new_relic/agent.rb +++ b/lib/new_relic/agent.rb @@ -132,8 +132,8 @@ class SerializationError < StandardError; end def agent # :nodoc: return @agent if @agent - NewRelic::Agent.logger.warn("Agent unavailable as it hasn't been started.") - NewRelic::Agent.logger.warn(caller.join("\n")) + NewRelic::Agent.logger.debug("Agent unavailable as it hasn't been started.") + NewRelic::Agent.logger.debug(caller.join("\n")) nil end diff --git a/test/new_relic/agent_test.rb b/test/new_relic/agent_test.rb index 3bf5281dfa..adf6187f9a 100644 --- a/test/new_relic/agent_test.rb +++ b/test/new_relic/agent_test.rb @@ -123,9 +123,9 @@ def test_manual_start_kicks_dependency_check_again NewRelic::Agent.shutdown end - def test_agent_logs_warning_when_not_started + def test_agent_logs_debug_when_not_started with_unstarted_agent do - expects_logging(:warn, includes("hasn't been started")) + expects_logging(:debug, includes("hasn't been started")) NewRelic::Agent.agent end end From c842b33be425041c36a71e98397d3e7d25d6b0d5 Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:05:10 -0800 Subject: [PATCH 04/16] Change title to bugfix (#2979) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d549502914..8c59b6be7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## dev -- **Feature: Add support for Trilogy database adapter** +- **Bugfix: Add support for Trilogy database adapter** 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). From 43e462143af24fcfdb56a51e08e5fe890f07bceb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 14:55:51 -0800 Subject: [PATCH 05/16] Prerelease 9.16.1-pre (#2980) * bump version --------- Co-authored-by: newrelic-ruby-agent-bot Co-authored-by: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> --- CHANGELOG.md | 2 +- lib/new_relic/version.rb | 2 +- newrelic.yml | 50 +++++++++++++++++++--------------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c59b6be7b..49cafb0fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # New Relic Ruby Agent Release Notes -## dev +## v9.16.1 - **Bugfix: Add support for Trilogy database adapter** diff --git a/lib/new_relic/version.rb b/lib/new_relic/version.rb index 40b2e49399..5fa810af0d 100644 --- a/lib/new_relic/version.rb +++ b/lib/new_relic/version.rb @@ -7,7 +7,7 @@ module NewRelic module VERSION # :nodoc: MAJOR = 9 MINOR = 16 - TINY = 0 + TINY = 1 STRING = "#{MAJOR}.#{MINOR}.#{TINY}" end diff --git a/newrelic.yml b/newrelic.yml index 954b0cd781..68a0cdd1c4 100644 --- a/newrelic.yml +++ b/newrelic.yml @@ -205,9 +205,8 @@ common: &default_settings # monitoring scripts. For now, auto-injection only works with Rails 5.2+. # browser_monitoring.content_security_policy_nonce: true - # Manual override for the path to your local CA bundle. This CA bundle will be - # used to validate the SSL certificate presented by New Relic's data collection - # service. + # Manual override for the path to your local CA bundle. This CA bundle validates + # the SSL certificate presented by New Relic's data collection service. # ca_bundle_path: nil # Enable or disable the capture of memcache keys from transaction traces. @@ -323,7 +322,6 @@ common: &default_settings # If true, disables agent middleware for Sinatra. This middleware is responsible # for advanced feature support such as cross application tracing, page load # timing, and error collection. - # # disable_sinatra_auto_middleware: false # If true, disables view instrumentation. @@ -723,8 +721,8 @@ common: &default_settings # If true, the agent will operate in a streamlined mode suitable for use with # short-lived serverless functions. NOTE: Only AWS Lambda functions are - # supported currently and this option is not intended for use without New - # Relic's Ruby Lambda layer offering. + # supported currently and this option isn't intended for use without New Relic's + # Ruby Lambda layer offering. # serverless_mode.enabled: false # An array of strings that will collectively serve as a denylist for filtering @@ -803,17 +801,17 @@ common: &default_settings # not be reported to New Relic. Each string in this array will be turned into a # regular expression via # Regexp.new to permit advanced matching. For each hash pair, if either the key - # or value is matched the - # pair will not be reported. By default, no user_data is reported, so this - # option should only be used if - # the stripe.user_data.include option is being used. + # or value is matched the pair + # isn't reported. By default, no user_data is reported. Use this option only if + # the + # stripe.user_data.include option is also used. # stripe.user_data.exclude: [] # An array of strings to specify which keys inside a Stripe event's user_data # hash should be reported # to New Relic. Each string in this array will be turned into a regular # expression via Regexp.new to - # permit advanced matching. Setting the value to ["."] will report all + # enable advanced matching. Setting the value to ["."] will report all # user_data. # stripe.user_data.include: [] @@ -877,7 +875,7 @@ common: &default_settings # If true, enables the collection of explain plans in transaction traces. This # setting will also apply to explain plans in slow SQL traces if - # slow_sql.explain_enabled is not set separately. + # slow_sql.explain_enabled isn't set separately. # transaction_tracer.explain_enabled: true # Threshold (in seconds) above which the agent will collect explain plans. @@ -951,12 +949,12 @@ common: &default_settings # NOTE: All "security.*" configuration parameters are related only to the # security agent, and all other configuration parameters that may # have "security" in the name somewhere are related to the APM agent. - - # If true, the security agent is loaded (a Ruby 'require' is performed) + + # If true, the security agent loads (the agent performs a Ruby 'require') # security.agent.enabled: false # The port the application is listening on. This setting is mandatory for - # Passenger servers. Other servers are detected by default. + # Passenger servers. The agent detects other servers by default. # security.application_info.port: nil # If true, the security agent is started (the agent runs in its event loop) @@ -964,7 +962,7 @@ common: &default_settings # Defines API paths the security agent should ignore in IAST scans. Accepts an # array of regex patterns matching the URI to ignore. The regex pattern should - # provide a complete match for the URL without the endpoint. For example, + # find a complete match for the URL without the endpoint. For example, # [".*account.*"], [".*/\api\/v1\/.*?\/login"] # security.exclude_from_iast_scan.api: [] @@ -985,8 +983,8 @@ common: &default_settings # If true, disables system command injection detection in IAST scans. # security.exclude_from_iast_scan.iast_detection_category.command_injection: false - # If true, disables the detection of low-severity insecure settings (e.g., hash, - # crypto, cookie, random generators, trust boundary). + # If true, disables the detection of low-severity insecure settings. For + # example, hash, crypto, cookie, random generators, trust boundary). # security.exclude_from_iast_scan.iast_detection_category.insecure_settings: false # If true, disables file operation-related IAST detections (File Access & @@ -1015,8 +1013,8 @@ common: &default_settings # If true, disables XPATH injection detection in IAST scans. # security.exclude_from_iast_scan.iast_detection_category.xpath_injection: false - # Unique test identifier when runnning IAST in CI/CD environment to - # differentiate between different test runs, e.g., a build number. + # A unique test identifier when runnning IAST in a CI/CD environment to + # differentiate between different test runs. For example, a build number. # security.iast_test_identifier: nil # Defines the mode for the security agent to operate in. Currently only IAST is @@ -1031,20 +1029,20 @@ common: &default_settings # disables Reflected Cross-Site Scripting (RXSS) vulnerability detection. # security.scan_controllers.report_http_response_body: true - # The number of application instances for a specific entity on which IAST - # analysis is performed. + # The number of application instances for a specific entity to perform IAST + # analysis on. # security.scan_controllers.scan_instance_count: 0 - # If true, allows IAST to continuously gather trace data in the background. - # Collected data will be used by the security agent to perform an IAST scan at - # the scheduled time. + # If true, allows IAST to continuously gather trace data in the background. The + # security agent uses collected data to perform an IAST scan at the scheduled + # time. # security.scan_schedule.always_sample_traces: false # Specifies the delay time (in minutes) before the IAST scan begins after the # application starts. # security.scan_schedule.delay: 0 - # Specifies the length of time (in minutes) that the IAST scan will run. + # Indicates the duration (in minutes) for which the IAST scan will be performed. # security.scan_schedule.duration: 0 # Specifies a cron expression that sets when the IAST scan should run. From 8032ce4b30c1b4c79950af14a4a4c876b801683e Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:06:20 -0800 Subject: [PATCH 06/16] Use `debug` level logs for when DT is disabled (#2984) * Use debug logs for when DT is disabled --- lib/new_relic/agent/distributed_tracing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/new_relic/agent/distributed_tracing.rb b/lib/new_relic/agent/distributed_tracing.rb index f0110e67a1..d49aabe68b 100644 --- a/lib/new_relic/agent/distributed_tracing.rb +++ b/lib/new_relic/agent/distributed_tracing.rb @@ -45,7 +45,7 @@ def insert_distributed_trace_headers(headers = {}) record_api_supportability_metric(:insert_distributed_trace_headers) unless Agent.config[:'distributed_tracing.enabled'] - NewRelic::Agent.logger.warn('Not configured to insert distributed trace headers') + NewRelic::Agent.logger.debug('Not configured to insert distributed trace headers') return nil end @@ -99,7 +99,7 @@ def accept_distributed_trace_headers(headers, transport_type = NewRelic::HTTP) record_api_supportability_metric(:accept_distributed_trace_headers) unless Agent.config[:'distributed_tracing.enabled'] - NewRelic::Agent.logger.warn('Not configured to accept distributed trace headers') + NewRelic::Agent.logger.debug('Not configured to accept distributed trace headers') return nil end From fc26239fa38de0e2b7bbc8e7b8bd336f1371112b Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:31:24 -0800 Subject: [PATCH 07/16] Do not rename final Grape segment (#2987) * Do not rename final segment --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- CHANGELOG.md | 6 ++++ .../instrumentation/grape/instrumentation.rb | 3 -- test/multiverse/suites/grape/grape_test.rb | 33 +++++-------------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49cafb0fbf..ce0c9a1b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # New Relic Ruby Agent Release Notes +## dev + +- **Bugfix: Stop renaming final Grape segment** + + 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). + ## v9.16.1 - **Bugfix: Add support for Trilogy database adapter** diff --git a/lib/new_relic/agent/instrumentation/grape/instrumentation.rb b/lib/new_relic/agent/instrumentation/grape/instrumentation.rb index 6d05c8db09..85c3e296dc 100644 --- a/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/grape/instrumentation.rb @@ -56,10 +56,7 @@ def handle_transaction(endpoint, class_name, version) def name_transaction(route, class_name, version) txn_name = name_for_transaction(route, class_name, version) - segment_name = "Middleware/Grape/#{class_name}/call" NewRelic::Agent::Transaction.set_default_transaction_name(txn_name, :grape) - txn = NewRelic::Agent::Transaction.tl_current - txn.segments.last.name = segment_name end def name_for_transaction(route, class_name, version) diff --git a/test/multiverse/suites/grape/grape_test.rb b/test/multiverse/suites/grape/grape_test.rb index db0d3c3cf3..c7c15dec03 100644 --- a/test/multiverse/suites/grape/grape_test.rb +++ b/test/multiverse/suites/grape/grape_test.rb @@ -36,38 +36,38 @@ def test_route_raises_an_error expected_txn_name = 'Controller/Grape/GrapeTestApi/self_destruct (GET)' - assert_grape_metrics(expected_txn_name) + assert_metrics_recorded(expected_txn_name) assert_metrics_recorded(["Errors/#{expected_txn_name}"]) end def test_getting_a_list_of_grape_apes get('/grape_ape') - assert_grape_metrics('Controller/Grape/GrapeTestApi/grape_ape (GET)') + assert_metrics_recorded('Controller/Grape/GrapeTestApi/grape_ape (GET)') end def test_showing_a_grape_ape get('/grape_ape/1') - assert_grape_metrics('Controller/Grape/GrapeTestApi/grape_ape/:id (GET)') + assert_metrics_recorded('Controller/Grape/GrapeTestApi/grape_ape/:id (GET)') end def test_creating_a_grape_ape post('/grape_ape', {}) - assert_grape_metrics('Controller/Grape/GrapeTestApi/grape_ape (POST)') + assert_metrics_recorded('Controller/Grape/GrapeTestApi/grape_ape (POST)') end def test_updating_a_grape_ape put('/grape_ape/1', {}) - assert_grape_metrics('Controller/Grape/GrapeTestApi/grape_ape/:id (PUT)') + assert_metrics_recorded('Controller/Grape/GrapeTestApi/grape_ape/:id (PUT)') end def test_deleting_a_grape_ape delete('/grape_ape/1') - assert_grape_metrics('Controller/Grape/GrapeTestApi/grape_ape/:id (DELETE)') + assert_metrics_recorded('Controller/Grape/GrapeTestApi/grape_ape/:id (DELETE)') end def test_transaction_renaming @@ -81,7 +81,7 @@ def test_transaction_renaming # internal representation of the name and category of a transaction as # truly separate entities. # - assert_grape_metrics('Controller/Rack/RenamedTxn') + assert_metrics_recorded('Controller/Rack/RenamedTxn') end def test_params_are_not_captured_with_capture_params_disabled @@ -259,16 +259,6 @@ def test_distinct_routes_make_for_distinct_txn_names assert_equal paths.size, names.uniq.size, 'Expected there to be one unique transaction name per unique full route path' end - - def assert_grape_metrics(expected_txn_name) - expected_node_name = 'Middleware/Grape/GrapeTestApi/call' - - assert_metrics_recorded([ - expected_node_name, - [expected_node_name, expected_txn_name], - expected_txn_name - ]) - end end end @@ -286,14 +276,7 @@ def app def test_subclass_of_grape_api_instance get('/banjaxing') - expected_node_name = 'Middleware/Grape/GrapeApiInstanceTestApi/call' - expected_txn_name = 'Controller/Grape/GrapeApiInstanceTestApi/banjaxing (GET)' - - assert_metrics_recorded([ - expected_node_name, - [expected_node_name, expected_txn_name], - expected_txn_name - ]) + assert_metrics_recorded('Controller/Grape/GrapeApiInstanceTestApi/banjaxing (GET)') end end end From 645492b90f0c04872b50c8b5813334dd27588024 Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:57:40 -0800 Subject: [PATCH 08/16] Do not attempt to decorate nil logs (#2986) * Do not attempt to decorate nil logs * Add CHANGELOG * Apply suggestions from code review Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- CHANGELOG.md | 4 ++++ lib/new_relic/agent/local_log_decorator.rb | 2 +- test/new_relic/agent/local_log_decorator_test.rb | 7 +++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce0c9a1b85..310ffab922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## dev +- **Bugfix: Do not attempt to decorate logs with `nil` messages** + + 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) + - **Bugfix: Stop renaming final Grape segment** 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). diff --git a/lib/new_relic/agent/local_log_decorator.rb b/lib/new_relic/agent/local_log_decorator.rb index e5a5abe60e..1085c788ee 100644 --- a/lib/new_relic/agent/local_log_decorator.rb +++ b/lib/new_relic/agent/local_log_decorator.rb @@ -9,7 +9,7 @@ module LocalLogDecorator extend self def decorate(message) - return message unless decorating_enabled? + return message if !decorating_enabled? || message.nil? metadata = NewRelic::Agent.linking_metadata diff --git a/test/new_relic/agent/local_log_decorator_test.rb b/test/new_relic/agent/local_log_decorator_test.rb index a3208fedd2..7a0a2c23f2 100644 --- a/test/new_relic/agent/local_log_decorator_test.rb +++ b/test/new_relic/agent/local_log_decorator_test.rb @@ -77,6 +77,13 @@ def test_decorates_if_enabled assert_equal decorated_message, "#{MESSAGE} #{METADATA_STRING}" end + def test_does_not_decorate_if_message_is_nil + metadata_stubs + decorated_message = LocalLogDecorator.decorate(nil) + + assert_nil(decorated_message) + end + def test_decorate_puts_metadata_at_end_of_first_newline metadata_stubs message = "This is a test of the Emergency Alert System\n this is only a test...." From 80c14d5ac826617c5a83920f9ebc59f71d9dee9d Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Mon, 9 Dec 2024 10:14:33 -0800 Subject: [PATCH 09/16] Add Rails 8.0 to accepted framework versions Previously, a log message stating "Detected untested Rails version 8.*" would be emitted. This is incorrect, as we are now testing the agent against Rails 8.0 --- lib/new_relic/agent/configuration/default_source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/configuration/default_source.rb b/lib/new_relic/agent/configuration/default_source.rb index 4bc5e3eee7..9fdcb20b2f 100644 --- a/lib/new_relic/agent/configuration/default_source.rb +++ b/lib/new_relic/agent/configuration/default_source.rb @@ -139,7 +139,7 @@ def self.framework case Rails::VERSION::MAJOR when 3 :rails3 - when 4..7 + when 4..8 :rails_notifications else ::NewRelic::Agent.logger.warn("Detected untested Rails version #{Rails::VERSION::STRING}") From 146898b6ff55ff4915be83080a33db60bde67577 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 10:22:42 -0800 Subject: [PATCH 10/16] Fix relative link in config description The link pointed to a config option that has since been renamed to allowed classes, instead of a list of regex-matched messages --- lib/new_relic/agent/configuration/default_source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/new_relic/agent/configuration/default_source.rb b/lib/new_relic/agent/configuration/default_source.rb index 9fdcb20b2f..efc3ecc21b 100644 --- a/lib/new_relic/agent/configuration/default_source.rb +++ b/lib/new_relic/agent/configuration/default_source.rb @@ -2177,7 +2177,7 @@ def self.notify :public => true, :type => Boolean, :allowed_from_server => false, - :description => 'If true, the agent strips messages from all exceptions except those in the [allowlist](#strip_exception_messages-allowlist). Enabled automatically in [high security mode](/docs/accounts-partnerships/accounts/security/high-security).' + :description => 'If true, the agent strips messages from all exceptions except those in the [allowed classes list](#strip_exception_messages-allowed_classes). Enabled automatically in [high security mode](/docs/accounts-partnerships/accounts/security/high-security).' }, :'strip_exception_messages.allowed_classes' => { :default => '', From 584011562f31858749e828672594d4fc78eb5e32 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 11:17:11 -0800 Subject: [PATCH 11/16] Add backtrace line 0 to 3.4 ERB failure logs Ruby 3.4 no longer provides the line number in the exception message for the error raised by a failure to parse ERB in the newrelic.yml file. To help our customers with debugging, add the line number to the output by printing the first line of the backtrace for the exception to the agent logs Resolves #2902 --- lib/new_relic/agent/configuration/yaml_source.rb | 5 ++++- test/multiverse/suites/config_file_loading/Envfile | 11 +++-------- .../config_file_loading/config_file_loading_test.rb | 5 ----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/new_relic/agent/configuration/yaml_source.rb b/lib/new_relic/agent/configuration/yaml_source.rb index f076dd1409..574d29ef83 100644 --- a/lib/new_relic/agent/configuration/yaml_source.rb +++ b/lib/new_relic/agent/configuration/yaml_source.rb @@ -99,7 +99,10 @@ def process_erb(file) file.gsub!(/^\s*#.*$/, '#') ERB.new(file).result(binding) rescue ScriptError, StandardError => e - log_failure('Failed ERB processing configuration file. This is typically caused by a Ruby error in <% %> templating blocks in your newrelic.yml file.', e) + message = 'Failed ERB processing configuration file. This is typically caused by a Ruby error in <% %> templating blocks in your newrelic.yml file.' + failure_array = [message, e] + failure_array << e.backtrace[0] if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0') + log_failure(*failure_array) nil end end diff --git a/test/multiverse/suites/config_file_loading/Envfile b/test/multiverse/suites/config_file_loading/Envfile index c90f1707e8..4fa471b889 100644 --- a/test/multiverse/suites/config_file_loading/Envfile +++ b/test/multiverse/suites/config_file_loading/Envfile @@ -4,15 +4,10 @@ omit_collector! -# TODO: RUBY 3.4 -# The CI has a prism-related error when it tries to run this suite -# The problem may be a bug fixed in future preview releases -# Disable ths suite for now, and try again when the next version -# is out. PSYCH_VERSIONS = [ - [nil, 2.4, 3.3], - ['4.0.0', 2.4, 3.3], - ['3.3.0', 2.4, 3.3] + [nil], + ['4.0.0'], + ['3.3.0'] ] def stringio_version diff --git a/test/multiverse/suites/config_file_loading/config_file_loading_test.rb b/test/multiverse/suites/config_file_loading/config_file_loading_test.rb index 953427bea7..77f1f3d689 100644 --- a/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +++ b/test/multiverse/suites/config_file_loading/config_file_loading_test.rb @@ -158,10 +158,6 @@ def test_warning_logged_when_config_file_yaml_parsing_error assert_log_contains(log, /ERROR.*Failed to read or parse configuration file at config\/newrelic\.yml/) end - # TODO: RUBY 3.4 SUPPORT - # Both error class and output have changes in Ruby 3.4 - # See Issue: https://github.com/newrelic/newrelic-ruby-agent/issues/2902 - unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0') def test_warning_logged_when_config_file_erb_error path = File.join(@cwd, 'config', 'newrelic.yml') setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4 @@ -172,7 +168,6 @@ def test_warning_logged_when_config_file_erb_error assert_log_contains(log, /ERROR.*Failed ERB processing/) assert_log_contains(log, /\(erb\):4/) end - end def test_exclude_commented_out_erb_lines config_contents = <<~YAML From 45b3bd05ab0d0a0eb71be74d3d5588cdb3bbf54a Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 11:19:50 -0800 Subject: [PATCH 12/16] Rubocop --- .../config_file_loading_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/multiverse/suites/config_file_loading/config_file_loading_test.rb b/test/multiverse/suites/config_file_loading/config_file_loading_test.rb index 77f1f3d689..15b18c5cd2 100644 --- a/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +++ b/test/multiverse/suites/config_file_loading/config_file_loading_test.rb @@ -158,16 +158,16 @@ def test_warning_logged_when_config_file_yaml_parsing_error assert_log_contains(log, /ERROR.*Failed to read or parse configuration file at config\/newrelic\.yml/) end - def test_warning_logged_when_config_file_erb_error - path = File.join(@cwd, 'config', 'newrelic.yml') - setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4 - setup_agent + def test_warning_logged_when_config_file_erb_error + path = File.join(@cwd, 'config', 'newrelic.yml') + setup_config(path, {}, "\n\n\n<%= this is not ruby %>") # the error is on line 4 + setup_agent - log = with_array_logger { NewRelic::Agent.manual_start } + log = with_array_logger { NewRelic::Agent.manual_start } - assert_log_contains(log, /ERROR.*Failed ERB processing/) - assert_log_contains(log, /\(erb\):4/) - end + assert_log_contains(log, /ERROR.*Failed ERB processing/) + assert_log_contains(log, /\(erb\):4/) + end def test_exclude_commented_out_erb_lines config_contents = <<~YAML From 834d0f2a055b08c8d97fe4058994afbc853a3307 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 11:33:28 -0800 Subject: [PATCH 13/16] Limit Psych versions Ruby 3.4 --- test/multiverse/suites/config_file_loading/Envfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/multiverse/suites/config_file_loading/Envfile b/test/multiverse/suites/config_file_loading/Envfile index 4fa471b889..c574be42d6 100644 --- a/test/multiverse/suites/config_file_loading/Envfile +++ b/test/multiverse/suites/config_file_loading/Envfile @@ -6,13 +6,13 @@ omit_collector! PSYCH_VERSIONS = [ [nil], - ['4.0.0'], - ['3.3.0'] + ['4.0.0', 2.4, 3.3], + ['3.3.0', 2.4, 3.3] ] def stringio_version if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4') - "gem 'stringio', '3.1.2.dev'" + "gem 'stringio', '~> 3.1.2'" else "gem 'stringio'" end From 76f72fcc8227991382e6a9bada8a968ea1040084 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 11:55:37 -0800 Subject: [PATCH 14/16] Set date dependency version --- test/multiverse/suites/config_file_loading/Envfile | 1 + 1 file changed, 1 insertion(+) diff --git a/test/multiverse/suites/config_file_loading/Envfile b/test/multiverse/suites/config_file_loading/Envfile index c574be42d6..9613346c19 100644 --- a/test/multiverse/suites/config_file_loading/Envfile +++ b/test/multiverse/suites/config_file_loading/Envfile @@ -25,6 +25,7 @@ def gem_list(psych_version = nil) # various places. gem 'fakefs', :require => false + gem 'date', '3.4.1' if Gem::Version.new(#{psych_version}) >= Gem::Version.new('5.2.1') gem 'psych'#{psych_version} gem 'jar-dependencies', '0.4.1' if RUBY_PLATFORM == 'java' From b0186bb0f4df41ab8476fd96f6ba0a15c28a5b79 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 12:12:35 -0800 Subject: [PATCH 15/16] Set a higher min for date --- test/multiverse/suites/config_file_loading/Envfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/multiverse/suites/config_file_loading/Envfile b/test/multiverse/suites/config_file_loading/Envfile index 9613346c19..8974bf37de 100644 --- a/test/multiverse/suites/config_file_loading/Envfile +++ b/test/multiverse/suites/config_file_loading/Envfile @@ -18,14 +18,23 @@ def stringio_version end end + +def date_version + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4') + "gem 'date', '~> 3.3.4'" + else + "gem 'date'" + end +end + def gem_list(psych_version = nil) <<~RB #{stringio_version} + #{date_version} # stub file system so we can test that newrelic.yml can be loaded from # various places. gem 'fakefs', :require => false - gem 'date', '3.4.1' if Gem::Version.new(#{psych_version}) >= Gem::Version.new('5.2.1') gem 'psych'#{psych_version} gem 'jar-dependencies', '0.4.1' if RUBY_PLATFORM == 'java' From 679030da324ae6dd469998d2e4f22adc0bad4ea4 Mon Sep 17 00:00:00 2001 From: Kayla Reopelle Date: Wed, 11 Dec 2024 13:28:58 -0800 Subject: [PATCH 16/16] Turn off branch coverage --- .github/workflows/ci.yml | 2 +- .simplecov | 2 +- test/multiverse/suites/config_file_loading/Envfile | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41a061873a..839e1850b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -384,4 +384,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} resultPath: lib/coverage_results/.last_run.json failedThreshold: 93.5 - failedThresholdBranch: 50 + failedThresholdBranch: 0 diff --git a/.simplecov b/.simplecov index fc932a35bf..719c1a05b4 100644 --- a/.simplecov +++ b/.simplecov @@ -9,7 +9,7 @@ if ENV['CI'] end SimpleCov.start do - enable_coverage(:branch) + # enable_coverage(:branch) SimpleCov.root(File.join(File.dirname(__FILE__), '/lib')) track_files('**/*.rb') formatter(SimpleCov::Formatter::SimpleFormatter) if ENV['CI'] diff --git a/test/multiverse/suites/config_file_loading/Envfile b/test/multiverse/suites/config_file_loading/Envfile index 8974bf37de..d54a8f701f 100644 --- a/test/multiverse/suites/config_file_loading/Envfile +++ b/test/multiverse/suites/config_file_loading/Envfile @@ -18,7 +18,6 @@ def stringio_version end end - def date_version if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4') "gem 'date', '~> 3.3.4'"