-
Notifications
You must be signed in to change notification settings - Fork 123
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
Open
danifitz
wants to merge
39
commits into
open-telemetry:main
Choose a base branch
from
danifitz:feature/nlog-instrumentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
39 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 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
Some comments aren't visible on the classic Files Changed page.
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
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
1 change: 1 addition & 0 deletions
1
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
1 change: 1 addition & 0 deletions
1
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
73 changes: 73 additions & 0 deletions
73
...emetry.AutoInstrumentation/Instrumentations/NLog/Bridge/Integrations/LoggerIntegration.cs
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,73 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.AutoInstrumentation.CallTarget; | ||
| using OpenTelemetry.AutoInstrumentation.Logging; | ||
| #if NET | ||
| using OpenTelemetry.AutoInstrumentation.Logger; | ||
| #endif | ||
|
|
||
| namespace OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.Bridge.Integrations; | ||
|
|
||
| /// <summary> | ||
| /// NLog Logger integration that hooks into the actual logging process. | ||
| /// This integration intercepts NLog's Logger.Log method calls to automatically | ||
| /// capture log events and forward them to OpenTelemetry when the NLog bridge is enabled. | ||
| /// | ||
| /// The integration targets NLog.Logger.Log method which is the core method called | ||
| /// for all logging operations, allowing us to capture events without modifying configuration. | ||
| /// </summary> | ||
| [InstrumentMethod( | ||
| assemblyName: "NLog", | ||
| typeName: "NLog.Logger", | ||
| methodName: "Log", | ||
| returnTypeName: ClrNames.Void, | ||
| parameterTypeNames: new[] { "NLog.LogEventInfo" }, | ||
|
Comment on lines
+23
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that you need to revisit the way how you injecting bytecode.
Even when I have checked the testing application calling this method, it is failing. |
||
| minimumVersion: "4.0.0", | ||
| maximumVersion: "6.*.*", | ||
| integrationName: "NLog", | ||
| type: InstrumentationType.Log)] | ||
| public static class LoggerIntegration | ||
Kielek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| #if NET | ||
| private static readonly IOtelLogger Logger = OtelLogging.GetLogger(); | ||
| private static int _warningLogged; | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Intercepts NLog's Logger.Log method calls to capture log events. | ||
| /// This method is called before the original Log method executes, | ||
| /// allowing us to capture and forward log events to OpenTelemetry. | ||
| /// </summary> | ||
| /// <typeparam name="TTarget">The type of the logger instance.</typeparam> | ||
| /// <param name="instance">The NLog Logger instance.</param> | ||
| /// <param name="logEvent">The NLog LogEventInfo being logged.</param> | ||
| /// <returns>A CallTargetState (unused in this case).</returns> | ||
| internal static CallTargetState OnMethodBegin<TTarget>(TTarget instance, ILoggingEvent logEvent) | ||
| { | ||
| #if NET | ||
| // Check if ILogger bridge has been initialized and warn if so | ||
| // This prevents conflicts between different logging bridges | ||
| if (LoggerInitializer.IsInitializedAtLeastOnce) | ||
| { | ||
| if (Interlocked.Exchange(ref _warningLogged, 1) != default) | ||
| { | ||
| return CallTargetState.GetDefault(); | ||
| } | ||
|
|
||
| Logger.Warning("Disabling NLog bridge due to ILogger bridge initialization."); | ||
| return CallTargetState.GetDefault(); | ||
| } | ||
| #endif | ||
|
|
||
| // Only process the log event if the NLog bridge is enabled | ||
| if (Instrumentation.LogSettings.Value.EnableNLogBridge && logEvent != null) | ||
| { | ||
| // Forward the log event to OpenTelemetry using our target | ||
| OpenTelemetryNLogTarget.Instance.WriteLogEvent(logEvent); | ||
| } | ||
|
|
||
| // Return default state - we don't need to track anything between begin/end | ||
| return CallTargetState.GetDefault(); | ||
| } | ||
| } | ||
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.