Monitoring NServiceBus endpoints with Jaeger

Component: NServiceBus
NuGet Package: NServiceBus (8-pre)
This page targets a pre-release version. Pre-releases are subject to change and samples are not guaranteed to be fully functional.

Jaeger is a distributed tracing system for monitoring and troubleshooting distributed systems. This sample demonstrates how to export OpenTelemetry traces from NServiceBus-based systems to Jaeger.

Prerequisites

A Jaeger instance is required to send, process and view OpenTelemetry trace diagnostics. Use the All in one Jaeger container image for development and testing purpose by running the following docker command:

$ docker run -d --name jaeger \
  -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 \
  -p 5775:5775/udp \
  -p 6831:6831/udp \
  -p 6832:6832/udp \
  -p 5778:5778 \
  -p 16686:16686 \
  -p 14268:14268 \
  -p 9411:9411 \
  jaegertracing/all-in-one:1.8

With this default configuration, the Jaeger UI will be available at http://localhost:16686.

Code overview

The sample contains two endpoints exchanging publish-subscribe events and point-to-point messages between each other. To enable tracing and export to Jaeger, the TraceProvider for each endpoint has to be configured as follows:

var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(EndpointName))
    .AddSource("NServiceBus.Core")
    .AddJaegerExporter()
    .Build();

NServiceBus must also enable the OpenTelemetry instrumentation:

var endpointConfiguration = new EndpointConfiguration(EndpointName);

endpointConfiguration.EnableOpenTelemetry();

Running the sample

Run the sample and press 1 on the Publisher endpoint to publish one or more events. Navigate to the Jaeger UI (at http://localhost:16686) to inspect the captured traces:

jaeger search UI

Inspecting a selected trace shows the conversation flow between the Publisher and the Subscriber endpoint:

jaeger trace UI

Related Articles

  • OpenTelemetry
    Observability of NServiceBus endpoints with OpenTelemetry.

Last modified