By default, our communication Ev.ServiceBus uses Activity enrichment for OpenTelemetry instrumentation. this includes renaming the Activity name to
$"{ClientType}/{ResourceId}/{PayloadTypeId}"
Examples
Queue/MyQueueName/MyPayloadType
Subscription/MyTopicName/Subscriptions/MySubscriptionName/MyPayloadType
Note : For our activity extension to work you need to configure your OpenTelemetry tracing to enable Azure Activity Source
Alternatively, you can use Elastic APM for instrumentation by utilizing the Ev.ServiceBus.Apm as following.
services.AddServiceBus(settings => {
settings.Enabled = true;
settings.ReceiveMessages = true;
settings.WithConnection("", new ServiceBusClientOptions());
}).UseApm();Ev.ServiceBus includes built-in metrics support through ServiceBusMeter, which provides the following metrics:
ev.servicebus.messages.sent: Counter for total number of messages sent to the service busev.servicebus.messages.received: Counter for total number of messages received from the service busev.servicebus.messages.delivery.count: Histogram tracking delivery attempts for a messageev.servicebus.message.queue.latency: Histogram measuring time a message spends in queue (ms)
These metrics include labels: clientType, resourceId, and payloadTypeId for detailed analysis.
To collect these metrics with OpenTelemetry, add the Ev.ServiceBus meter to your OpenTelemetry configuration:
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddMeter("Ev.ServiceBus");
});To export metrics to Prometheus:
- Install the
Ev.ServiceBus.Prometheuspackage - Register the
ServicebusPrometheusExporteras a hosted service:
builder.Services.AddHostedService<ServicebusPrometheusExporter>();- Configure the Prometheus HTTP endpoint in your application:
app.UseMetricServer();
app.UseHttpMetrics();This will expose your metrics at the default /metrics endpoint that can be scraped by Prometheus.