Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
12b3643
Add NLog instrumentation for OpenTelemetry .NET Auto-Instrumentation
danifitz Aug 6, 2025
dd0eee6
Fix: https://github.com/open-telemetry/opentelemetry-dotnet-instrumen…
danifitz Aug 11, 2025
1b5ee77
Fix https://github.com/open-telemetry/opentelemetry-dotnet-instrument…
danifitz Aug 11, 2025
489fa3b
Fix: https://github.com/open-telemetry/opentelemetry-dotnet-instrumen…
danifitz Aug 11, 2025
638a6aa
Test: https://github.com/open-telemetry/opentelemetry-dotnet-instrume…
danifitz Aug 11, 2025
206be87
feat: refactor NLog instrumentation to use standard NLog Target archi…
danifitz Aug 20, 2025
799ef71
refactor: remove unused NLog.Extensions.Logging from TestApplication.…
danifitz Aug 20, 2025
4401757
refactor: optimize NLog target for async compatibility and performance
danifitz Aug 21, 2025
0fcf644
feat: add hybrid typed layout support for NLog version compatibility
danifitz Aug 27, 2025
4ffa40a
feat: implement NLog v5.3.4+ typed layouts for OpenTelemetryTarget
danifitz Sep 10, 2025
f6cd7d5
fix test coverage
danifitz Sep 10, 2025
665fb09
fix: correct NLog bridge EmitLog method call to match OpenTelemetry SDK
danifitz Sep 10, 2025
3a79c85
refactor: simplify NLog target configuration to use environment varia…
danifitz Sep 11, 2025
f6957e6
Removed NLog from AssemblyInfo
danifitz Sep 24, 2025
b078f85
feat: add NLog instrumentation with duck typing and NLog 6.x support
danifitz Sep 24, 2025
4a0d5a3
Merge branch 'main' into feature/nlog-instrumentation
danifitz Sep 24, 2025
bf571f5
fix CHANGELOG
Kielek Sep 30, 2025
16b004e
Fix build errors
Kielek Sep 30, 2025
e650142
commit generated file
Kielek Sep 30, 2025
c41f73c
Merge branch 'main' into feature/nlog-instrumentation
Kielek Sep 30, 2025
e66da6a
Move NLog version to test folder
Kielek Sep 30, 2025
3d5aff8
cleanup solution
Kielek Sep 30, 2025
ad1c62f
add NLOG to dictionary
Kielek Sep 30, 2025
54dd6da
typo fixes
Kielek Sep 30, 2025
0602818
remove reference to NLog.Extensions.Logging
Kielek Sep 30, 2025
903ab69
Update tested versions
Kielek Sep 30, 2025
4702a68
Minimal assembly version set to 4.0.0
Kielek Sep 30, 2025
951c355
fix sln file
Kielek Sep 30, 2025
29d4251
remove reference to System.Private.Uri
Kielek Sep 30, 2025
29bde76
Fix compilation for tests app
Kielek Sep 30, 2025
911fbd8
Apply suggestions from code review
lachmatt Oct 1, 2025
60311e1
Merge branch 'main' into feature/nlog-instrumentation
Kielek Oct 1, 2025
d912c7e
Merge branch 'main' into feature/nlog-instrumentation
Kielek Oct 1, 2025
c6b7bde
Merge branch 'main' into feature/nlog-instrumentation
Kielek Oct 2, 2025
fad8ea4
Fix issue occurring in VS
Kielek Oct 2, 2025
e3d9274
Add missing settings test case
Kielek Oct 2, 2025
e95e972
remove redundant lines
Kielek Oct 2, 2025
62f933d
Sync implementation with available documentation
Kielek Oct 2, 2025
33546ee
user facing documentation
Kielek Oct 2, 2025
ea3e2fb
refactor: Switch NLog integration from target injection to bytecode i…
danifitz Nov 10, 2025
836f1e7
Updated NLog instrumentation README.md
danifitz Nov 10, 2025
321dd11
Merge branch 'main' into feature/nlog-instrumentation
danifitz Nov 18, 2025
7e5261f
fix: resolve kielek feedback about injecting trace context even when …
danifitz Nov 18, 2025
57f7293
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz Nov 18, 2025
879c83f
refactor(nlog): target WriteToTargets instead of Logger.Log
danifitz Nov 25, 2025
1b86b0b
fix(nlog): correct log record attribute handling
danifitz Nov 25, 2025
ca6c3e9
test(nlog): update tests for new instrumentation approach
danifitz Nov 25, 2025
38883c9
docs(nlog): update README for new architecture
danifitz Nov 25, 2025
03f2c8b
refactor(nlog): remove GlobalDiagnosticsContext integration
danifitz Nov 26, 2025
2cf8700
fix: remove duplicate package versions in Directory.Packages.props
danifitz Nov 26, 2025
bd36cab
Merge branch 'main' into feature/nlog-instrumentation
danifitz Nov 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.Bridge.Integrations.LoggerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteLogEventToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsLegacyIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration0
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration1
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.Bridge.Integrations.LoggerIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteLogEventToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsLegacyIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration0
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration1
OpenTelemetry.AutoInstrumentation.Instrumentations.NoCode.NoCodeIntegration2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static partial class InstrumentationDefinitions
{
private static NativeCallTargetDefinition[] GetDefinitionsArray()
{
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(40);
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(42);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
Expand Down Expand Up @@ -108,7 +108,9 @@ private static NativeCallTargetDefinition[] GetDefinitionsArray()
// NLog
if (logSettings.EnabledInstrumentations.Contains(LogInstrumentation.NLog))
{
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "Log", ["System.Void", "NLog.LogEventInfo"], 5, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.Bridge.Integrations.LoggerIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteLogEventToTargets", ["System.Void", "NLog.LogEventInfo", "NLog.Internal.ITargetWithFilterChain"], 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteLogEventToTargetsIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteToTargets", ["System.Void", "NLog.LogEventInfo", "NLog.Internal.ITargetWithFilterChain"], 5, 0, 0, 5, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteToTargets", ["System.Void", "NLog.LogEventInfo", "NLog.Internal.TargetWithFilterChain"], 5, 0, 0, 5, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.WriteToTargetsLegacyIntegration"));
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ private static BlockExpression BuildLogRecordAttributes(
// If no parameterless constructor, try to find other constructors or use default for structs
if (constructorInfo == null)
{
var constructors = logRecordAttributesListType.GetConstructors();
Logger.Debug($"LogRecordAttributeList constructors: {string.Join(", ", constructors.Select(c => $"({string.Join(", ", c.GetParameters().Select(p => p.ParameterType.Name))})"))}");
Logger.Debug($"LogRecordAttributeList IsValueType: {logRecordAttributesListType.IsValueType}");

// Try to find a constructor that takes an int (capacity)
constructorInfo = logRecordAttributesListType.GetConstructor(new[] { typeof(int) });
if (constructorInfo != null)
Expand All @@ -174,14 +170,15 @@ private static BlockExpression BuildLogRecordAttributes(
}

var addAttributeMethodInfo = logRecordAttributesListType.GetMethod("Add", new[] { typeof(string), typeof(object) })!;
var recordExceptionMethodInfo = logRecordAttributesListType.GetMethod("RecordException", BindingFlags.Instance | BindingFlags.Public)!;

var expressions = new List<Expression> { assignInstanceVar };

// Add exception as an attribute if present
var addExceptionExpression = Expression.IfThen(
// Record exception using RecordException which adds exception.type, exception.message, exception.stacktrace
var recordExceptionExpression = Expression.IfThen(
Expression.NotEqual(exception, Expression.Constant(null)),
Expression.Call(instanceVar, addAttributeMethodInfo, Expression.Constant("exception"), exception));
expressions.Add(addExceptionExpression);
Expression.Call(instanceVar, recordExceptionMethodInfo, exception));
expressions.Add(recordExceptionExpression);

// Add custom properties if present
var addPropertiesExpression = BuildAddPropertiesExpression(instanceVar, properties, addAttributeMethodInfo);
Expand Down Expand Up @@ -271,10 +268,7 @@ private static Expression BuildAddArgsExpression(ParameterExpression instanceVar
Expression.Call(
instanceVar,
addAttributeMethodInfo,
Expression.Call(
typeof(string).GetMethod("Concat", new[] { typeof(string), typeof(string) })!,
Expression.Constant("arg_"),
Expression.Call(indexVar, typeof(int).GetMethod("ToString", Type.EmptyTypes)!)),
Expression.Call(indexVar, typeof(int).GetMethod("ToString", Type.EmptyTypes)!),
Expression.ArrayIndex(argsParam, indexVar)),
Expression.Assign(indexVar, Expression.Add(indexVar, Expression.Constant(1)))),
breakLabel);
Expand Down
Loading