Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt to decorate nil logs #2986

Merged
merged 4 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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
7 changes: 7 additions & 0 deletions test/new_relic/agent/local_log_decorator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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...."
Expand Down
Loading