Skip to content

Appending with Tags

Chronicle lets you associate tags with appended events. Tags are stored as event metadata and can be used for categorization, filtering, and concurrency scoping.

Chronicle maintains built-in metadata tags for event identity and stream routing:

  • EventSourceType
  • EventSourceId
  • EventStreamType
  • EventStreamId

You can add custom tags in addition to these built-in tags. For the full list and behavior, see Event Metadata Tags.

Custom tags are simple strings that you provide when appending. They are merged with any static tags defined on the event type.

using Cratis.Chronicle.Events;
[EventType]
public record TaggedOrderPlaced(string CustomerId, decimal Total);
public class TaggedCheckoutService(IEventLog eventLog)
{
public Task<AppendResult> PlaceOrder(OrderId orderId, string customerId, decimal total)
{
return eventLog.Append(
orderId,
new TaggedOrderPlaced(customerId, total),
tags: ["checkout", "priority"]);
}
}

AppendMany applies the provided tags to each event in the batch.

using Cratis.Chronicle.EventSequences;
using Cratis.Chronicle.Events;
public readonly record struct TaggedAccountId(string Value)
{
public static implicit operator EventSourceId(TaggedAccountId id) => new(id.Value);
}
[EventType]
public record TaggedMoneyWithdrawn(decimal Amount);
[EventType]
public record TaggedMoneyDeposited(decimal Amount);
public class TaggedTransferService(IEventLog eventLog)
{
public Task<AppendManyResult> Transfer(TaggedAccountId fromAccount, TaggedAccountId toAccount, decimal amount)
{
var events = new[]
{
new EventForEventSourceId(fromAccount, new TaggedMoneyWithdrawn(amount)),
new EventForEventSourceId(toAccount, new TaggedMoneyDeposited(amount))
};
return eventLog.AppendMany(events, tags: ["transfer", "audit"]);
}
}