Repository: newrelic/newrelic-ruby-agent (Ruby)

Issue:
`NewRelic::Agent::Logging::DecoratingFormatter#clear_tags!` should  be public?
## Description

We're getting errors akin to the following with 9.2.2 when starting up our web server:

```
App 1254076 output: [ 2023-06-14 15:34:38.8502 1254076/0x00007fa3c128c1b8(Worker 1) utils.rb ]: *** Exception NoMethodError in Rack application object (private method
`clear_tags!' called for #<NewRelic::Agent::Logging::DecoratingFormatter:0x00007fa3c7698468 @app_name="App">) (process 1254076, thread 0x00007fa3c128
c1b8(Worker 1)):
App 1254076 output:     from /data/app/shared/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/tagged_logging.rb:95:in `clear_tags!'
App 1254076 output:     from /data/app/shared/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/tagged_logging.rb:109:in `flush'
App 1254076 output:     from /data/app/shared/bundle/ruby/3.2.0/gems/activesupport-7.0.5/lib/active_support/log_subscriber.rb:97:in `flush_all!'
App 1254076 output:     from /data/app/shared/bundle/ruby/3.2.0/gems/lograge-0.12.0/lib/lograge/rails_ext/rack/logger.rb:23:in `call_app'
```

It appears the no-op method `NewRelic::Agent::Logging::DecoratingFormatter#clear_tags!` was made private recently but it should likely be public since it appears to be public in Rails itself:

https://github.com/rails/rails/blob/01363bd7e789d07b8fcf30b5a8efe3c8ba4423ee/activesupport/lib/active_support/tagged_logging.rb#L52

## Expected Behavior

Rails should start and not error out.

## Steps to Reproduce

In our case, we use tagged logging and lograge and it comes up during app boot. 

## Your Environment

- Ruby 3.2.2
- Rails 7.0.5
- Agent 9.2.2



Discussion:
https://issues.newrelic.com/browse/NEWRELIC-9337
Thank you for bringing this to our attention @dark-panda. I've created a PR for this and the fix will be included in our next release.



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 697135f47a..c9b8a1d6c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
 
 ## dev
 
-Version <dev> of the agent adds the ability to filter logs by level, expands instrumentation for Action Cable, and provides a bugfix for Code-Level Metrics.
+Version <dev> of the agent adds the ability to filter logs by level, expands instrumentation for Action Cable,provides bugfix for Code-Level Metrics, and a bugfix for `NewRelic::Agent::Logging::DecoratingFormatter#clear_tags!` being incorrectly private.
 
 - **Feature: Filter forwarded logs based on level**
 
@@ -24,6 +24,10 @@ Version <dev> of the agent adds the ability to filter logs by level, expands ins
 
   Controllers in Rails automatically render views with names that correspond to valid routes. This means that a controller method may not have a corresponding method in the controller class. Code-Level Metrics now report on these methods and don't log false warnings. Thanks to [@jcrisp](https://github.com/jcrisp) for reporting this issue. [PR#2061](https://github.com/newrelic/newrelic-ruby-agent/pull/2061)
 
+- **Bugfix: Private method `clear_tags!` for NewRelic::Agent::Logging::DecoratingFormatter**
+
+  As part of a refactor included in a previous release of the agent, the method `NewRelic::Agent::Logging::DecoratingFormatter#clear_tags!` was incorrectly made private. This method is now public again. Thanks to [@dark-panda](https://github.com/dark-panda) for reporting this issue. [PR#](https://github.com/newrelic/newrelic-ruby-agent/pull/2078)
+
 ## v9.2.2
 
   Version 9.2.2 of the agent fixes a bug with the `Transaction#finished?` method.
diff --git a/lib/new_relic/agent/logging.rb b/lib/new_relic/agent/logging.rb
index 69d58de716..d6b6bc3ed8 100644
--- a/lib/new_relic/agent/logging.rb
+++ b/lib/new_relic/agent/logging.rb
@@ -62,6 +62,10 @@ def call(severity, time, progname, msg)
           message << CLOSING_BRACE << NEWLINE
         end
 
+        def clear_tags!
+          # No-op; just avoiding issues with act-fluent-logger-rails
+        end
+
         private
 
         def add_app_name(message)
@@ -138,10 +142,6 @@ def escape(message)
           end
           message.to_json
         end
-
-        def clear_tags!
-          # No-op; just avoiding issues with act-fluent-logger-rails
-        end
       end
 
       # This logger decorates logs with trace and entity metadata, and emits log


Test patch:
diff --git a/test/new_relic/agent/logging_test.rb b/test/new_relic/agent/logging_test.rb
index 3a12c8fcea..92f64c1379 100644
--- a/test/new_relic/agent/logging_test.rb
+++ b/test/new_relic/agent/logging_test.rb
@@ -18,6 +18,11 @@ def last_message
           JSON.load(@output.string.split("\n")[-1])
         end
 
+        def test_clear_tags_is_called_without_error
+          logger = DecoratingLogger.new(@output)
+          logger.formatter.clear_tags!
+        end
+
         def test_log_to_json
           logger = DecoratingLogger.new(@output)
           logger.info('this is a test')