feat(logs): add NLog integration - #5176
1 issue
find-bugs: Found 1 issue (1 high)
High
NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes - `src/Sentry.NLog/SentryTarget.cs:355`
In SentryTarget.Structured.cs, CaptureStructuredLog calls log.SetDefaultAttributes(options, Sdk). The Sdk field is a SdkVersion, but the target method signature is SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null), so Sdk is being bound to the Scope? scope parameter. SdkVersion is a sealed class with no implicit conversion to Scope, so this is a type mismatch. Even if it were to resolve, the scope argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in SentrySink.Structured.cs: var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);. Fix: obtain the scope from the hub (var scope = hub.GetScope();) and call log.SetDefaultAttributes(options, scope, Sdk);.
Also found at:
src/Sentry.NLog/SentryTarget.Structured.cs:15
⏱ 14m 9s · 7.3M in / 120.9k out · $10.48
Annotations
Check failure on line 355 in src/Sentry.NLog/SentryTarget.cs
sentry-warden / warden: find-bugs
NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes
In `SentryTarget.Structured.cs`, `CaptureStructuredLog` calls `log.SetDefaultAttributes(options, Sdk)`. The `Sdk` field is a `SdkVersion`, but the target method signature is `SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null)`, so `Sdk` is being bound to the `Scope? scope` parameter. `SdkVersion` is a sealed class with no implicit conversion to `Scope`, so this is a type mismatch. Even if it were to resolve, the `scope` argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in `SentrySink.Structured.cs`: `var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);`. Fix: obtain the scope from the hub (`var scope = hub.GetScope();`) and call `log.SetDefaultAttributes(options, scope, Sdk);`.
Check failure on line 15 in src/Sentry.NLog/SentryTarget.Structured.cs
sentry-warden / warden: find-bugs
[YAU-G66] NLog CaptureStructuredLog passes SdkVersion to the Scope parameter of SetDefaultAttributes (additional location)
In `SentryTarget.Structured.cs`, `CaptureStructuredLog` calls `log.SetDefaultAttributes(options, Sdk)`. The `Sdk` field is a `SdkVersion`, but the target method signature is `SetDefaultAttributes(SentryOptions options, Scope? scope, SdkVersion? sdk = null)`, so `Sdk` is being bound to the `Scope? scope` parameter. `SdkVersion` is a sealed class with no implicit conversion to `Scope`, so this is a type mismatch. Even if it were to resolve, the `scope` argument would be wrong and the actual SDK version would never be passed, meaning scope-derived attributes (user.id, user.name, user.email, scope Sdk) are never applied to structured logs. Compare the correct Serilog implementation in `SentrySink.Structured.cs`: `var scope = hub.GetScope(); log.SetDefaultAttributes(options, scope, Sdk);`. Fix: obtain the scope from the hub (`var scope = hub.GetScope();`) and call `log.SetDefaultAttributes(options, scope, Sdk);`.