newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
192 stars 140 forks source link

Add local decorating for customers using Log4j 2 with JsonTemplateLayout #1866

Closed obenkenobi closed 3 weeks ago

obenkenobi commented 3 weeks ago

Overview

Adds local decorating (i.e. NR-LINKING metadata) to log4j 2 logs using JsonTemplateLayout such as shown configured in the XML snippet below:

    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
                         <JsonTemplateLayout eventTemplateUri="classpath:JsonLayout.json"/>
        </Console>
    </Appenders>

Example log without local decorating:

{
  "@timestamp": "2024-04-18T21:08:01.250Z",
  "log.level": "INFO",
  "process.thread.name": "http-nio-8081-exec-1",
  "log.logger": "org.springframework.samples.petclinic.system.WelcomeController",
  "message": "info bar"
}

Example log with local decorating:

{
  "@timestamp": "2024-04-18T21:08:01.250Z",
  "log.level": "INFO",
  "process.thread.name": "http-nio-8081-exec-1",
  "log.logger": "org.springframework.samples.petclinic.system.WelcomeController",
  "message": "info bar NR-LINKING|MzQ3Nzg3NHxBUE18QVBQTElDQVRJT058NTM4Mzc3ODY0|192.168.0.31|e0a726b1de7a78af9e74bfb042845180|3f4885dca4f83070|Petclinic+Log4j+Jsontemplatelayout+decorating|"
}

Related Github Issue

#1730

codecov-commenter commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 0% with 27 lines in your changes are missing coverage. Please review.

Project coverage is 70.69%. Comparing base (0e3a23f) to head (0117d92). Report is 110 commits behind head on main.

Files Patch % Lines
.../com/newrelic/agent/bridge/logging/Log4jUtils.java 0.00% 27 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1866 +/- ## ============================================ - Coverage 70.88% 70.69% -0.19% + Complexity 9974 9872 -102 ============================================ Files 829 828 -1 Lines 39985 39832 -153 Branches 6058 6064 +6 ============================================ - Hits 28344 28161 -183 - Misses 8915 8947 +32 + Partials 2726 2724 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.