diff --git a/src/Datadog.APM.sln b/src/Datadog.APM.sln
index dd24ae39a04f..8396ed6aaee7 100644
--- a/src/Datadog.APM.sln
+++ b/src/Datadog.APM.sln
@@ -6,7 +6,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Tracer", "Datadog.T
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Tracer.Tests", "Datadog.Tracer.Tests\Datadog.Tracer.Tests.csproj", "{73A1BE1C-9C8A-43FA-86A8-BF2744B4C1BB}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Datadog.Tracer.IntegrationTests", "Datadog.Tracer.IntegrationTests\Datadog.Tracer.IntegrationTests.csproj", "{0434F813-5F94-4195-8A2C-E2E755513822}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Datadog.Tracer.IntegrationTests", "Datadog.Tracer.IntegrationTests\Datadog.Tracer.IntegrationTests.csproj", "{0434F813-5F94-4195-8A2C-E2E755513822}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Datadog.Tracer.Tests.Net45", "Datadog.Tracer.Tests.Net45\Datadog.Tracer.Tests.Net45.csproj", "{E03FF1CD-8DC2-42C3-B85E-921893710CF0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Datadog.Tracer.IntegrationTests.Net45", "Datadog.Tracer.IntegrationTests.Net45\Datadog.Tracer.IntegrationTests.Net45.csproj", "{9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -54,6 +58,30 @@ Global
{0434F813-5F94-4195-8A2C-E2E755513822}.Release|x64.Build.0 = Release|Any CPU
{0434F813-5F94-4195-8A2C-E2E755513822}.Release|x86.ActiveCfg = Release|Any CPU
{0434F813-5F94-4195-8A2C-E2E755513822}.Release|x86.Build.0 = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|x64.Build.0 = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Debug|x86.Build.0 = Debug|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|x64.ActiveCfg = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|x64.Build.0 = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|x86.ActiveCfg = Release|Any CPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}.Release|x86.Build.0 = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|x64.Build.0 = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Debug|x86.Build.0 = Debug|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|x64.ActiveCfg = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|x64.Build.0 = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|x86.ActiveCfg = Release|Any CPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/Datadog.Tracer.IntegrationTests.Net45/Datadog.Tracer.IntegrationTests.Net45.csproj b/src/Datadog.Tracer.IntegrationTests.Net45/Datadog.Tracer.IntegrationTests.Net45.csproj
new file mode 100644
index 000000000000..ff7f37317a44
--- /dev/null
+++ b/src/Datadog.Tracer.IntegrationTests.Net45/Datadog.Tracer.IntegrationTests.Net45.csproj
@@ -0,0 +1,89 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {9DD2FA11-BCBA-4F8A-93CE-D1ED28282A6E}
+ Library
+ Properties
+ Datadog.Tracer.IntegrationTests.Net45
+ Datadog.Tracer.IntegrationTests.Net45
+ v4.5
+ 512
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\MsgPack.Cli.0.9.2\lib\net45\MsgPack.dll
+
+
+ ..\packages\OpenTracing.0.10.0\lib\netstandard1.0\OpenTracing.dll
+
+
+
+
+
+
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+
+
+
+
+
+
+
+
+ ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll
+
+
+ ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll
+
+
+ ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll
+
+
+ ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll
+
+
+
+
+ MsgPackHelpers.cs
+
+
+ RecordHttpHandler.cs
+
+
+ SendTracesToAgent.cs
+
+
+
+
+
+
+
+
+ {5dfdf781-f24c-45b1-82ef-9125875a80a4}
+ Datadog.Tracer
+
+
+
+
\ No newline at end of file
diff --git a/src/Datadog.Tracer.IntegrationTests.Net45/Properties/AssemblyInfo.cs b/src/Datadog.Tracer.IntegrationTests.Net45/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000000..9224fdc8ab57
--- /dev/null
+++ b/src/Datadog.Tracer.IntegrationTests.Net45/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Datadog.Tracer.IntegrationsTests.Net45")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Datadog.Tracer.IntegrationsTests.Net45")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9dd2fa11-bcba-4f8a-93ce-d1ed28282a6e")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/Datadog.Tracer.IntegrationTests.Net45/packages.config b/src/Datadog.Tracer.IntegrationTests.Net45/packages.config
new file mode 100644
index 000000000000..61c7774e947c
--- /dev/null
+++ b/src/Datadog.Tracer.IntegrationTests.Net45/packages.config
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Datadog.Tracer.IntegrationTests/Datadog.Tracer.IntegrationTests.csproj b/src/Datadog.Tracer.IntegrationTests/Datadog.Tracer.IntegrationTests.csproj
index 23a13e48127e..43cef98636a0 100644
--- a/src/Datadog.Tracer.IntegrationTests/Datadog.Tracer.IntegrationTests.csproj
+++ b/src/Datadog.Tracer.IntegrationTests/Datadog.Tracer.IntegrationTests.csproj
@@ -1,8 +1,12 @@
- netcoreapp2.0
+ netcoreapp2.0;
+ false
+
+
+ netcoreapp2.0;net452;net46;net461;net462;net47
false
@@ -12,6 +16,11 @@
+
+
+
+
+
diff --git a/src/Datadog.Tracer.IntegrationTests/RecordHttpHandler.cs b/src/Datadog.Tracer.IntegrationTests/RecordHttpHandler.cs
index 9a7d35b827ac..2392a1472fa6 100644
--- a/src/Datadog.Tracer.IntegrationTests/RecordHttpHandler.cs
+++ b/src/Datadog.Tracer.IntegrationTests/RecordHttpHandler.cs
@@ -20,16 +20,16 @@ public class RecordHttpHandler : DelegatingHandler
private int _target = 0;
private TaskCompletionSource _tcs;
- public List Requests { get; set; }
+ public List> Requests { get; set; }
public List> Traces => Requests
- .Where(x => x.RequestUri.ToString().Contains("/v0.3/traces"))
- .Select(x => Unpacking.UnpackObject(x.Content.ReadAsByteArrayAsync().Result).Value.AsList())
+ .Where(x => x.Item1.RequestUri.ToString().Contains("/v0.3/traces"))
+ .Select(x => Unpacking.UnpackObject(x.Item2).Value.AsList())
.ToList();
public List Services => Requests
- .Where(x => x.RequestUri.ToString().Contains("/v0.3/services"))
- .Select(x => Unpacking.UnpackObject(x.Content.ReadAsByteArrayAsync().Result).Value.AsDictionary())
+ .Where(x => x.Item1.RequestUri.ToString().Contains("/v0.3/services"))
+ .Select(x => Unpacking.UnpackObject(x.Item2).Value.AsDictionary())
.ToList();
public List Responses { get; set; }
@@ -37,16 +37,17 @@ public class RecordHttpHandler : DelegatingHandler
public RecordHttpHandler()
{
InnerHandler = new HttpClientHandler();
- Requests = new List();
+ Requests = new List>();
Responses = new List();
}
protected async override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
+ var requestContent = await request.Content.ReadAsByteArrayAsync();
var response = await base.SendAsync(request, cancellationToken);
lock(_lock)
{
- Requests.Add(request);
+ Requests.Add(Tuple.Create(request, requestContent));
Responses.Add(response);
_count++;
if(_tcs != null && _count >= _target)
diff --git a/src/Datadog.Tracer.Tests.Net45/Datadog.Tracer.Tests.Net45.csproj b/src/Datadog.Tracer.Tests.Net45/Datadog.Tracer.Tests.Net45.csproj
new file mode 100644
index 000000000000..daa90a55176d
--- /dev/null
+++ b/src/Datadog.Tracer.Tests.Net45/Datadog.Tracer.Tests.Net45.csproj
@@ -0,0 +1,107 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {E03FF1CD-8DC2-42C3-B85E-921893710CF0}
+ Library
+ Properties
+ Datadog.Tracer.Tests.Net45
+ Datadog.Tracer.Tests.Net45
+ v4.5
+ 512
+
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll
+
+
+ ..\packages\Moq.4.7.142\lib\net45\Moq.dll
+
+
+ ..\packages\OpenTracing.0.10.0\lib\netstandard1.0\OpenTracing.dll
+
+
+
+
+
+
+
+
+ ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
+
+
+
+
+
+
+
+
+ ..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll
+
+
+ ..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll
+
+
+ ..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll
+
+
+ ..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll
+
+
+
+
+ AgentWriterBufferTests.cs
+
+
+ AgentWriterTests.cs
+
+
+ ApiTests.cs
+
+
+ SpanBuilderTests.cs
+
+
+ SpanTests.cs
+
+
+ TracerTests.cs
+
+
+
+
+
+ {5dfdf781-f24c-45b1-82ef-9125875a80a4}
+ Datadog.Tracer
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Datadog.Tracer.Tests.Net45/Properties/AssemblyInfo.cs b/src/Datadog.Tracer.Tests.Net45/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000000..0e47e933c863
--- /dev/null
+++ b/src/Datadog.Tracer.Tests.Net45/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Datadog.Tracer.Tests.Net45")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Datadog.Tracer.Tests.Net45")]
+[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("e03ff1cd-8dc2-42c3-b85e-921893710cf0")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/Datadog.Tracer.Tests.Net45/packages.config b/src/Datadog.Tracer.Tests.Net45/packages.config
new file mode 100644
index 000000000000..f3a1c7dcbb99
--- /dev/null
+++ b/src/Datadog.Tracer.Tests.Net45/packages.config
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Datadog.Tracer.Tests/AgentWriterTests.cs b/src/Datadog.Tracer.Tests/AgentWriterTests.cs
index c85c5ab87ffe..bef7ac098016 100644
--- a/src/Datadog.Tracer.Tests/AgentWriterTests.cs
+++ b/src/Datadog.Tracer.Tests/AgentWriterTests.cs
@@ -28,12 +28,12 @@ public async Task WriteServiceInfo_2Services_SendToApi()
{
var serviceInfo = new ServiceInfo { App = "AA", AppType = "BB", ServiceName = "CC" };
_agentWriter.WriteServiceInfo(serviceInfo);
- await Task.Delay(TimeSpan.FromSeconds(1));
+ await Task.Delay(TimeSpan.FromSeconds(1.5));
_api.Verify(x => x.SendServiceAsync(It.Is(y => y.Equals(serviceInfo))), Times.Once);
serviceInfo = new ServiceInfo { App = "DD", AppType = "EE", ServiceName = "FF" };
_agentWriter.WriteServiceInfo(serviceInfo);
- await Task.Delay(TimeSpan.FromSeconds(1));
+ await Task.Delay(TimeSpan.FromSeconds(1.5));
_api.Verify(x => x.SendServiceAsync(It.Is(y => y.Equals(serviceInfo))), Times.Once);
}
@@ -43,12 +43,12 @@ public async Task WriteTrace_2Traces_SendToApi()
// TODO:bertrand it is too complicated to setup such a simple test
var trace = new List { new Span(_tracer.Object, null, "Operation", "Service", null) };
_agentWriter.WriteTrace(trace);
- await Task.Delay(TimeSpan.FromSeconds(1));
+ await Task.Delay(TimeSpan.FromSeconds(1.5));
_api.Verify(x => x.SendTracesAsync(It.Is>>(y => y.Single().Equals(trace))), Times.Once);
trace = new List { new Span(_tracer.Object, null, "Operation2", "AnotherService", null) };
_agentWriter.WriteTrace(trace);
- await Task.Delay(TimeSpan.FromSeconds(1));
+ await Task.Delay(TimeSpan.FromSeconds(1.5));
_api.Verify(x => x.SendTracesAsync(It.Is>>(y => y.Single().Equals(trace))), Times.Once);
}
}
diff --git a/src/Datadog.Tracer.Tests/Datadog.Tracer.Tests.csproj b/src/Datadog.Tracer.Tests/Datadog.Tracer.Tests.csproj
index e864eed71f86..18c0867516f7 100644
--- a/src/Datadog.Tracer.Tests/Datadog.Tracer.Tests.csproj
+++ b/src/Datadog.Tracer.Tests/Datadog.Tracer.Tests.csproj
@@ -1,8 +1,12 @@
- netcoreapp2.0
+ netcoreapp2.0;
+ false
+
+
+ netcoreapp2.0;net452;net46;net461;net462;net47
false
diff --git a/src/Datadog.Tracer.Tests/SpanTests.cs b/src/Datadog.Tracer.Tests/SpanTests.cs
index 1584e3f05e39..619613718128 100644
--- a/src/Datadog.Tracer.Tests/SpanTests.cs
+++ b/src/Datadog.Tracer.Tests/SpanTests.cs
@@ -57,7 +57,7 @@ public void Finish_StartTimeInThePastWithNoEndTime_DurationProperlyComputed()
span.Finish();
_traceContextMock.Verify(x => x.CloseSpan(It.IsAny()), Times.Once);
- Assert.True(span.Duration > TimeSpan.FromMinutes(1) && span.Duration < TimeSpan.FromMinutes(2));
+ Assert.True(span.Duration >= TimeSpan.FromMinutes(1) && span.Duration < TimeSpan.FromMinutes(2));
}
[Fact]
diff --git a/src/Datadog.Tracer.Tests/TimeUtilsTests.cs b/src/Datadog.Tracer.Tests/TimeUtilsTests.cs
index 659823a228ec..2b97d6345646 100644
--- a/src/Datadog.Tracer.Tests/TimeUtilsTests.cs
+++ b/src/Datadog.Tracer.Tests/TimeUtilsTests.cs
@@ -1,4 +1,5 @@
-using System;
+#if !NET45 && !NET451 && !NET452
+using System;
using Xunit;
namespace Datadog.Tracer.Tests
@@ -20,3 +21,4 @@ public void ToUnixTimeNanoseconds_Now_CorrectMillisecondRoundedValue()
}
}
}
+#endif
\ No newline at end of file
diff --git a/src/Datadog.Tracer/Api.cs b/src/Datadog.Tracer/Api.cs
index 3da303e8046f..50d7c7bb544c 100644
--- a/src/Datadog.Tracer/Api.cs
+++ b/src/Datadog.Tracer/Api.cs
@@ -1,7 +1,6 @@
using MsgPack.Serialization;
using System;
using System.Collections.Generic;
-using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.InteropServices;
@@ -34,7 +33,7 @@ static Api()
private Uri _tracesEndpoint;
private Uri _servicesEndpoint;
- private HttpClient _client = new HttpClient();
+ private HttpClient _client;
public Api(Uri baseEndpoint, DelegatingHandler delegatingHandler = null)
{
@@ -51,7 +50,7 @@ public Api(Uri baseEndpoint, DelegatingHandler delegatingHandler = null)
// TODO:bertrand add header for os version
_client.DefaultRequestHeaders.Add("Datadog-Meta-Lang", ".NET");
_client.DefaultRequestHeaders.Add("Datadog-Meta-Lang-Interpreter", RuntimeInformation.FrameworkDescription);
- _client.DefaultRequestHeaders.Add("Datadog-Meta-Tracer-Version", Assembly.GetEntryAssembly().GetName().Version.ToString());
+ _client.DefaultRequestHeaders.Add("Datadog-Meta-Tracer-Version", Assembly.GetAssembly(typeof(Api)).GetName().Version.ToString());
}
private async Task SendAsync(T value, Uri endpoint)
diff --git a/src/Datadog.Tracer/AssemblyInfo.cs b/src/Datadog.Tracer/AssemblyInfo.cs
index c7d78ef12023..ad2af0c8b72e 100644
--- a/src/Datadog.Tracer/AssemblyInfo.cs
+++ b/src/Datadog.Tracer/AssemblyInfo.cs
@@ -1,5 +1,7 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Datadog.Tracer.Tests")]
+[assembly: InternalsVisibleTo("Datadog.Tracer.Tests.Net45")]
[assembly: InternalsVisibleTo("Datadog.Tracer.IntegrationTests")]
+[assembly: InternalsVisibleTo("Datadog.Tracer.IntegrationTests.Net45")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
\ No newline at end of file
diff --git a/src/Datadog.Tracer/AsyncLocalCompat.cs b/src/Datadog.Tracer/AsyncLocalCompat.cs
new file mode 100644
index 000000000000..eafe46b8c039
--- /dev/null
+++ b/src/Datadog.Tracer/AsyncLocalCompat.cs
@@ -0,0 +1,47 @@
+
+namespace Datadog.Tracer
+{
+#if NET45
+ using System.Runtime.Remoting.Messaging;
+ // TODO:bertrand revisit this when we want to support multiple AppDomains
+ internal class AsyncLocalCompat
+ {
+ private string _name;
+
+ public AsyncLocalCompat(string name)
+ {
+ _name = name;
+ }
+
+ public T Get()
+ {
+ return (T)CallContext.LogicalGetData(_name);
+ }
+
+ public void Set(T value)
+ {
+ CallContext.LogicalSetData(_name, value);
+ }
+ }
+#else
+ using System.Threading;
+ internal class AsyncLocalCompat
+ {
+ private AsyncLocal _asyncLocal = new AsyncLocal();
+
+ public AsyncLocalCompat(string name)
+ {
+ }
+
+ public T Get()
+ {
+ return _asyncLocal.Value;
+ }
+
+ public void Set(T value)
+ {
+ _asyncLocal.Value = value;
+ }
+ }
+#endif
+}
diff --git a/src/Datadog.Tracer/Datadog.Tracer.csproj b/src/Datadog.Tracer/Datadog.Tracer.csproj
index 2915eaff975d..512264212287 100644
--- a/src/Datadog.Tracer/Datadog.Tracer.csproj
+++ b/src/Datadog.Tracer/Datadog.Tracer.csproj
@@ -1,7 +1,7 @@
- netstandard2.0
+ netstandard2.0;net45;net46
diff --git a/src/Datadog.Tracer/TimeUtils.cs b/src/Datadog.Tracer/TimeUtils.cs
index 489bd4e73d77..3f4db9010939 100644
--- a/src/Datadog.Tracer/TimeUtils.cs
+++ b/src/Datadog.Tracer/TimeUtils.cs
@@ -5,7 +5,7 @@ namespace Datadog.Tracer
static class TimeUtils
{
private const long NanoSecondsPerTick = 1000000 / TimeSpan.TicksPerMillisecond;
- private static readonly long UnixEpochInTicks = DateTimeOffset.FromUnixTimeMilliseconds(0).Ticks;
+ private static readonly long UnixEpochInTicks = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).Ticks;
public static long ToUnixTimeNanoseconds(this DateTimeOffset dateTimeOffset)
{
diff --git a/src/Datadog.Tracer/TraceContext.cs b/src/Datadog.Tracer/TraceContext.cs
index 2e6abe32bea0..8a05596ab52c 100644
--- a/src/Datadog.Tracer/TraceContext.cs
+++ b/src/Datadog.Tracer/TraceContext.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.Threading;
namespace Datadog.Tracer
{
@@ -9,7 +8,7 @@ internal class TraceContext : ITraceContext
private IDatadogTracer _tracer;
private List _spans = new List();
private int _openSpans = 0;
- private AsyncLocal _currentSpanContext = new AsyncLocal();
+ private AsyncLocalCompat _currentSpanContext = new AsyncLocalCompat("Datadog.Tracer.TraceContext._currentSpanContext");
public bool Sampled { get; set; }
@@ -20,14 +19,14 @@ public TraceContext(IDatadogTracer tracer)
public SpanContext GetCurrentSpanContext()
{
- return _currentSpanContext.Value;
+ return _currentSpanContext.Get();
}
public void AddSpan(Span span)
{
lock (_lock)
{
- _currentSpanContext.Value = span.Context;
+ _currentSpanContext.Set(span.Context);
_spans.Add(span);
_openSpans++;
}
@@ -37,7 +36,7 @@ public void CloseSpan(Span span)
{
lock (_lock)
{
- _currentSpanContext.Value = _currentSpanContext.Value?.Parent;
+ _currentSpanContext.Set(_currentSpanContext.Get()?.Parent);
_openSpans--;
if (span.IsRootSpan)
{
diff --git a/src/Datadog.Tracer/Tracer.cs b/src/Datadog.Tracer/Tracer.cs
index 850556e9bf63..487dd7c4eb08 100644
--- a/src/Datadog.Tracer/Tracer.cs
+++ b/src/Datadog.Tracer/Tracer.cs
@@ -9,7 +9,7 @@ namespace Datadog.Tracer
{
internal class Tracer : ITracer, IDatadogTracer
{
- private AsyncLocal _currentContext = new AsyncLocal();
+ private AsyncLocalCompat _currentContext = new AsyncLocalCompat("Datadog.Tracer.Tracer._currentContext");
private string _defaultServiceName;
private Dictionary _services = new Dictionary();
private IAgentWriter _agentWriter;
@@ -69,16 +69,16 @@ void IDatadogTracer.Write(List trace)
ITraceContext IDatadogTracer.GetTraceContext()
{
- if(_currentContext.Value == null)
+ if(_currentContext.Get() == null)
{
- _currentContext.Value = new TraceContext(this);
+ _currentContext.Set(new TraceContext(this));
}
- return _currentContext.Value;
+ return _currentContext.Get();
}
void IDatadogTracer.CloseCurrentTraceContext()
{
- _currentContext.Value = null;
+ _currentContext.Set(null);
}
}
}