OpenTracing instrumentation for .NET Core apps
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Allows building the solution with CTRL+Shift+B in VSCode Sep 10, 2018
benchmarks/OpenTracing.Contrib.NetCore.Benchmarks Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
samples Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
src Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
test/OpenTracing.Contrib.NetCore.Tests Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
.appveyor.yml Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
.editorconfig Project migrated from cwe1ss/opentracing-contrib-dotnet Mar 1, 2018
.gitattributes Project migrated from cwe1ss/opentracing-contrib-dotnet Mar 1, 2018
.gitignore Benchmark project Mar 15, 2018
.travis.yml Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
Directory.Build.props Sign assemblies; use git tag name for version (#19) May 25, 2018
LICENSE Initial commit Mar 1, 2018
NuGet.config Project migrated from cwe1ss/opentracing-contrib-dotnet Mar 1, 2018
OpenTracing.Contrib.sln Use official Jaeger client instead of custom Zipkin client (#1) (#17) May 20, 2018
README.md Update README.md Oct 15, 2018
RELEASE.md release process improvements Sep 10, 2018
SignKey.snk Sign assemblies; use git tag name for version (#19) May 25, 2018
build.ps1 Sign assemblies; use git tag name for version (#19) May 25, 2018
global.json Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
launch-sample.ps1 Run tests for .NET Core 2.0 and 2.1; Package upgrades (#24) Sep 10, 2018
version.props release process improvements Sep 10, 2018

README.md

OpenTracing instrumentation for .NET Core apps

This repository provides OpenTracing instrumentation for .NET Core based applications. It can be used with any OpenTracing compatible tracer.

Supported .NET versions

This project currently only supports apps targeting netcoreapp2.0 (.NET Core 2.0) or higher!

Supported libraries and frameworks

DiagnosticSource based instrumentation

This project supports any library or framework that uses .NET's DiagnosticSource to instrument its code. It will create a span for every Activity and it will create span.Log calls for all other diagnostic events.

To further improve the tracing output, the library provides enhanced instrumentation (Inject/Extract, tags, configuration options) for the following libraries / frameworks:

  • ASP.NET Core
  • Entity Framework Core
  • .NET Core BCL types (HttpClient)

Microsoft.Extensions.Logging based instrumentation

This project also adds itself as a logger provider for logging events from the Microsoft.Extensions.Logging system. It will create span.Log calls for each logging event, however it will only create them if there is an active span (ITracer.ActiveSpan).

Usage

This project depends on several packages from Microsofts new Microsoft.Extensions.* stack (e.g. Dependency Injection, Logging) so its main use case is ASP.NET Core apps but it's also possible to instrument non-web based .NET Core apps like console apps, background services etc. if they also use this stack.

1. Add the NuGet package OpenTracing.Contrib.NetCore to your project.
2. Add the OpenTracing services to your IServiceCollection via services.AddOpenTracing().

How you do this depends on how you've setup the Microsoft.Extensions.DependencyInjection system in your app.

In ASP.NET Core apps you can add the call to your ConfigureServices method (of your Program.cs file):

public static IWebHost BuildWebHost(string[] args)
{
    return WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureServices(services =>
        {
            // Enables and automatically starts the instrumentation!
            services.AddOpenTracing();
        })
        .Build();
}
3. Make sure InstrumentationService, which implements IHostedService, is started.

InstrumentationService is responsible for starting and stopping the instrumentation. The service implements IHostedService so it is automatically started in ASP.NET Core, however if you have your own console host, you manually have to call StartAsync and StopAsync.

Note that .NET Core 2.1 will greatly simplify this setup by introducing a generic HostBuilder that works similar to the existing WebHostBuilder from ASP.NET Core. Have a look at the TrafficGenerator sample for an example of a HostBuilder based console application.