Skip to content

Commit

Permalink
Merge branch 'dev' into firehose_instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Dec 17, 2024
2 parents 663f60f + 40f8b53 commit 19c6ef1
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
resultPath: lib/coverage_results/.last_run.json
failedThreshold: 93.5
failedThresholdBranch: 50
failedThresholdBranch: 0
2 changes: 1 addition & 1 deletion .simplecov
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# New Relic Ruby Agent Release Notes

## 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).

## v9.16.1

- **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).

## 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**

Expand Down
4 changes: 2 additions & 2 deletions lib/new_relic/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/new_relic/agent/configuration/default_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -2186,7 +2186,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 => '',
Expand Down
5 changes: 4 additions & 1 deletion lib/new_relic/agent/configuration/yaml_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/new_relic/agent/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/new_relic/agent/distributed_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/new_relic/agent/instrumentation/active_record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
3 changes: 0 additions & 3 deletions lib/new_relic/agent/instrumentation/grape/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/agent/local_log_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/new_relic/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module NewRelic
module VERSION # :nodoc:
MAJOR = 9
MINOR = 16
TINY = 0
TINY = 1

STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
end
Expand Down
50 changes: 24 additions & 26 deletions newrelic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: []

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -951,20 +949,20 @@ 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)
# security.enabled: false

# 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: []

Expand All @@ -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 &
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions test/multiverse/suites/config_file_loading/Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@

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],
[nil],
['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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,15 @@ 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
setup_agent

log = with_array_logger { NewRelic::Agent.manual_start }

assert_log_contains(log, /ERROR.*Failed ERB processing/)
assert_log_contains(log, /\(erb\):4/)
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

log = with_array_logger { NewRelic::Agent.manual_start }

assert_log_contains(log, /ERROR.*Failed ERB processing/)
assert_log_contains(log, /\(erb\):4/)
end

def test_exclude_commented_out_erb_lines
Expand Down
Loading

0 comments on commit 19c6ef1

Please sign in to comment.