Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 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
90d51b1
fix(nlog): support .NET Framework expression tree limitations
danifitz Nov 27, 2025
d606872
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz Nov 28, 2025
e9d1a01
fix: removed duplicates from the unshipped api
danifitz Dec 1, 2025
55acf76
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 2, 2025
593c11b
Fix changelog place
Kielek Dec 2, 2025
b50235d
generated files
Kielek Dec 2, 2025
ae97b8b
Bump NLog to 6.0.6
Kielek Dec 2, 2025
a279df6
Comments why we need more library versions in the coverage
Kielek Dec 2, 2025
3b6d6bf
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 2, 2025
a0ee9bc
Fix NLog trace context injection test
danifitz Dec 3, 2025
0df8b51
Merge branch 'main' into feature/nlog-instrumentation
danifitz Dec 3, 2025
543beb6
Add longdate to spellcheck dictionary
danifitz Dec 3, 2025
56f6c88
Fix regex to handle 12-hour time format
danifitz Dec 3, 2025
d4559ab
Fix duplicate NET472 in NetFramework array
danifitz Dec 3, 2025
7f4dd8d
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz Dec 3, 2025
3a6f6be
Fix NLog trace context test regex for macOS locale
danifitz Dec 4, 2025
8b371b6
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 5, 2025
30f9ff2
File based configuration
Kielek Dec 5, 2025
b9a4e83
cleanup test application
Kielek Dec 5, 2025
9ba276d
Modern array initialization
Kielek Dec 5, 2025
8a4483b
Add NLog integrations for wrapperType overload
danifitz Dec 8, 2025
181e395
Remove unused IMessageTemplateParameters interface
danifitz Dec 8, 2025
a7a7068
Use official NLog.Extensions.Logging package
danifitz Dec 8, 2025
f721d8b
Fix ClrNames.Type reference and SA1518 error
danifitz Dec 8, 2025
827a533
Consolidate NLog integrations from 6 files to 2
danifitz Dec 9, 2025
ac925b4
Merge upstream changes
danifitz Dec 9, 2025
77e539c
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 9, 2025
3f46647
generated file
Kielek Dec 9, 2025
e0c432c
Centos SHA update
Kielek Dec 9, 2025
79a7cac
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 10, 2025
e0e9a38
lint check
Kielek Dec 10, 2025
e64e57f
Add test coverage for Logger.Log(Type wrapperType, LogEventInfo) over…
danifitz Dec 16, 2025
c438a70
Merge branch 'feature/nlog-instrumentation' of https://github.com/dan…
danifitz Dec 16, 2025
6227b53
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 16, 2025
96f15af
Fix build after merge with main
Kielek Dec 16, 2025
fca5534
Improve managing tests dependencies
Kielek Dec 16, 2025
b642ff6
Merge branch 'main' into feature/nlog-instrumentation
Kielek Dec 16, 2025
34c69f4
Fig merge main issue
Kielek Dec 16, 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
2 changes: 2 additions & 0 deletions .cspell/other.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ILOGGER
inetsrv
JIT
LINQ
longdate
MASSTRANSIT
metricsexporter
mkdir
Expand All @@ -41,6 +42,7 @@ mycompanymyproductmylibrary
MYSQLCONNECTOR
MYSQLDATA
NETRUNTIME
NLOG
Npgsql
NSERVICEBUS
omnisharp
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h

- Add `-NoReset` switch parameter to skip service restart in PowerShell
registration functions.
- Support for [`NLog`](https://www.nuget.org/packages/NLog/)
logs instrumentation for versions `5.*` and `6.*` on .NET using duck typing
for zero-config auto-injection.

### Changed

Expand Down
19 changes: 19 additions & 0 deletions OpenTelemetry.AutoInstrumentation.sln
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SdkVersionAnalyzer", "tools
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.Log4NetBridge", "test\test-applications\integrations\TestApplication.Log4NetBridge\TestApplication.Log4NetBridge.csproj", "{926B7C03-42C2-4192-94A7-CD0B1C693279}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.NLogBridge", "test\test-applications\integrations\TestApplication.NLogBridge\TestApplication.NLogBridge.csproj", "{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.SelectiveSampler", "test\test-applications\integrations\TestApplication.SelectiveSampler\TestApplication.SelectiveSampler.csproj", "{FD1A1ABD-6A48-4E94-B5F7-2081AFCD1BBB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApplication.ProfilerSpanStoppageHandling", "test\test-applications\integrations\TestApplication.ProfilerSpanStoppageHandling\TestApplication.ProfilerSpanStoppageHandling.csproj", "{665280EB-F428-4C04-A293-33228C73BF8A}"
Expand Down Expand Up @@ -1538,6 +1540,22 @@ Global
{926B7C03-42C2-4192-94A7-CD0B1C693279}.Release|x64.Build.0 = Release|x64
{926B7C03-42C2-4192-94A7-CD0B1C693279}.Release|x86.ActiveCfg = Release|x86
{926B7C03-42C2-4192-94A7-CD0B1C693279}.Release|x86.Build.0 = Release|x86
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|Any CPU.ActiveCfg = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|Any CPU.Build.0 = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|ARM64.ActiveCfg = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|ARM64.Build.0 = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|x64.ActiveCfg = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|x64.Build.0 = Debug|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|x86.ActiveCfg = Debug|x86
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Debug|x86.Build.0 = Debug|x86
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|Any CPU.ActiveCfg = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|Any CPU.Build.0 = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|ARM64.ActiveCfg = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|ARM64.Build.0 = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|x64.ActiveCfg = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|x64.Build.0 = Release|x64
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|x86.ActiveCfg = Release|x86
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D}.Release|x86.Build.0 = Release|x86
{FD1A1ABD-6A48-4E94-B5F7-2081AFCD1BBB}.Debug|Any CPU.ActiveCfg = Debug|x64
{FD1A1ABD-6A48-4E94-B5F7-2081AFCD1BBB}.Debug|Any CPU.Build.0 = Debug|x64
{FD1A1ABD-6A48-4E94-B5F7-2081AFCD1BBB}.Debug|ARM64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -1692,6 +1710,7 @@ Global
{AA3E0C5C-A4E2-46AB-BD18-2D30D3ABF692} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{C75FA076-D460-414B-97F7-6F8D0E85AE74} = {00F4C92D-6652-4BD8-A334-B35D3E711BE6}
{926B7C03-42C2-4192-94A7-CD0B1C693279} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{A7B8C9D0-1E2F-3A4B-5C6D-7E8F9A0B1C2D} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{FD1A1ABD-6A48-4E94-B5F7-2081AFCD1BBB} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{665280EB-F428-4C04-A293-33228C73BF8A} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
{500BF40F-EECB-4F6A-377B-EDBDFFDE09BE} = {E409ADD3-9574-465C-AB09-4324D205CC7C}
Expand Down
9 changes: 9 additions & 0 deletions build/LibraryVersions.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public static partial class LibraryVersion
new("3.2.0"),
]
},
{
"TestApplication.NLogBridge",
[
new("5.0.0", additionalMetaData: new() { { "NLogExtensionsLogging", "5.0.0" } }),
new("5.3.4", additionalMetaData: new() { { "NLogExtensionsLogging", "5.3.15" } }),
new("6.0.0", additionalMetaData: new() { { "NLogExtensionsLogging", "6.0.0" } }),
new("6.0.6", additionalMetaData: new() { { "NLogExtensionsLogging", "6.1.0" } }),
]
},
{
"TestApplication.MassTransit",
[
Expand Down
2 changes: 1 addition & 1 deletion build/TargetFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TargetFramework : Enumeration

// should be in version order
public static readonly TargetFramework[] NetFramework = {
NET462, NET47, NET471, NET472, NET472
NET462, NET47, NET471, NET472
};

public static implicit operator string(TargetFramework framework)
Expand Down
4 changes: 4 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ due to lack of stable semantic convention.
|-----------|---------------------------------------------------------------------------------------------------------------------------------|--------------------|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `ILOGGER` | [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging) **Not supported on .NET Framework** | ≥8.0.0 | bytecode or source \[1\] | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `LOG4NET` | [log4net](https://www.nuget.org/packages/log4net) \[2\] | ≥2.0.13 && < 4.0.0 | bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |
| `NLOG` | [NLog](https://www.nuget.org/packages/NLog) \[3\] | ≥5.0.0 && < 7.0.0 | bytecode | [Experimental](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/versioning-and-stability.md) |

\[1\]: For ASP.NET Core applications, the `LoggingBuilder` instrumentation
can be enabled without using the .NET CLR Profiler by setting
Expand All @@ -215,6 +216,9 @@ the `ASPNETCORE_HOSTINGSTARTUPASSEMBLIES` environment variable to
\[2\]: Instrumentation provides both [trace context injection](./log-trace-correlation.md#log4net-trace-context-injection)
and [logs bridge](./log4net-bridge.md).

\[3\]: Instrumentation provides both [trace context injection](./log-trace-correlation.md#log4net-trace-context-injection)
and [logs bridge](./nlog-bridge.md).

### Instrumentation options

| Environment variable | Description | Default value | Status |
Expand Down
5 changes: 5 additions & 0 deletions docs/file-based-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ instrumentation/development:
logs:
ilogger: # Microsoft.Extensions.Logging
log4net: # Log4Net
nlog: # NLog
```

## Instrumentation options
Expand Down Expand Up @@ -567,6 +568,10 @@ instrumentation/development:
# Logs bridge is disabled by default
# More info about log4net bridge can be found at https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/docs/log4net-bridge.md
bridge_enabled: true
nlog:
# Logs bridge is disabled by default
# More info about NLog bridge can be found at https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/docs/nlog-bridge.md
bridge_enabled: true
```

## Instrumentation Additional Sources
Expand Down
24 changes: 24 additions & 0 deletions docs/log-trace-correlation.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,27 @@ Following properties are set by default on the collection of logging event's pro

This allows for trace context to be logged into currently configured log destination,
e.g. a file. In order to use them, pattern needs to be updated.

### `NLog`

See [`nlog-bridge`](./nlog-bridge.md).

## `NLog` trace context injection

> [!IMPORTANT]
> NLog trace context injection is an experimental feature.

The `NLog` trace context injection is enabled by default.
It can be disabled by setting
`OTEL_DOTNET_AUTO_LOGS_NLOG_INSTRUMENTATION_ENABLED` to `false`.

Context injection is supported for `NLOG` in versions >= 5.0.0 && < 7.0.0

Following properties are set by default on the collection of logging event's properties:

- `trace_id`
- `span_id`
- `trace_flags`

This allows for trace context to be logged into currently configured log destination,
e.g. a file. In order to use them, pattern needs to be updated.
45 changes: 45 additions & 0 deletions docs/nlog-bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# `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`.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsWithWrapperTypeIntegration
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsIntegration
OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsWithWrapperTypeIntegration
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ public static class Logs
/// </summary>
public const string EnableLog4NetBridge = "OTEL_DOTNET_AUTO_LOGS_ENABLE_LOG4NET_BRIDGE";

/// <summary>
/// Configuration key for whether or not experimental NLog bridge
/// should be enabled.
/// </summary>
public const string EnableNLogBridge = "OTEL_DOTNET_AUTO_LOGS_ENABLE_NLOG_BRIDGE";

/// <summary>
/// Configuration key for disabling all log instrumentations.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ internal class DotNetLogs
/// Gets or sets the Log4Net logs instrumentation configuration.
/// </summary>
[YamlMember(Alias = "log4net")]
public Log4NetBridgeEnabled? Log4Net { get; set; }
public LogBridgeEnabled? Log4Net { get; set; }

/// <summary>
/// Gets or sets the Log4Net logs instrumentation configuration.
/// </summary>
[YamlMember(Alias = "nlog")]
public LogBridgeEnabled? NLog { get; set; }

/// <summary>
/// Returns the list of enabled log instrumentations.
Expand All @@ -36,6 +42,11 @@ public IReadOnlyList<LogInstrumentation> GetEnabledInstrumentations()
result.Add(LogInstrumentation.Log4Net);
}

if (NLog != null)
{
result.Add(LogInstrumentation.NLog);
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

[EmptyObjectOnEmptyYaml]
internal class Log4NetBridgeEnabled
internal class LogBridgeEnabled
{
/// <summary>
/// Gets or sets a value indicating whether the Log4Net bridge is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ internal enum LogInstrumentation
/// Log4Net instrumentation.
/// </summary>
Log4Net = 1,

/// <summary>
/// NLog instrumentation.
/// </summary>
NLog = 2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ internal class LogSettings : Settings
/// </summary>
public bool EnableLog4NetBridge { get; private set; }

/// <summary>
/// Gets a value indicating whether the experimental NLog bridge is enabled.
/// </summary>
public bool EnableNLogBridge { get; private set; }

/// <summary>
/// Gets the list of enabled instrumentations.
/// </summary>
Expand All @@ -60,6 +65,7 @@ protected override void OnLoadEnvVar(Configuration configuration)

IncludeFormattedMessage = configuration.GetBool(ConfigurationKeys.Logs.IncludeFormattedMessage) ?? false;
EnableLog4NetBridge = configuration.GetBool(ConfigurationKeys.Logs.EnableLog4NetBridge) ?? false;
EnableNLogBridge = configuration.GetBool(ConfigurationKeys.Logs.EnableNLogBridge) ?? false;

var instrumentationEnabledByDefault =
configuration.GetBool(ConfigurationKeys.Logs.LogsInstrumentationEnabled) ??
Expand All @@ -85,6 +91,11 @@ protected override void OnLoadFile(YamlConfiguration configuration)
{
EnableLog4NetBridge = logs?.Log4Net?.BridgeEnabled ?? false;
}

if (EnabledInstrumentations.Contains(LogInstrumentation.NLog))
{
EnableNLogBridge = logs?.NLog?.BridgeEnabled ?? false;
}
}

private static List<LogExporter> ParseLogExporter(Configuration configuration)
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>(36);
var nativeCallTargetDefinitions = new List<NativeCallTargetDefinition>(42);
// Traces
var tracerSettings = Instrumentation.TracerSettings.Value;
if (tracerSettings.TracesEnabled)
Expand Down Expand Up @@ -101,6 +101,17 @@ private static NativeCallTargetDefinition[] GetDefinitionsArray()
nativeCallTargetDefinitions.Add(new("log4net", "log4net.Appender.AppenderCollection", "ToArray", ["log4net.Appender.IAppender[]"], 2, 0, 13, 3, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.Log4Net.Bridge.Integrations.AppenderCollectionIntegration"));
nativeCallTargetDefinitions.Add(new("log4net", "log4net.Util.AppenderAttachedImpl", "AppendLoopOnAppenders", ["System.Int32", "log4net.Core.LoggingEvent"], 2, 0, 13, 3, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.Log4Net.TraceContextInjection.Integrations.AppenderAttachedImplIntegration"));
}

// NLog
if (logSettings.EnabledInstrumentations.Contains(LogInstrumentation.NLog))
{
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.NLogWriteToTargetsIntegration"));
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.NLogWriteToTargetsIntegration"));
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.NLogWriteToTargetsIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteToTargets", ["System.Void", "System.Type", "NLog.LogEventInfo", "NLog.Internal.ITargetWithFilterChain"], 5, 0, 0, 5, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsWithWrapperTypeIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteToTargets", ["System.Void", "System.Type", "NLog.LogEventInfo", "NLog.Internal.TargetWithFilterChain"], 5, 0, 0, 5, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsWithWrapperTypeIntegration"));
nativeCallTargetDefinitions.Add(new("NLog", "NLog.Logger", "WriteLogEventToTargets", ["System.Void", "System.Type", "NLog.LogEventInfo", "NLog.Internal.ITargetWithFilterChain"], 6, 0, 0, 6, 65535, 65535, AssemblyFullName, "OpenTelemetry.AutoInstrumentation.Instrumentations.NLog.TraceContextInjection.Integrations.NLogWriteToTargetsWithWrapperTypeIntegration"));
}
}

// Metrics
Expand Down
Loading
Loading