Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Monitoring NServiceBus endpoints with Application Insights

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

Azure Application Insights (App Insights) provides monitoring and alerting capabilities that can be leveraged to monitor the health of NServiceBus endpoints.

This sample shows how to capture NServiceBus OpenTelemetry traces and export them to App Insights. The sample simulates message load as well as a 10% failure rate on processing messages.

Prerequisites

This sample requires an App Insights connection string.

Running the sample

  1. Create an Application Insights resource in Azure
  2. Copy the connection string from the Azure portal dashboard into the sample
  3. Start the sample endpoint
  4. Press any key to send a message, or ESC to quit

Reviewing traces

  1. On the Azure portal dashboard, open the InvestigatePerformance panel
  2. Drill into the samples
  3. Review the custom properties

Timeline view of a trace in Application Insights

Reviewing meters

Navigate to MonitoringMetrics on the Azure portal dashboard for the configured Application Insight instance to start creating graphs.

Message processing counters

To monitor the rate of messages being fetched from the queuing system, processed successfully, retried, and failed for the endpoint use:

  • nservicebus.messaging.fetches
  • nservicebus.messaging.successes
  • nservicebus.messaging.failures

Graph showing fetched, success, and failed counters in Application Insights

Recoverability

To monitor recoverability metrics use:

  • nservicebus.recoverability.immediate
  • nservicebus.recoverability.delayed
  • nservicebus.recoverability.error

Graph showing recoverability metrics in Application Insights

Handler time, critical time, and processing time

To monitor handler time, processing time, and critical time (in seconds) for successfully processed messages use:

  • nservicebus.messaging.handler_time
  • nservicebus.messaging.processing_time
  • nservicebus.messaging.critical_time

Graph showing processing time and critical time metrics in Application Insights

Code walk-through

The OpenTelemetry instrumentation is enabled on the endpoint.

var endpointConfiguration = new EndpointConfiguration(endpointName);
endpointConfiguration.EnableOpenTelemetry();

Tracing

The endpoint configures an OpenTelemetry trace provider that includes the NServiceBus.Core source and exports collected traces to Azure Monitor.

var traceProvider = Sdk.CreateTracerProviderBuilder()
    .SetResourceBuilder(resourceBuilder)
    .AddSource("NServiceBus.Core")
    .AddAzureMonitorTraceExporter(o => o.ConnectionString = appInsightsConnectionString)
    .AddConsoleExporter()
    .Build();

Meters

The endpoint configures an OpenTelemetry meter provider that includes the NServiceBus.Core meter and exports metric data to Azure Monitor.

var meterProvider = Sdk.CreateMeterProviderBuilder()
    .SetResourceBuilder(resourceBuilder)
    .AddMeter("NServiceBus.Core")
    .AddAzureMonitorMetricExporter(o => o.ConnectionString = appInsightsConnectionString)
    .AddConsoleExporter()
    .Build();

Related Articles

  • OpenTelemetry
    Observability of NServiceBus endpoints with OpenTelemetry.