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

Update NLog to improve local log decoration coverage #1393

Merged
merged 4 commits into from
Feb 24, 2023

Conversation

jaffinito
Copy link
Member

@jaffinito jaffinito commented Feb 21, 2023

Description

Changes how the NLog instrumentation updates the log message for local log decoration.

  • Instead of examining and using LogEventInfo.Message, the new instrumentation uses LogEventInfo.FormattedMessage and its backing field, (v4.5+ _formattedMessage)|(Pre v4.5 formattedMessage). This property has additional logic that Message does not and appears to be the source for the actual log message we see. Calling FormattedMessage causes NLog to build the message and store it in the backing field.
  • Using the visibility bypasser, we get the setter for the backing field and use it to set the field to itself with our decoration token. The Action is stored staticly, same as with other bypasser setups.
  • Since we can only get the major assembly version from NLog assembly we cannot use minVersion or maxVersion. The cleanest solution was to check for _formattedMessage first since it is the going forward name and if that fails, use formattedMessage. This is done using reflection, but is will only happen once per run so the impact is minimal.

Caveats:
This does not 100% cover all the log lines. It does cover the vast majority of them.

Author Checklist

Reviewer Checklist

  • Perform code review
  • Pull request was adequately tested (new/existing tests, performance tests)
  • Review Changelog

@jaffinito jaffinito marked this pull request as ready for review February 22, 2023 00:44
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2023

Codecov Report

Merging #1393 (e7f2ffe) into main (670936f) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1393      +/-   ##
==========================================
- Coverage   71.62%   71.61%   -0.01%     
==========================================
  Files         459      459              
  Lines       30619    30619              
==========================================
- Hits        21932    21929       -3     
- Misses       8687     8690       +3     
Impacted Files Coverage Δ
src/Agent/NewRelic/Agent/Core/Time/Scheduler.cs 79.45% <0.00%> (-2.06%) ⬇️

tippmar-nr
tippmar-nr previously approved these changes Feb 22, 2023
Copy link
Member

@nrcventura nrcventura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like there are integration tests that exercise this code, but we need an item on our backlog to add the necessary assertions to validate this behavior.

@jaffinito
Copy link
Member Author

I added a story to our backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants