Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Monitoring NServiceBus endpoints with Jaeger

Component: NServiceBus
NuGet Package: NServiceBus (9.x)

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 --name jaeger \
  -e COLLECTOR_OTLP_ENABLED=true \
  -p 16686:16686 \
  -p 4317:4317 \
  -p 4318:4318 \
  jaegertracing/all-in-one:latest

With this default configuration, the Jaeger UI will be available at http://localhost:16686 and the OTEL Collector is set up to listen on the default ports, 4317 (gRPC) 4318 (http).

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*")
    .AddOtlpExporter() // The exporter defaults to gRPC on over port 4317 - https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/README.md#otlpexporteroptions
    .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.