Skip to content

Event Annotations

NEWDAY\N17781 edited this page Mar 23, 2026 · 25 revisions

Event & Message Tracking

Requests can be marked with RequestResponseMetaType.Event to give them special styling in diagrams. Event-annotated notes are rendered with:

  • A light blue background (#cfecf7)
  • Smaller font size (11px)
  • Rounded corners

This is useful for distinguishing asynchronous events, webhooks, or message bus interactions from standard HTTP request/response flows.

MessageTracker

The MessageTracker class makes it easy to log non-HTTP interactions — such as events, messages, or commands sent via Kafka, EventGrid, RabbitMQ, SNS, or any other transport — so they appear in the generated sequence diagrams alongside regular HTTP traffic.

Registration

Register MessageTracker in your WebApplicationFactory startup, alongside your existing tracking setup:

builder.ConfigureTestServices(services =>
{
    services.TrackDependenciesForDiagrams(new XUnitTestTrackingMessageHandlerOptions { ... });
    services.TrackMessagesForDiagrams(callingServiceName: "My API");
});

This registers MessageTracker as a singleton in DI, along with IHttpContextAccessor (needed to read test-tracking headers from the current request context).

Usage

Inject MessageTracker into any fake or stub that simulates publishing or sending messages. Call TrackMessageRequest when the message is sent, and TrackMessageResponse when the publish completes:

public class FakeEventPublisher : IEventPublisher
{
    private readonly MessageTracker _tracker;

    public FakeEventPublisher(MessageTracker tracker)
    {
        _tracker = tracker;
    }

    public Task PublishAsync(OrderCreatedEvent @event)
    {
        var correlationId = _tracker.TrackMessageRequest(
            protocol: "Kafka",
            destinationName: "Order Service",
            destinationUri: new Uri("kafka://order-events"),
            payload: @event);

        _tracker.TrackMessageResponse(
            protocol: "Kafka",
            destinationName: "Order Service",
            destinationUri: new Uri("kafka://order-events"),
            requestResponseId: correlationId);

        return Task.CompletedTask;
    }
}

Parameters

Parameter Description
protocol The transport label shown in the diagram (e.g. "Kafka", "EventGrid", "SNS", "RabbitMQ").
destinationName The name of the destination service or topic shown in the diagram.
destinationUri A URI representing the destination (e.g. new Uri("kafka://order-events")).
payload The message payload — serialised to JSON and shown in the diagram note.
requestResponseId The correlation ID returned by TrackMessageRequest, used to pair the request and response.
responsePayload Optional response payload for TrackMessageResponse (e.g. an acknowledgement).

Custom JSON Serialisation

If your payloads require specific serialisation settings, pass JsonSerializerOptions to the registration:

services.TrackMessagesForDiagrams(
    callingServiceName: "My API",
    serializerOptions: new JsonSerializerOptions { WriteIndented = true });

Home


Demo


Getting Started

Common Tasks

Integration Guides

Extensions

Configuration

Features

Reference

Clone this wiki locally