Commit 24819c4
feat: Include structured log message arguments as context data for MEL (#3479)
* feat: Extract structured log message arguments as context data for MEL (#3470)
* feat: Extract structured log message arguments as context data for MEL
When using Microsoft.Extensions.Logging with structured logging
(e.g., logger.LogInformation("User {UserId} did {Action}", userId, action)),
the named parameters are now extracted from the TState state parameter and
merged into context data. This makes them available as individual log
attributes in New Relic (e.g., context.UserId, context.Action), matching
the behavior already available for Serilog and NLog.
The state extraction is wrapped in its own try/catch to ensure it cannot
disrupt existing scope-based context data harvesting. The {OriginalFormat}
key (the message template string) is excluded.
Fixes #2519
* test: Add integration test for MEL structured log arg context data
Adds StructuredLogArgContextDataTests that verifies structured log
message arguments (e.g., {Name}, {Id}) are extracted as context data
attributes when using Microsoft.Extensions.Logging.
- Adds InfoWithStructuredArgs to MicrosoftLoggingLoggingAdapter
- Adds CreateSingleLogMessageWithStructuredArgs to LoggingTester
- Test asserts that Name and Id appear in the log line attributes
* Fix build errors and start refactoring
* Passing integration test for MEL
* Expand tests to all relevant logging frameworks
* Refactoring conditional code
* Rename and reorder for clarity
* Refactor LoggingTester
Separate the context data handling testing from the main message logging paths
* PR feedback part 1
* Document reason for goofy message template format.
* Expand integration testing to cover the context + structured log args case
---------
Co-authored-by: piekstra <piekstra@users.noreply.github.com>1 parent 73de305 commit 24819c4
17 files changed
Lines changed: 930 additions & 330 deletions
File tree
- src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/MicrosoftExtensionsLogging
- tests/Agent/IntegrationTests
- IntegrationTests/Logging
Lines changed: 39 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
61 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
67 | 74 | | |
68 | | - | |
| 75 | + | |
69 | 76 | | |
70 | 77 | | |
71 | 78 | | |
| |||
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
109 | 145 | | |
110 | 146 | | |
111 | 147 | | |
| |||
135 | 171 | | |
136 | 172 | | |
137 | 173 | | |
138 | | - | |
| 174 | + | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 371 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
743 | 743 | | |
744 | 744 | | |
745 | 745 | | |
746 | | - | |
| 746 | + | |
0 commit comments