Skip to content

Commit

Permalink
Merge branch 'dev' into skip_span_event_when_transaction_ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle authored Nov 17, 2021
2 parents 987369a + d589560 commit 16e42ef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

Previously, the agent was incorrectly recording span events only on transactions that should be ignored. This fix will prevent any span events from being created for transactions using newrelic_ignore, or ignored through the `rules.ignore_url_regexes` configuration option.

* **Bugfix: Scrub non-unicode characters from DecoratingLogger**

To prevent `JSON::GeneratorErrors`, the DecoratingLogger replaces non-unicode characters with the replacement character: �. Thank you Jonathan del Strother (@jdelStrother) for bringing this to our attention!

## v8.1.0

Expand Down
11 changes: 5 additions & 6 deletions lib/new_relic/agent/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DecoratingFormatter < ::Logger::Formatter
COLON = ':'.freeze
COMMA = ','.freeze
CLOSING_BRACE = '}'.freeze
REPLACEMENT_CHAR = '�'

def initialize
Agent.config.register_callback :app_name do
Expand Down Expand Up @@ -86,12 +87,10 @@ def add_key_value message, key, value
message << QUOTE << key << QUOTE << COLON << QUOTE << value << QUOTE
end

def escape message
if String === message
message.to_json
else
message.inspect.to_json
end
def escape(message)
message = message.to_s unless message.is_a?(String)
message = message.scrub(REPLACEMENT_CHAR) unless message.valid_encoding?
message.to_json
end

def clear_tags!
Expand Down
12 changes: 11 additions & 1 deletion test/new_relic/agent/logging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_constructor_arguments_shift_age
'carriage_return' => "message with a carriage return \r",
'tab' => "message with a tab \t ",
'unicode' => "message with a unicode snowman ☃ ",
'unicode_hex' => "message with a unicode snowman \u2603 "
'unicode_hex' => "message with a unicode snowman \u2603 ",
}
messages_to_escape.each do |name, message|
define_method "test_escape_message_#{name}" do
Expand All @@ -88,6 +88,16 @@ def test_constructor_arguments_shift_age
end
end

def test_to_replace_non_utf_8_chars
message = 'message with a non-unicode code '
input = "#{message} \xb3"
expectation = "#{message} #{DecoratingFormatter::REPLACEMENT_CHAR}"
logger = DecoratingLogger.new @output

logger.info input
assert_equal expectation,
last_message['message']
end

if RUBY_VERSION >= '2.4.0'
def test_constructor_arguments_level
Expand Down

0 comments on commit 16e42ef

Please sign in to comment.