Skip to content

[Feature]: OpenTelemetry / Diagnostics Integration #222

@eneshoxha

Description

@eneshoxha

Title: Add OpenTelemetry tracing behaviors via System.Diagnostics.Activity

Labels: enhancement, mediator, new-package

Body:

Problem

The built-in logging behaviors use ILogger with Stopwatch for timing. Modern .NET applications expect distributed tracing via System.Diagnostics.Activity and OpenTelemetry. Without this, Cortex.Mediator operations are invisible in distributed traces.

Proposed Solution

Create a Cortex.Mediator.OpenTelemetry package:

  • Define an ActivitySource named Cortex.Mediator
  • TracingCommandBehavior<TCommand, TResult> -- starts an Activity span for command execution
  • TracingQueryBehavior<TQuery, TResult> -- same for queries
  • TracingNotificationBehavior<TNotification> -- same for notifications
  • Tags: mediator.message.type (command/query/notification), mediator.message.name, mediator.handler.name, mediator.result.status (success/failure)
  • Set Activity status to Error on exceptions

Registration:

options.AddOpenTelemetryBehaviors();

// In OpenTelemetry configuration:
builder.Services.AddOpenTelemetry()
    .WithTracing(tracing => tracing.AddSource("Cortex.Mediator"));

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestfeatureThis label is in use for minor version increments

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions