RabbitMQ.Client.OpenTelemetry
1.0.0-rc.3
dotnet add package RabbitMQ.Client.OpenTelemetry --version 1.0.0-rc.3
NuGet\Install-Package RabbitMQ.Client.OpenTelemetry -Version 1.0.0-rc.3
<PackageReference Include="RabbitMQ.Client.OpenTelemetry" Version="1.0.0-rc.3" />
<PackageVersion Include="RabbitMQ.Client.OpenTelemetry" Version="1.0.0-rc.3" />
<PackageReference Include="RabbitMQ.Client.OpenTelemetry" />
paket add RabbitMQ.Client.OpenTelemetry --version 1.0.0-rc.3
#r "nuget: RabbitMQ.Client.OpenTelemetry, 1.0.0-rc.3"
#:package RabbitMQ.Client.OpenTelemetry@1.0.0-rc.3
#addin nuget:?package=RabbitMQ.Client.OpenTelemetry&version=1.0.0-rc.3&prerelease
#tool nuget:?package=RabbitMQ.Client.OpenTelemetry&version=1.0.0-rc.3&prerelease
RabbitMQ .NET Client - OpenTelemetry Instrumentation
Introduction
This library makes it easy to instrument your RabbitMQ .NET Client applications with OpenTelemetry.
Examples
The following examples demonstrate how to use the RabbitMQ .NET Client OpenTelemetry Instrumentation.
Basic Usage
ASP.NET Core Configuration Example
using OpenTelemetry.Trace;
// Configure the OpenTelemetry SDK to trace ASP.NET Core, the RabbitMQ .NET Client and export the traces to the console.
// Also configures context propagation to propagate the TraceContext and Baggage using the W3C specification.
var compositeTextMapPropagator = new CompositeTextMapPropagator(new TextMapPropagator[]
{
new TraceContextPropagator(),
new BaggagePropagator()
});
Sdk.SetDefaultTextMapPropagator(compositeTextMapPropagator);
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource
.AddService(serviceName: builder.Environment.ApplicationName))
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddRabbitMQInstrumentation()
.AddConsoleExporter());
Console Application Configuration Example
using OpenTelemetry.Trace;
// Configure the OpenTelemetry SDK to trace ASP.NET Core, the RabbitMQ .NET Client and export the traces to the console.
// Also configures context propagation to propagate the TraceContext and Baggage using the W3C specification.
var compositeTextMapPropagator = new CompositeTextMapPropagator(new TextMapPropagator[]
{
new TraceContextPropagator(),
new BaggagePropagator()
});
Sdk.SetDefaultTextMapPropagator(compositeTextMapPropagator);
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddRabbitMQInstrumentation()
.AddConsoleExporter()
.Build();
Options
RabbitMQTracingOptions shapes the spans this client produces. Pass a configuration action to
AddRabbitMQInstrumentation:
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddRabbitMQInstrumentation(options =>
{
// Append the destination to publish, delivery and fetch span names, for example
// "publish my-exchange:my.routing.key". Set this to false where a high-cardinality
// routing key or a server-named queue would make span names unusable as an
// aggregation key. Default: true.
options.UseRoutingKeyAsOperationName = true;
// Parent a delivery span to the trace context the publisher propagated in the
// message, so a publish and the deliveries it causes form a single trace.
// Default: true.
options.UsePublisherAsParent = true;
})
.AddConsoleExporter()
.Build();
Scope of the configuration
Tracing configuration is process-wide, not per-TracerProvider. AddRabbitMQInstrumentation
writes the static members of RabbitMQActivitySource, which every connection in the process reads.
So when more than one TracerProvider configures the client, the last call wins, and disposing a
provider does not restore what it replaced.
This is a property of the model rather than an implementation shortcut: one ActivitySource
produces a single Activity shared by every listener, and one publish injects a single set of
headers, so neither span shape nor propagated context can differ per provider.
A factory can carry its own configuration, though, and that is the recommended way. Set
ConnectionFactory.TracingOptions, or call UseOpenTelemetryTracing on the factory, and the
connections it creates use that instead of the process-wide default:
factory.UseOpenTelemetryTracing(options =>
options.UseRoutingKeyAsOperationName = true);
Every member of ConnectionTracingOptions is nullable and null means inherit, resolved per
member, so setting one span-shaping flag leaves whatever propagation is configured process-wide
untouched. Propagator takes a System.Diagnostics.DistributedContextPropagator; this package
supplies OpenTelemetryPropagator, which bridges OpenTelemetry's own TextMapPropagator and is
what UseOpenTelemetryTracing installs for you. To extend it rather than replace it, decorate what
is already there:
factory.UseOpenTelemetryTracing(options =>
options.Propagator = new MyDecorator(options.Propagator));
Three consequences worth planning around:
- Call
AddRabbitMQInstrumentationfrom one place. Two providers configured with different options will not each get their own. RabbitMQActivitySource.ContextInjector,ContextExtractor,UseRoutingKeyAsOperationNameandTracingOptionsare[Obsolete]as of 7.3.0. They still work and will be removed in a future major version; preferConnectionFactory.TracingOptions.- If you do configure the process-wide default directly, save and restore the previous values
yourself if you need them back. Assigning
nulltoContextInjector,ContextExtractor, orTracingOptionsthrowsArgumentNullException.
What is emitted
Three activity sources, all subscribed by AddRabbitMQInstrumentation through the
RabbitMQ.Client.* wildcard:
| Source | Spans |
|---|---|
RabbitMQ.Client.Publisher |
publish |
RabbitMQ.Client.Subscriber |
deliver, fetch |
RabbitMQ.Client.Connection |
connection attempt, tcp connection attempt |
Spans follow the OpenTelemetry messaging semantic conventions.
Span names are {operation} {destination}, where the destination is
messaging.destination.name - {exchange}:{routing key} for a publish and
{exchange}:{routing key}:{queue} for a basic.get, with empty parts omitted. A deliver span
carries the two-part {exchange}:{routing key} form, because a delivery frame does not carry the
queue it came from; see
#2055. Set
UseRoutingKeyAsOperationName to false for bare operation names, which is what you want when a
high-cardinality routing key or a server-named queue would make span names unusable as an
aggregation key.
An empty basic.get emits the same fetch operation name as one that returned a message, with
messaging.rabbitmq.message.received set to false; encoding the outcome in
messaging.operation.name is not valid, so the fetch (empty) name was removed in 7.3.0. fetch
spans are CLIENT, matching the convention's mapping of receive; deliveries are CONSUMER. The
delivery tag is messaging.rabbitmq.message.delivery_tag, which is the registry name - it was
messaging.rabbitmq.delivery_tag before 7.3.0 and matched nothing in the convention.
A failed operation sets the span status to Error along with error.type and an exception event.
By default a delivery span is parented to the message creation context the publisher propagated.
Whenever a context is extracted it is also attached to the delivery span as a link, in both modes,
so UsePublisherAsParent = false drops the parent and leaves the link rather than swapping one for
the other.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- OpenTelemetry.Api (>= 1.15.3)
- RabbitMQ.Client (>= 7.3.0)
-
net8.0
- OpenTelemetry.Api (>= 1.15.3)
- RabbitMQ.Client (>= 7.3.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RabbitMQ.Client.OpenTelemetry:
| Package | Downloads |
|---|---|
|
Stratara.ServiceDefaults
Observability defaults for the Stratara stack — ConfigureOpenTelemetry (HTTP, EF Core, RabbitMQ, runtime instrumentation; OTLP exporter) and ConfigureSerilog (structured logging, OTLP sink). Reference from every host. |
|
|
FastTechFoods.Observability
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-rc.3 | 0 | 11/23/2026 |
| 1.0.0-rc.2 | 847,520 | 11/14/2025 |
| 1.0.0-rc.1 | 1,089,123 | 6/4/2024 |