NServiceBus version 8 and above supports OpenTelemetry through traces, metrics, and logging.
Enable OpenTelemetry instrumentation in NServiceBus:
endpointConfiguration.EnableOpenTelemetry();
With OpenTelemetry instrumentation enabled, tracing, metrics, and logging can be individually configured via the OpenTelemetry API itself.
Traces
NServiceBus endpoints generate OpenTelemetry traces for incoming and outgoing messages. To capture trace information, add the NServiceBus.
activity source to the OpenTelemetry configuration:
var tracingProviderBuilder = Sdk.CreateTracerProviderBuilder()
.AddSource("NServiceBus.Core")
// ... Add other trace sources
// ... Add exporters
.Build();
See the OpenTelemetry samples for instructions on how to send trace information to different tools.
Meters
NServiceBus endpoints can be configured to expose metrics related to message processing. To capture meter information, add the NServiceBus.
meter source to the OpenTelemetry configuration:
var meterProviderProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("NServiceBus.Core")
// ... Add other meters
// ... Add exporters
.Build();
Emitted meters
nservicebus.
- Total number of messages processed successfully by the endpointmessaging. successes nservicebus.
- Total number of messages fetched from the queue by the endpointmessaging. fetches nservicebus.
- Total number of messages processed unsuccessfully by the endpointmessaging. failures
See the OpenTelemetry samples for instructions on how to send metric information to different tools.
Logging
NServiceBus supports logging out of the box. To collect OpenTelemetry-compatible logging in NServiceBus endpoints, it's possible to configure the endpoint to connect traces and logging when using Microsoft.
package. See the Connecting OpenTelemetry traces and logs sample for more details.