This repository has been archived by the owner on Apr 22, 2022. It is now read-only.
forked from DataDog/dd-trace-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Trace Id Injection NullReferenceException with NLog 1.0.0.505 (Da…
…taDog#614) Issue: Currently using the Trace Id Injection fails with a NullReferenceException when the instrumented application is using NLog 1.0.0.505. This occurs because the LibLog library we use to detect the instrumented application's logging framework assumes that all versions of NLog have the type `NLog.MappedDiagnosticsContext` for using the Mdc features. Unfortunately this is incorrect in one case: the very first NLog library v1.0.0.505 had its Mdc features in a type named `NLog.MDC`. Rather than vendor LibLog to support this, for now we will catch the issue and disable Trace Id Injection for the application. Changes: - Add new reproduction project NLog10LogsInjection.NullReferenceException and an associated CI test case to reproduce issue with DD_LOGS_INJECTION=true on NLog v1.0.0.505 - Add the fix to catch the inability to add to the MDC of the application logging framework. - Additionally, perform small refactoring of CI test harness.
- Loading branch information
1 parent
5bbbcbe
commit f30235e
Showing
12 changed files
with
157 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
11 changes: 11 additions & 0 deletions
11
reproductions/NLog10LogsInjection.NullReferenceException/NLog.config
This file contains 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,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<targets> | ||
<target name="logfile" xsi:type="File" fileName="file.txt" /> | ||
</targets> | ||
|
||
<rules> | ||
<logger name="*" minlevel="Trace" writeTo="logfile" /> | ||
</rules> | ||
</nlog> |
17 changes: 17 additions & 0 deletions
17
...g10LogsInjection.NullReferenceException/NLog10LogsInjection.NullReferenceException.csproj
This file contains 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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net452;net461</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<ExcludeManagedProfiler>true</ExcludeManagedProfiler> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NLog" Version="1.0.0.505" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Datadog.Trace\Datadog.Trace.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
29 changes: 29 additions & 0 deletions
29
reproductions/NLog10LogsInjection.NullReferenceException/Program.cs
This file contains 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,29 @@ | ||
using Datadog.Trace; | ||
using NLog; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace NLog10LogsInjection.NullReferenceException | ||
{ | ||
class Program | ||
{ | ||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); | ||
|
||
static int Main(string[] args) | ||
{ | ||
using (var scope = Tracer.Instance.StartActive("Main")) | ||
{ | ||
Logger.Info("Message during a trace."); | ||
|
||
using (var innerScope = Tracer.Instance.StartActive("Main-Inner")) | ||
{ | ||
Logger.Info("Inner message during a trace."); | ||
} | ||
} | ||
|
||
Console.WriteLine("Successfully created a trace with two spans and didn't crash. Delay for five seconds to flush the trace."); | ||
Task.Delay(TimeSpan.FromSeconds(5)).GetAwaiter().GetResult(); | ||
return 0; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
reproductions/NLog10LogsInjection.NullReferenceException/Properties/launchSettings.json
This file contains 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,11 @@ | ||
{ | ||
"profiles": { | ||
"NLog10LogsInjection.NullReferenceException": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"DD_LOGS_INJECTION": "true" | ||
}, | ||
"nativeDebugging": true | ||
} | ||
} | ||
} |
This file contains 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 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 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
22 changes: 22 additions & 0 deletions
22
...rofiler.IntegrationTests/SmokeTests/NLog10LogsInjectionNullReferenceExceptionSmokeTest.cs
This file contains 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,22 @@ | ||
using Datadog.Trace.ClrProfiler.IntegrationTests.Helpers; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Datadog.Trace.ClrProfiler.IntegrationTests.SmokeTests | ||
{ | ||
public class NLog10LogsInjectionNullReferenceExceptionSmokeTest : SmokeTestBase | ||
{ | ||
public NLog10LogsInjectionNullReferenceExceptionSmokeTest(ITestOutputHelper output) | ||
: base(output, "NLog10LogsInjection.NullReferenceException", maxTestRunSeconds: 45) | ||
{ | ||
SetEnvironmentVariable("DD_LOGS_INJECTION", "true"); | ||
} | ||
|
||
[TargetFrameworkVersionsFact("net452;net461")] | ||
[Trait("Category", "Smoke")] | ||
public void NoExceptions() | ||
{ | ||
CheckForSmoke(shouldDeserializeTraces: false); | ||
} | ||
} | ||
} |
This file contains 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 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 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