-
Notifications
You must be signed in to change notification settings - Fork 129
Add NLog instrumentation for OpenTelemetry .NET Auto-Instrumentation #4371
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
Merged
Kielek
merged 89 commits into
open-telemetry:main
from
danifitz:feature/nlog-instrumentation
Dec 17, 2025
Merged
Changes from 48 commits
Commits
Show all changes
89 commits
Select commit
Hold shift + click to select a range
12b3643
Add NLog instrumentation for OpenTelemetry .NET Auto-Instrumentation
danifitz dd0eee6
Fix: https://github.com/open-telemetry/opentelemetry-dotnet-instrumen…
danifitz 1b5ee77
Fix https://github.com/open-telemetry/opentelemetry-dotnet-instrument…
danifitz 489fa3b
Fix: https://github.com/open-telemetry/opentelemetry-dotnet-instrumen…
danifitz 638a6aa
Test: https://github.com/open-telemetry/opentelemetry-dotnet-instrume…
danifitz 206be87
feat: refactor NLog instrumentation to use standard NLog Target archi…
danifitz 799ef71
refactor: remove unused NLog.Extensions.Logging from TestApplication.…
danifitz 4401757
refactor: optimize NLog target for async compatibility and performance
danifitz 0fcf644
feat: add hybrid typed layout support for NLog version compatibility
danifitz 4ffa40a
feat: implement NLog v5.3.4+ typed layouts for OpenTelemetryTarget
danifitz f6cd7d5
fix test coverage
danifitz 665fb09
fix: correct NLog bridge EmitLog method call to match OpenTelemetry SDK
danifitz 3a79c85
refactor: simplify NLog target configuration to use environment varia…
danifitz f6957e6
Removed NLog from AssemblyInfo
danifitz b078f85
feat: add NLog instrumentation with duck typing and NLog 6.x support
danifitz 4a0d5a3
Merge branch 'main' into feature/nlog-instrumentation
danifitz bf571f5
fix CHANGELOG
Kielek 16b004e
Fix build errors
Kielek e650142
commit generated file
Kielek c41f73c
Merge branch 'main' into feature/nlog-instrumentation
Kielek e66da6a
Move NLog version to test folder
Kielek 3d5aff8
cleanup solution
Kielek ad1c62f
add NLOG to dictionary
Kielek 54dd6da
typo fixes
Kielek 0602818
remove reference to NLog.Extensions.Logging
Kielek 903ab69
Update tested versions
Kielek 4702a68
Minimal assembly version set to 4.0.0
Kielek 951c355
fix sln file
Kielek 29d4251
remove reference to System.Private.Uri
Kielek 29bde76
Fix compilation for tests app
Kielek 911fbd8
Apply suggestions from code review
lachmatt 60311e1
Merge branch 'main' into feature/nlog-instrumentation
Kielek d912c7e
Merge branch 'main' into feature/nlog-instrumentation
Kielek c6b7bde
Merge branch 'main' into feature/nlog-instrumentation
Kielek fad8ea4
Fix issue occurring in VS
Kielek e3d9274
Add missing settings test case
Kielek e95e972
remove redundant lines
Kielek 62f933d
Sync implementation with available documentation
Kielek 33546ee
user facing documentation
Kielek ea3e2fb
refactor: Switch NLog integration from target injection to bytecode i…
danifitz 836f1e7
Updated NLog instrumentation README.md
danifitz 321dd11
Merge branch 'main' into feature/nlog-instrumentation
danifitz 7e5261f
fix: resolve kielek feedback about injecting trace context even when …
danifitz 57f7293
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz 879c83f
refactor(nlog): target WriteToTargets instead of Logger.Log
danifitz 1b86b0b
fix(nlog): correct log record attribute handling
danifitz ca6c3e9
test(nlog): update tests for new instrumentation approach
danifitz 38883c9
docs(nlog): update README for new architecture
danifitz 03f2c8b
refactor(nlog): remove GlobalDiagnosticsContext integration
danifitz 2cf8700
fix: remove duplicate package versions in Directory.Packages.props
danifitz bd36cab
Merge branch 'main' into feature/nlog-instrumentation
danifitz 90d51b1
fix(nlog): support .NET Framework expression tree limitations
danifitz d606872
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz e9d1a01
fix: removed duplicates from the unshipped api
danifitz 55acf76
Merge branch 'main' into feature/nlog-instrumentation
Kielek 593c11b
Fix changelog place
Kielek b50235d
generated files
Kielek ae97b8b
Bump NLog to 6.0.6
Kielek a279df6
Comments why we need more library versions in the coverage
Kielek 3b6d6bf
Merge branch 'main' into feature/nlog-instrumentation
Kielek a0ee9bc
Fix NLog trace context injection test
danifitz 0df8b51
Merge branch 'main' into feature/nlog-instrumentation
danifitz 543beb6
Add longdate to spellcheck dictionary
danifitz 56f6c88
Fix regex to handle 12-hour time format
danifitz d4559ab
Fix duplicate NET472 in NetFramework array
danifitz 7f4dd8d
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz 3a6f6be
Fix NLog trace context test regex for macOS locale
danifitz 8b371b6
Merge branch 'main' into feature/nlog-instrumentation
Kielek 30f9ff2
File based configuration
Kielek b9a4e83
cleanup test application
Kielek 9ba276d
Modern array initialization
Kielek 8a4483b
Add NLog integrations for wrapperType overload
danifitz 181e395
Remove unused IMessageTemplateParameters interface
danifitz a7a7068
Use official NLog.Extensions.Logging package
danifitz f721d8b
Fix ClrNames.Type reference and SA1518 error
danifitz 827a533
Consolidate NLog integrations from 6 files to 2
danifitz ac925b4
Merge upstream changes
danifitz 77e539c
Merge branch 'main' into feature/nlog-instrumentation
Kielek 3f46647
generated file
Kielek e0c432c
Centos SHA update
Kielek 79a7cac
Merge branch 'main' into feature/nlog-instrumentation
Kielek e0e9a38
lint check
Kielek e64e57f
Add test coverage for Logger.Log(Type wrapperType, LogEventInfo) over…
danifitz c438a70
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz 6227b53
Merge branch 'main' into feature/nlog-instrumentation
Kielek 96f15af
Fix build after merge with main
Kielek fca5534
Improve managing tests dependencies
Kielek b642ff6
Merge branch 'main' into feature/nlog-instrumentation
Kielek 34c69f4
Fig merge main issue
Kielek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ mycompanymyproductmylibrary | |
| MYSQLCONNECTOR | ||
| MYSQLDATA | ||
| NETRUNTIME | ||
| NLOG | ||
| Npgsql | ||
| NSERVICEBUS | ||
| omnisharp | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # `NLog` [logs bridge](https://opentelemetry.io/docs/specs/otel/glossary/#log-appender--bridge) | ||
|
|
||
| > [!IMPORTANT] | ||
| > NLog bridge is an experimental feature. | ||
|
|
||
| The `NLog` logs bridge is disabled by default. In order to enable it, | ||
| set `OTEL_DOTNET_AUTO_LOGS_ENABLE_NLOG_BRIDGE` to `true`. | ||
|
|
||
| Bridge is supported for `NLOG` in versions >= 5.0.0 && < 7.0.0 | ||
|
|
||
| If `NLOG` is used as a [logging provider](https://learn.microsoft.com/en-us/dotnet/core/extensions/logging-providers), | ||
| `NLOG` bridge should not be enabled, in order to reduce possibility of | ||
| duplicated logs export. | ||
|
|
||
| ## `NLog` logging events conversion | ||
|
|
||
| `NLog`'s `ILoggingEvent`s are converted to OpenTelemetry log records in | ||
| a following way: | ||
|
|
||
| - `TimeStamp` is set as a `Timestamp` | ||
| - `Level.Name` is set as a `SeverityText` | ||
| - `FormattedMessage` is set as a `Body` if it is available | ||
| - Otherwise, `Message` is set as a `Body` | ||
| - `LoggerName` is set as an `InstrumentationScope.Name` | ||
| - `GetProperties()`, apart from builtin properties prefixed with `nlog:`, `NLog.`, | ||
| are added as attributes | ||
| - `Exception` is used to populate the following properties: `exception.type`, | ||
| `exception.message`, `exception.stacktrace` | ||
| - `Level.Value` is mapped to `SeverityNumber` as outlined in the next section | ||
|
|
||
| ### `NLog` level severity mapping | ||
|
|
||
| `NLog` levels are mapped to OpenTelemetry severity types according to | ||
| following rules based on their numerical values. | ||
|
|
||
| Levels with numerical values of: | ||
|
|
||
| - Equal to `LogLevel.Fatal` is mapped to `LogRecordSeverity.Fatal` | ||
| - Equal to `LogLevel.Error` is mapped to `LogRecordSeverity.Error` | ||
| - Equal to `LogLevel.Warn` is mapped to `LogRecordSeverity.Warn` | ||
| - Equal to `LogLevel.Info` is mapped to `LogRecordSeverity.Info` | ||
| - Equal to `LogLevel.Debug` is mapped to `LogRecordSeverity.Debug` | ||
| - Equal to `LogLevel.Trace` is mapped to `LogRecordSeverity.Trace` | ||
| - Equal to `LogLevel.Off` is mapped to `LogRecordSeverity.Trace` | ||
| - Any other is mapped to `LogRecordSeverity.Info`. | ||
|
|
3 changes: 3 additions & 0 deletions
3
src/OpenTelemetry.AutoInstrumentation/.publicApi/net462/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/OpenTelemetry.AutoInstrumentation/.publicApi/net8.0/PublicAPI.Unshipped.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.