Skip to content

Commit

Permalink
Use DiagnosticSource to instrument ASP.NET Core (DataDog#611)
Browse files Browse the repository at this point in the history
* clean up env vars, project properties, and unused references

* update 3rd-party license file

* changes to IScope, ISpan, and IDatadogTracer interfaces

* disable current AspNetCoreMvc2 and AspNetCoreMvc3 integrations

* add minimal solution

* subscribe to DiagnosticSource events from Tracer if enabled

* add startup hook

* add Datadog.Trace.DiagnosticListeners

* add DiagnosticSource configuration

* fix URLs to moved repositories

* update notes in deprecated NuGet package

* fix nuget package comment

* remove redundant null coalescing operator

* use System.Net.Http from the GAC when targeting net4*, use the nuget package when targeting netstandard2.0

* support ASP.NET Core running on .NET Framework

* add logs

* remove the build dependency on Datadog.Trace.dll and Datadog.Trace.ClrProfiler.Managed.dll in sample app

* fix comment

* don't try to write to stderr

* remove tailing whitespace

* call Tracer.StartDiagnosticObservers from the auto-instrumentation startup hook

* stop previous observers when starting new ones in StartDiagnosticObservers()

* convert GetListenerName() to property ListenerName

* check if there is a parent span earlier to avoid extra work

* reorder methods into expected execution order

* reference System.Diagnostics.DiagnosticSource 4.4.1, the version used by Microsoft.AspNetCore.* 2.0.0

* move the check for available System.Diagnostics.DiagnosticSource into Tracer

* remove remaning sample apps and solution items from the "minimal" solution

* remove integration tests for deleted integrations

* add missing System.Net.Http references

* fix aspnet core mvc integration tests

* always save moduel metadata for Microsoft.AspNetCore.Hosting to ensure the startup hook is executed on ASP.NET Core

* handle Microsoft.AspNetCore.Diagnostics.UnhandledException event to capture exceptions in ASP.NET Core (not MVC)

* use ordinal string compare

* stop handling Microsoft.AspNetCore.Mvc.AfterOnActionExecuted since we now have Microsoft.AspNetCore.Diagnostics.UnhandledException

* add test app for "pure" ASP.NET Core 3.1 (no MVC)

* optimize Log.IsEnabled() calls (only cache the result if it will be used very often)

* add checks for error flag and error type in AspNetCoreMvc integration tests

* rethrow exceptions in SubmitRequest() so tests fail

* add missing netcoreapp3.1 targets in Windows

* rename SpanExpectation.Detail() to ToString() and other code clean up

* fix WebServerSpanExpectation and AspNetCoreMvcSpanExpectation to properly validate the http status code and http method, and fix the tags for http status code and http method

* rewrite SubmitRequest() to use HttpClient instead of WebRequest

* stop EntityFramework6x.MdTokenLookupFailure from including Test.Common.props

* change wording in sample app

* target netcoreapp3.1 in PrepareRelease (resolves nuget restore error)

* don't configure an exception handler

* add test for 404

* change the default values to unbreak the GraphQL tests
  • Loading branch information
lucaspimentel authored Feb 4, 2020
1 parent 7aba67d commit e21a59a
Show file tree
Hide file tree
Showing 62 changed files with 1,327 additions and 1,424 deletions.
224 changes: 224 additions & 0 deletions Datadog.Trace.Minimal.sln

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ Component,Origin,License,Copyright
opentracing-csharp,https://github.com/opentracing/opentracing-csharp,MIT,Copyright 2016-2017 The OpenTracing Authors
msgpack-cli,https://github.com/msgpack/msgpack-cli,Apache-2.0,"Copyright 2010-2016 FUJIWARA, Yusuke, all rights reserved."
liblog,https://github.com/damianh/LibLog,MIT,Copyright (C) 2011-2017 Damian Hickey
coreclr,https://github.com/dotnet/coreclr,MIT,Copyright (c) .NET Foundation and contributors. All rights reserved.
dotnet/runtime,https://github.com/dotnet/runtime,MIT,Copyright (c) .NET Foundation and contributors. All rights reserved.
clr-samples,https://github.com/Microsoft/clr-samples,MIT,Copyright (c) .NET Foundation and contributors. All rights reserved.
clrprofiler,https://github.com/MicrosoftArchive/clrprofiler,MIT,Copyright (c) Microsoft Corporation. All rights reserved.
JSON for Modern C++,https://github.com/nlohmann/json,MIT,Copyright (c) 2013-2018 Niels Lohmann
Sigil,https://github.com/kevin-montrose/Sigil,MS-PL,2013-2016 Kevin Montrose
miniutf,https://github.com/dropbox/miniutf,MIT,"Copyright (c) 2013 Dropbox, Inc."
Serilog,https://github.com/serilog/serilog,Apache-2.0,"Copyright (c) 2013-2018 Serilog Contributors"
Serilog.Sinks.File,https://github.com/serilog/serilog-sinks-file,Apache-2.0,"Copyright (c) 2016 Serilog Contributors"
opentracing-contrib/csharp-netcore,https://github.com/opentracing-contrib/csharp-netcore,Apache-2.0,
274 changes: 0 additions & 274 deletions integrations.json
Original file line number Diff line number Diff line change
@@ -1,278 +1,4 @@
[
{
"name": "AspNetCoreMvc2",
"method_replacements": [
{
"caller": {
"assembly": "Microsoft.AspNetCore.Mvc.Core"
},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Internal.MvcCoreDiagnosticSourceExtensions",
"method": "BeforeAction",
"signature_types": [
"System.Void",
"_",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.HttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "BeforeAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {
"assembly": "Microsoft.AspNetCore.Mvc.Core"
},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Internal.MvcCoreDiagnosticSourceExtensions",
"method": "AfterAction",
"signature_types": [
"System.Void",
"_",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.HttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "AfterAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {
"assembly": "Microsoft.AspNetCore.Mvc.Core"
},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker",
"method": "Rethrow",
"signature_types": [
"System.Void",
"_"
],
"minimum_major": 2,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 2,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc2Integration",
"method": "Rethrow",
"signature": "00 04 01 1C 08 08 0A"
}
}
]
},
{
"name": "AspNetCoreMvc3",
"method_replacements": [
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.MvcCoreDiagnosticListenerExtensions",
"method": "BeforeAction",
"signature_types": [
"System.Void",
"System.Diagnostics.DiagnosticListener",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.DefaultHttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "BeforeAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.MvcCoreDiagnosticListenerExtensions",
"method": "BeforeAction",
"signature_types": [
"System.Void",
"System.Diagnostics.DiagnosticListener",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.HttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "BeforeAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.MvcCoreDiagnosticListenerExtensions",
"method": "AfterAction",
"signature_types": [
"System.Void",
"System.Diagnostics.DiagnosticListener",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.DefaultHttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "AfterAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.MvcCoreDiagnosticListenerExtensions",
"method": "AfterAction",
"signature_types": [
"System.Void",
"System.Diagnostics.DiagnosticListener",
"Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor",
"Microsoft.AspNetCore.Http.HttpContext",
"Microsoft.AspNetCore.Routing.RouteData"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "AfterAction",
"signature": "00 07 01 1C 1C 1C 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker",
"method": "Rethrow",
"signature_types": [
"System.Void",
"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+ResourceExecutedContextSealed"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "Rethrow_ResourceExecutedContextSealed",
"signature": "00 04 01 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker",
"method": "Rethrow",
"signature_types": [
"System.Void",
"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+ExceptionContextSealed"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "Rethrow_ExceptionContextSealed",
"signature": "00 04 01 1C 08 08 0A"
}
},
{
"caller": {},
"target": {
"assembly": "Microsoft.AspNetCore.Mvc.Core",
"type": "Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker",
"method": "Rethrow",
"signature_types": [
"System.Void",
"Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker+ResultExecutedContextSealed"
],
"minimum_major": 3,
"minimum_minor": 0,
"minimum_patch": 0,
"maximum_major": 3,
"maximum_minor": 65535,
"maximum_patch": 65535
},
"wrapper": {
"assembly": "Datadog.Trace.ClrProfiler.Managed, Version=1.11.1.0, Culture=neutral, PublicKeyToken=def86d061d0d2eeb",
"type": "Datadog.Trace.ClrProfiler.Integrations.AspNetCoreMvc3Integration",
"method": "Rethrow_ResultExecutedContextSealed",
"signature": "00 04 01 1C 08 08 0A"
}
}
]
},
{
"name": "AspNetMvc",
"method_replacements": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('netcoreapp')) ">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('netcoreapp')) ">
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project>
5 changes: 0 additions & 5 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<Project>
<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net452;net461;netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.1;netcoreapp3.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<Import Project="..\Test.Common.props" />
</Project>
20 changes: 20 additions & 0 deletions samples/Samples.AspNetCore31/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Samples.AspNetCore31
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
44 changes: 44 additions & 0 deletions samples/Samples.AspNetCore31/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54570",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",

"CORECLR_ENABLE_PROFILING": "1",
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}",
"CORECLR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll",

"DD_DOTNET_TRACER_HOME": "$(ProjectDir)$(OutputPath)profiler-lib",
"DD_INTEGRATIONS": "$(ProjectDir)$(OutputPath)profiler-lib\\integrations.json"
},
"use64Bit": true,
"nativeDebugging": true
},
"Samples.AspNetCore31": {
"commandName": "Project",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",

"CORECLR_ENABLE_PROFILING": "1",
"CORECLR_PROFILER": "{846F5F1C-F9AE-4B07-969E-05C26BC060D8}",
"CORECLR_PROFILER_PATH": "$(ProjectDir)$(OutputPath)profiler-lib\\Datadog.Trace.ClrProfiler.Native.dll",

"DD_DOTNET_TRACER_HOME": "$(ProjectDir)$(OutputPath)profiler-lib",
"DD_INTEGRATIONS": "$(ProjectDir)$(OutputPath)profiler-lib\\integrations.json"
},
"nativeDebugging": true,
"applicationUrl": "http://localhost:54571"
}
}
}
Loading

0 comments on commit e21a59a

Please sign in to comment.