Muflone.OpenTelemetry 10.0.0-beta1

This is a prerelease version of Muflone.OpenTelemetry.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Muflone.OpenTelemetry --version 10.0.0-beta1
                    
NuGet\Install-Package Muflone.OpenTelemetry -Version 10.0.0-beta1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Muflone.OpenTelemetry" Version="10.0.0-beta1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muflone.OpenTelemetry" Version="10.0.0-beta1" />
                    
Directory.Packages.props
<PackageReference Include="Muflone.OpenTelemetry" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Muflone.OpenTelemetry --version 10.0.0-beta1
                    
#r "nuget: Muflone.OpenTelemetry, 10.0.0-beta1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Muflone.OpenTelemetry@10.0.0-beta1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muflone.OpenTelemetry&version=10.0.0-beta1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muflone.OpenTelemetry&version=10.0.0-beta1&prerelease
                    
Install as a Cake Tool

Muflone.OpenTelemetry

OpenTelemetry instrumentation for the Muflone CQRS framework, enabling distributed tracing across command and event processing pipelines.

Installation

Install via NuGet:

dotnet add package Muflone.OpenTelemetry

Requirements

  • .NET 10.0 or higher
  • Muflone framework
  • OpenTelemetry.Api 1.15.0+

Quick Start

1. Configure OpenTelemetry

Add Muflone instrumentation to your OpenTelemetry configuration:

using OpenTelemetry.Trace;

var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddMufloneInstrumentation()  // Enable Muflone tracing
    .AddConsoleExporter()         // Or any other exporter (Jaeger, Zipkin, etc.)
    .Build();

2. Inject Trace Context (Producers)

When sending commands or publishing events, inject the current trace context:

using Muflone.Messages;

// In your command sender
var command = new CreateOrderCommand { OrderId = orderId };
command.InjectTraceContext();  // Inject W3C trace context
await commandSender.SendAsync(command);

3. Start Consumer Activities (Handlers)

In your command or event handlers, start a consumer activity to continue the trace:

using Muflone.Messages;
using Muflone.Messages.Commands;

public class CreateOrderCommandHandler : ICommandHandlerAsync<CreateOrderCommand>
{
    public async Task HandleAsync(CreateOrderCommand command)
    {
        // Start consumer activity - automatically extracts parent context
        using var activity = command.StartConsumerActivity();
        
        // Your handler logic here
        await CreateOrder(command.OrderId);
        
        // Activity automatically completes when disposed
    }
}

4. Start Producer Activities (Event Publishers)

When publishing domain or integration events:

using Muflone.Messages;
using Muflone.Messages.Events;

public class OrderService
{
    private readonly IEventBus _eventBus;
    
    public async Task ProcessOrder(Order order)
    {
        var @event = new OrderCreatedEvent { OrderId = order.Id };
        
        // Start producer activity for outgoing event
        using var activity = @event.StartProducerActivity();
        @event.InjectTraceContext();  // Inject context for downstream consumers
        
        await _eventBus.PublishAsync(@event);
    }
}

API Reference

AddMufloneInstrumentation()

Extension method on TracerProviderBuilder to enable Muflone tracing.

TracerProviderBuilder AddMufloneInstrumentation(this TracerProviderBuilder builder)

InjectTraceContext()

Extension method on IMessage to inject the current W3C trace context into the message's UserProperties.

void InjectTraceContext(this IMessage message)

Behavior:

  • Stores Activity.Current.Id in UserProperties["traceparent"]
  • Stores Activity.Current.TraceStateString in UserProperties["tracestate"] (if present)
  • No-op if no active activity exists

StartConsumerActivity()

Extension method on IEvent to start a consumer activity with automatic parent context extraction.

Activity? StartConsumerActivity(this IEvent @event, string? activityName = null)

Parameters:

  • activityName: Optional custom activity name (defaults to event type name)

Returns:

  • The started Activity, or null if activities are disabled

Behavior:

  • Creates ActivityKind.Consumer activity
  • Automatically extracts parent context from UserProperties["traceparent"] and UserProperties["tracestate"]
  • Uses event type name as activity name if not specified

StartProducerActivity()

Extension method on ICommand to start a producer activity with automatic parent context extraction.

Activity? StartProducerActivity(this ICommand command, string? activityName = null)

Parameters:

  • activityName: Optional custom activity name (defaults to command type name)

Returns:

  • The started Activity, or null if activities are disabled

Behavior:

  • Creates ActivityKind.Producer activity
  • Automatically extracts parent context from UserProperties["traceparent"] and UserProperties["tracestate"]
  • Uses command type name as activity name if not specified

Trace Propagation

This package uses the W3C Trace Context standard for propagation:

  • traceparent: Contains the trace ID, parent span ID, and trace flags
  • tracestate: Optional vendor-specific trace information

Both values are stored as strings in the message's UserProperties dictionary and are compatible with standard OpenTelemetry propagators.

Complete Example

using Muflone.Messages;
using Muflone.Messages.Commands;
using Muflone.Messages.Events;
using OpenTelemetry.Trace;
using OpenTelemetry;

// Configure OpenTelemetry
var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddMufloneInstrumentation()
    .AddConsoleExporter()
    .Build();

// Command sender
public class OrderController
{
    private readonly ICommandSender _commandSender;
    
    public async Task CreateOrder(CreateOrderRequest request)
    {
        var command = new CreateOrderCommand 
        { 
            OrderId = Guid.NewGuid(),
            CustomerId = request.CustomerId 
        };
        
        // Start producer activity and inject context
        using var activity = command.StartProducerActivity();
        command.InjectTraceContext();
        
        await _commandSender.SendAsync(command);
    }
}

// Command handler
public class CreateOrderCommandHandler : ICommandHandlerAsync<CreateOrderCommand>
{
    private readonly IEventBus _eventBus;
    
    public async Task HandleAsync(CreateOrderCommand command)
    {
        // Start consumer activity - continues the trace
        using var activity = command.StartConsumerActivity();
        
        // Business logic
        var order = await CreateOrderInDatabase(command);
        
        // Publish event with trace context
        var @event = new OrderCreatedEvent { OrderId = order.Id };
        using var publishActivity = @event.StartProducerActivity();
        @event.InjectTraceContext();
        
        await _eventBus.PublishAsync(@event);
    }
}

// Event handler
public class OrderCreatedEventHandler : IEventHandlerAsync<OrderCreatedEvent>
{
    public async Task HandleAsync(OrderCreatedEvent @event)
    {
        // Continue the distributed trace
        using var activity = @event.StartConsumerActivity();
        
        // Handle event
        await SendConfirmationEmail(@event.OrderId);
    }
}

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.1.0 80 3/1/2026
10.1.0-rc1 109 2/12/2026
10.1.0-beta1 80 2/9/2026
10.0.0 111 1/25/2026 10.0.0 is deprecated because it has critical bugs.
10.0.0-beta1 94 1/25/2026