Distributed Tracing
Video
Distributed Tracing
In the Kubernetes/OpenShift world, the de-facto standard for distributed tracing through microservices is OpenTracing and Jaeger. Jaeger and OpenTracing are available as libraries for ASP.NET applications as well.
- Install the OpenTracing packagebash
cd <solution root>/src/RedHat.TodoList dotnet add package OpenTracing.Contrib.NetCore dotnet add package Jaeger.Core
- Enable OpenTracing in your
Startup.cs
file as follows:csharppublic void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddOpenTracing(); // Adds the Jaeger Tracer. services.AddSingleton<ITracer>(serviceProvider => { string serviceName = serviceProvider.GetRequiredService<IWebHostEnvironment>().ApplicationName; // This will log to a default localhost installation of Jaeger. var tracer = new Tracer.Builder(serviceName) .WithSampler(new ConstSampler(true)) .Build(); // Allows code that can't use DI to also access the tracer. GlobalTracer.Register(tracer); return tracer; });
- Now, you can use Environment Variables or settings in
appsettings.json
to configure where to send the tracing data