Skip to content

Commit

Permalink
Do not attempt to decorate nil logs (#2986)
Browse files Browse the repository at this point in the history
* Do not attempt to decorate nil logs

* Add CHANGELOG

* Apply suggestions from code review

Co-authored-by: Kayla Reopelle <[email protected]>

---------

Co-authored-by: Kayla Reopelle <[email protected]>
  • Loading branch information
hannahramadan and kaylareopelle authored Dec 7, 2024
1 parent fc26239 commit 645492b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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

0 comments on commit 645492b

Please sign in to comment.