Tag Chronicle events and observer definitions
Tags in Cratis Chronicle serve two different tasks: event tags help you select stored events or filter delivery, while descriptive tags label observer and read-model definitions. Use named event tags when you need to find the events from a particular batch, run or session.
Overview
Section titled “Overview”Plain tags are strings such as analytics or customer.registration. Event types can declare them through attributes, and an append can add more at runtime. Reactors, reducers and projections are observers: they process appended events. Tags on their definitions describe their responsibility; they do not select the events they process. Read-model definitions can carry descriptive tags too.
In .NET, [Tag] and [Tags] are interchangeable ways to declare plain tags. You can mix the two attributes; Chronicle merges their tags.
A named tag keeps a name and value separate, such as import-batch = 4711. Use this form for a runtime identifier rather than encoding it into a plain tag.
Tagging events
Section titled “Tagging events”Choose static tags for categories that belong to every event of a type. Add dynamic tags when the category depends on the operation appending the event.
Static event tags
Section titled “Static event tags”Declare tags on the event type so appends include them without repeating them at each call site:
using Cratis.Chronicle;using Cratis.Chronicle.Events;
[EventType][Tag("analytics", "user-action")]public record TaggingUserLoggedIn(string UserId, DateTimeOffset LoggedInAt);
// [Tags] (plural) is equivalent to [Tag] — use whichever reads more naturally[EventType][Tags("analytics", "user-action")]public record TaggingUserLoggedInAlternate(string UserId, DateTimeOffset LoggedInAt);
// Mixing [Tag] and [Tags] on the same type merges all the tags[EventType][Tag("security")][Tags("audit")]public record TaggingUserPasswordChanged(string UserId, DateTimeOffset ChangedAt);Kotlin does not support this workflow yet.Java does not support this workflow yet.defmodule MyApp.Events.TaggingStaticUserLoggedIn do use Cratis.Chronicle.Events.EventType, id: "tagging-static-user-logged-in", tags: ["analytics", "user-action"]
defstruct [:user_id, :logged_in_at]end
# There is one `tags:` option: list every tag the event type carries in it.defmodule MyApp.Events.TaggingStaticUserPasswordChanged do use Cratis.Chronicle.Events.EventType, id: "tagging-static-user-password-changed", tags: ["security", "audit"]
defstruct [:user_id, :changed_at]endimport { eventType, tag, tags } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()@tag('analytics', 'user-action')class TaggingUserLoggedIn { @field(String) readonly userId: string; @field(Date) readonly loggedInAt: Date;
constructor(userId: string, loggedInAt: Date) { this.userId = userId; this.loggedInAt = loggedInAt; }}
// @tags() (plural) is equivalent to @tag() — use whichever reads more naturally@eventType()@tags('analytics', 'user-action')class TaggingUserLoggedInAlternate { @field(String) readonly userId: string; @field(Date) readonly loggedInAt: Date;
constructor(userId: string, loggedInAt: Date) { this.userId = userId; this.loggedInAt = loggedInAt; }}
// Mixing @tag() and @tags() on the same type merges all the tags@eventType()@tag('security')@tags('audit')class TaggingUserPasswordChanged { @field(String) readonly userId: string; @field(Date) readonly changedAt: Date;
constructor(userId: string, changedAt: Date) { this.userId = userId; this.changedAt = changedAt; }}Dynamic event tags
Section titled “Dynamic event tags”When appending events, you can provide additional tags that will be merged with any static tags:
using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;
public class TaggingUserLoginService(IEventLog eventLog){ public Task RecordLogin(EventSourceId eventSourceId) => // The event will end up with four tags: ["analytics", "user-action", "production", "critical"] eventLog.Append( eventSourceId, new TaggingUserLoggedIn("user123", DateTimeOffset.UtcNow), tags: ["production", "critical"]);}import io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.events.EventType
@EventTypedata class TaggingUserLoggedIn(val userId: String)
class TaggingUserLoginService(private val eventLog: IEventLog) { suspend fun recordLogin(eventSourceId: String) { eventLog.append( eventSourceId, TaggingUserLoggedIn("user123"), AppendOptions(tags = listOf("production", "critical")) ) }}import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;
@EventTyperecord TaggingUserLoggedIn(String userId) {}
class TaggingUserLoginService { private final IEventLog eventLog;
TaggingUserLoginService(IEventLog eventLog) { this.eventLog = eventLog; }
void recordLogin(String eventSourceId) { EventLogJavaBridge.append( eventLog, eventSourceId, new TaggingUserLoggedIn("user123"), new AppendOptionsBuilder().tag("production").tag("critical").build()); }}defmodule MyApp.Events.TaggingUserLoggedIn do use Cratis.Chronicle.Events.EventType, id: "tagging-user-logged-in"
defstruct [:user_id, :logged_in_at]end
defmodule MyApp.TaggingUserLoginService do alias MyApp.Events.TaggingUserLoggedIn
def record_login(event_source_id, user_id) do # This event type declares no static tags, so the event carries only the two # dynamic tags: ["production", "critical"] Cratis.Chronicle.append( event_source_id, %TaggingUserLoggedIn{user_id: user_id, logged_in_at: DateTime.utc_now()}, tags: ["production", "critical"] ) endendimport { IEventStore } from '@cratis/chronicle';
class TaggingUserLoginService { constructor(private readonly store: IEventStore) {}
// The event will end up with four tags: ['analytics', 'user-action', 'production', 'critical'] async recordLogin(eventSourceId: string): Promise<void> { await this.store.eventLog.append( eventSourceId, new TaggingUserLoggedIn('user123', new Date()), { tags: ['production', 'critical'] }); }}In this example, the event will have four tags: ["analytics", "user-action", "production", "critical"].
Tags in event context
Section titled “Tags in event context”A handler can read the combined static and dynamic tags from EventContext, which carries the event’s metadata:
using System.Linq;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reducers;
public record TaggingUserAnalytics(int LoginCount, int CriticalLoginCount);
public class TaggingUserAnalyticsReducer : IReducerFor<TaggingUserAnalytics>{ public TaggingUserAnalytics LoggedIn(TaggingUserLoggedIn @event, TaggingUserAnalytics? current, EventContext context) { var analytics = current ?? new TaggingUserAnalytics(0, 0);
// Access tags from the event context var isCritical = context.Tags.Any(tag => tag.Value == "critical");
return analytics with { LoginCount = analytics.LoginCount + 1, CriticalLoginCount = analytics.CriticalLoginCount + (isCritical ? 1 : 0) }; }}import io.cratis.chronicle.events.EventContextimport io.cratis.chronicle.observation.Reducerimport io.cratis.chronicle.readModels.ReadModel
@ReadModeldata class TaggingUserAnalytics(val loginCount: Int = 0, val criticalLoginCount: Int = 0)
@Reducerclass TaggingUserAnalyticsReducer { fun loggedIn( event: TaggingUserLoggedIn, current: TaggingUserAnalytics?, context: EventContext ): TaggingUserAnalytics { val analytics = current ?: TaggingUserAnalytics()
// Tags the event was appended with are available on the context. val isCritical = context.tags.contains("critical")
return analytics.copy( loginCount = analytics.loginCount + 1, criticalLoginCount = analytics.criticalLoginCount + if (isCritical) 1 else 0 ) }}import io.cratis.chronicle.events.EventContext;import io.cratis.chronicle.observation.Reducer;import io.cratis.chronicle.readModels.ReadModel;
@ReadModelrecord TaggingUserAnalytics(int loginCount, int criticalLoginCount) { static TaggingUserAnalytics initial() { return new TaggingUserAnalytics(0, 0); }}
@Reducerclass TaggingUserAnalyticsReducer { TaggingUserAnalytics loggedIn(TaggingUserLoggedIn event, TaggingUserAnalytics current, EventContext context) { TaggingUserAnalytics analytics = current != null ? current : TaggingUserAnalytics.initial();
// Tags the event was appended with are available on the context. boolean isCritical = context.getTags().contains("critical");
return new TaggingUserAnalytics( analytics.loginCount() + 1, analytics.criticalLoginCount() + (isCritical ? 1 : 0)); }}defmodule MyApp.ReadModels.TaggingUserAnalytics do use Cratis.Chronicle.ReadModels.ReadModel
defstruct id: nil, login_count: 0, critical_login_count: 0end
defmodule MyApp.Reducers.TaggingUserAnalyticsReducer do use Cratis.Chronicle.Reducers.Reducer, model: MyApp.ReadModels.TaggingUserAnalytics
alias MyApp.Events.TaggingUserLoggedIn alias MyApp.ReadModels.TaggingUserAnalytics
@handles TaggingUserLoggedIn
@impl true def reduce(%TaggingUserLoggedIn{}, model, context) do analytics = model || %TaggingUserAnalytics{id: context.event_source_id}
# Access tags from the event context critical? = "critical" in context.tags
%{ analytics | login_count: analytics.login_count + 1, critical_login_count: analytics.critical_login_count + if(critical?, do: 1, else: 0) } endendimport { EventContext, reducer } from '@cratis/chronicle';
class TaggingUserAnalytics { loginCount = 0; criticalLoginCount = 0;}
@reducer('', undefined, TaggingUserAnalytics)class TaggingUserAnalyticsReducer { taggingUserLoggedIn( event: TaggingUserLoggedIn, current: TaggingUserAnalytics | undefined, context: EventContext ): TaggingUserAnalytics { const analytics = current ?? new TaggingUserAnalytics();
// Access tags from the event context const isCritical = context.tags.some(tag => tag.value === 'critical');
return { loginCount: analytics.loginCount + 1, criticalLoginCount: analytics.criticalLoginCount + (isCritical ? 1 : 0) }; }}Named tags
Section titled “Named tags”A plain tag such as checkout or audit identifies a category. A named tag identifies which import batch, workflow run or checkout session produced an event. Keeping import-batch and 4711 separate lets you query the name with any value, or just the values you need, without parsing a string such as import-batch:4711.
Appending named tags
Section titled “Appending named tags”You supply named tags with AppendWithNamedTags (or AppendManyWithNamedTags for a batch). Unlike plain tags, there is no attribute that declares them on an event type.
using Cratis.Chronicle;using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;
[EventType][Tag("catalog")]public record TaggingCatalogItemImported(string Sku, string Title);
public class TaggingCatalogImportService(IEventLog eventLog){ public Task<AppendResult> Import(EventSourceId itemId, string sku, string title, string batchId) => // Plain tags: ["catalog", "import"] // Named tags: import-batch = <batchId>, source-system = erp eventLog.AppendWithNamedTags( itemId, new TaggingCatalogItemImported(sku, title), namedTags: [new NamedTag("import-batch", batchId), new NamedTag("source-system", "erp")], tags: ["import"]);}import { eventType, IEventStore, NamedTag, tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()@tag('catalog')class TaggingCatalogItemImported { @field(String) readonly sku: string; @field(String) readonly title: string;
constructor(sku: string, title: string) { this.sku = sku; this.title = title; }}
class TaggingCatalogImportService { constructor(private readonly store: IEventStore) {}
// Plain tags: ['catalog', 'import'] // Named tags: import-batch = <batchId>, source-system = erp async import(itemId: string, sku: string, title: string, batchId: string): Promise<void> { await this.store.eventLog.append( itemId, new TaggingCatalogItemImported(sku, title), { namedTags: [new NamedTag('import-batch', batchId), new NamedTag('source-system', 'erp')], tags: ['import'] }); }}Named tags and plain tags are stored separately. The [Tag] attribute and the tags values above still produce plain tags, and a named tag never appears in the plain tag list. Appending with Tags covers batch appends and how per-event and call-level named tags combine.
Names and values
Section titled “Names and values”Names and values compare exactly, using ordinal, case-sensitive matching. Import-Batch and import-batch are different names. A name cannot be empty or whitespace; a value can be empty and can contain separators such as :, . or , because Chronicle does not parse it.
One name can have several values on the same event. Each distinct name/value pair is a separate tag, and exact duplicates are kept once.
Reading named tags
Section titled “Reading named tags”Named tags come back on the EventContext next to the plain tags:
using System.Linq;using Cratis.Chronicle.Events;using Cratis.Chronicle.Reactors;
public class TaggingCatalogImportTracker : IReactor{ public Task Imported(TaggingCatalogItemImported @event, EventContext context) { // Names and values compare exactly (ordinal, case-sensitive). // A name can carry more than one value, so read every match. var batchIds = context.NamedTags .Where(tag => tag.Name.Value == "import-batch") .Select(tag => tag.Value) .ToArray();
Console.WriteLine($"{@event.Sku} imported in batch(es) {string.Join(", ", batchIds)}"); return Task.CompletedTask; }}import { EventContext, reactor } from '@cratis/chronicle';
@reactor()class TaggingCatalogImportTracker { taggingCatalogItemImported(event: TaggingCatalogItemImported, context: EventContext): void { // Names and values compare exactly (case-sensitive). // A name can carry more than one value, so read every match. const batchIds = (context.namedTags ?? []) .filter(tag => tag.name === 'import-batch') .map(tag => tag.value);
console.log(`${event.sku} imported in batch(es) ${batchIds.join(', ')}`); }}Querying by named tag
Section titled “Querying by named tag”The Chronicle server’s event sequence service answers named-tag queries through two operations: QueryEventsWithNamedTags returns a page of events, and SequenceHistogramWithNamedTags returns event counts over time. Each criterion takes one of three forms:
| Criterion | Matches events that carry |
|---|---|
| Name only | The name, with any value |
| Name and a value | Exactly that name and value |
| Name and a set of values | The name with any of those values |
An event matches when it satisfies any one of the criteria. The named-tag criteria then combine with every other filter on the query: event source, event source type, event stream type, correlation ID, event types, plain tags, and the occurred date range. A named-tag query needs at least one criterion, and a criterion with an empty set of values is rejected. Neither case turns into a query that returns everything.
Before you use named tags
Section titled “Before you use named tags”MongoDB, SQL (SQLite, PostgreSQL, and SQL Server), and in-memory storage support named-tag appends and queries. SQL stores them in a companion table named __cratis_named_tags in each event-store namespace database. That name is reserved for Chronicle. If a conflicting table already exists, every event-sequence operation in that namespace fails with NamedTagsTableCollision on first access (migration is lazy) and continues to fail until the conflicting table is renamed.
Tagging observers
Section titled “Tagging observers”Label an observer definition when you want to describe its domain, purpose or owner. These labels stay on the definition rather than becoming event metadata.
Single tag
Section titled “Single tag”Apply one label to the observer:
using Cratis.Chronicle;using Cratis.Chronicle.Reactors;
[Tag("Notifications")]public class TaggingOrderConfirmationReactor : IReactor;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Notifications")@Reactorclass TaggingOrderConfirmationReactor { fun on(event: TaggingOrderConfirmed) { }}
@EventTypedata class TaggingOrderConfirmed(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Notifications")@Reactorclass TaggingOrderConfirmationReactor { void on(TaggingOrderConfirmed event) { }}
@EventTyperecord TaggingOrderConfirmed(String id) {}Elixir does not support this workflow yet.import { reactor, tag } from '@cratis/chronicle';
@reactor()@tag('Notifications')class TaggingOrderConfirmationReactor {}Multiple tags (single attribute)
Section titled “Multiple tags (single attribute)”Both [Tag] and [Tags] accept several labels:
using Cratis.Chronicle;using Cratis.Chronicle.Reactors;
[Tag("Notifications", "Customer", "Email")]public class TaggingCustomerNotificationReactor : IReactor;
// [Tags] (plural) is equivalent — use whichever reads more naturally[Tags("Notifications", "Customer", "Email")]public class TaggingCustomerNotificationReactorAlternate : IReactor;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Notifications", "Customer", "Email")@Reactorclass TaggingCustomerNotificationReactor { fun on(event: TaggingCustomerRegistered) { }}
@EventTypedata class TaggingCustomerRegistered(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag({"Notifications", "Customer", "Email"})@Reactorclass TaggingCustomerNotificationReactor { void on(TaggingCustomerRegistered event) { }}
@EventTyperecord TaggingCustomerRegistered(String id) {}Elixir does not support this workflow yet.import { reactor, tag, tags } from '@cratis/chronicle';
@reactor()@tag('Notifications', 'Customer', 'Email')class TaggingCustomerNotificationReactor {}
// @tags() (plural) is equivalent — use whichever reads more naturally@reactor()@tags('Notifications', 'Customer', 'Email')class TaggingCustomerNotificationReactorAlternate {}Multiple tags (multiple attributes)
Section titled “Multiple tags (multiple attributes)”Repeat the attribute when separate lines make the labels easier to read:
using Cratis.Chronicle;using Cratis.Chronicle.Reactors;
[Tag("Integration")][Tag("ExternalAPI")][Tag("Inventory")]public class TaggingInventorySyncReactor : IReactor;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Integration")@Tag("ExternalAPI")@Tag("Inventory")@Reactorclass TaggingInventorySyncReactor { fun on(event: TaggingInventoryAdjusted) { }}
@EventTypedata class TaggingInventoryAdjusted(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Integration")@Tag("ExternalAPI")@Tag("Inventory")@Reactorclass TaggingInventorySyncReactor { void on(TaggingInventoryAdjusted event) { }}
@EventTyperecord TaggingInventoryAdjusted(String id) {}Elixir does not support this workflow yet.import { reactor, tag } from '@cratis/chronicle';
@reactor()@tag('Integration')@tag('ExternalAPI')@tag('Inventory')class TaggingInventorySyncReactor {}Mixed approach
Section titled “Mixed approach”Mixing [Tag] and [Tags] still produces one combined set of labels:
using Cratis.Chronicle;using Cratis.Chronicle.Reactors;
[Tag("Notifications", "SMS")][Tags("Customer")]public class TaggingSmsNotificationReactor : IReactor;
// Or mix single and multiple attributes the other way around[Tag("Integration")][Tags("ExternalAPI", "Inventory")]public class TaggingInventorySyncReactorMixed : IReactor;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
// Kotlin exposes only @Tag (repeatable) - combine a multi-value use with a stacked one however reads best@Tag("Notifications", "SMS")@Tag("Customer")@Reactorclass TaggingSmsNotificationReactor { fun on(event: TaggingSmsRequested) { }}
@EventTypedata class TaggingSmsRequested(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
// Java exposes only @Tag (repeatable) - combine a multi-value use with a stacked one however reads best@Tag({"Notifications", "SMS"})@Tag("Customer")@Reactorclass TaggingSmsNotificationReactor { void on(TaggingSmsRequested event) { }}
@EventTyperecord TaggingSmsRequested(String id) {}Elixir does not support this workflow yet.import { reactor, tag, tags } from '@cratis/chronicle';
@reactor()@tag('Notifications', 'SMS')@tags('Customer')class TaggingSmsNotificationReactor {}
// Or mix single and multiple attributes the other way around@reactor()@tag('Integration')@tags('ExternalAPI', 'Inventory')class TaggingInventorySyncReactorMixed {}Tagging read models
Section titled “Tagging read models”Put labels on a read-model definition to describe the data it holds:
using Cratis.Chronicle;
[Tag("Reporting", "Analytics")]public record TaggingConceptsSalesReport(decimal TotalSales, int OrderCount);Kotlin does not support this workflow yet.Java does not support this workflow yet.Elixir does not support this workflow yet.import { tag } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@tag('Reporting', 'Analytics')class TaggingConceptsSalesReport { @field(Number) readonly totalSales: number; @field(Number) readonly orderCount: number;
constructor(totalSales: number, orderCount: number) { this.totalSales = totalSales; this.orderCount = orderCount; }}Best practices
Section titled “Best practices”Choose stable names that describe a category someone will search for, and use the same spelling for related events or definitions. Dot notation, such as customer.registration and customer.profile, can make a naming convention readable; it does not turn a plain tag into a structured query.
Keep runtime identifiers in named tags. A batch number or session ID is a value to match, not a new category. Add labels only when they help a reader distinguish the event or definition.
Common tagging patterns
Section titled “Common tagging patterns”The following examples organize plain tags by different responsibilities. Choose the categories that match how your team finds and maintains its events and definitions.
By domain
Section titled “By domain”using Cratis.Chronicle;
[Tag("Sales")][Tag("Inventory")][Tag("Customer")][Tag("Shipping")]public record TaggingByDomainExample;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Sales")@Tag("Inventory")@Tag("Customer")@Tag("Shipping")@Reactorclass TaggingByDomainExample { fun on(event: TaggingByDomainOrderPlaced) { }}
@EventTypedata class TaggingByDomainOrderPlaced(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Sales")@Tag("Inventory")@Tag("Customer")@Tag("Shipping")@Reactorclass TaggingByDomainExample { void on(TaggingByDomainOrderPlaced event) { }}
@EventTyperecord TaggingByDomainOrderPlaced(String id) {}defmodule MyApp.Events.TaggingByDomainExample do use Cratis.Chronicle.Events.EventType, id: "tagging-by-domain-example", tags: ["Sales", "Inventory", "Customer", "Shipping"]
defstruct [:data]endimport { tag } from '@cratis/chronicle';
@tag('Sales')@tag('Inventory')@tag('Customer')@tag('Shipping')class TaggingByDomainExample {}By purpose
Section titled “By purpose”using Cratis.Chronicle;
[Tag("Analytics")][Tag("Reporting")][Tag("Integration")][Tag("Alerting")][Tag("Monitoring")][Tag("Automation")]public record TaggingByPurposeExample;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Analytics")@Tag("Reporting")@Tag("Integration")@Tag("Alerting")@Tag("Monitoring")@Tag("Automation")@Reactorclass TaggingByPurposeExample { fun on(event: TaggingByPurposeCustomerRegistered) { }}
@EventTypedata class TaggingByPurposeCustomerRegistered(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Analytics")@Tag("Reporting")@Tag("Integration")@Tag("Alerting")@Tag("Monitoring")@Tag("Automation")@Reactorclass TaggingByPurposeExample { void on(TaggingByPurposeCustomerRegistered event) { }}
@EventTyperecord TaggingByPurposeCustomerRegistered(String id) {}defmodule MyApp.Events.TaggingByPurposeExample do use Cratis.Chronicle.Events.EventType, id: "tagging-by-purpose-example", tags: ["Analytics", "Reporting", "Integration", "Alerting", "Monitoring", "Automation"]
defstruct [:data]endimport { tag } from '@cratis/chronicle';
@tag('Analytics')@tag('Reporting')@tag('Integration')@tag('Alerting')@tag('Monitoring')@tag('Automation')class TaggingByPurposeExample {}By integration type
Section titled “By integration type”using Cratis.Chronicle;
[Tag("Notifications")][Tag("ExternalAPI")][Tag("MessageQueue")][Tag("FileSystem")]public record TaggingByIntegrationTypeExample;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Notifications")@Tag("ExternalAPI")@Tag("MessageQueue")@Tag("FileSystem")@Reactorclass TaggingByIntegrationTypeExample { fun on(event: TaggingByIntegrationTypeRecordSynced) { }}
@EventTypedata class TaggingByIntegrationTypeRecordSynced(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Notifications")@Tag("ExternalAPI")@Tag("MessageQueue")@Tag("FileSystem")@Reactorclass TaggingByIntegrationTypeExample { void on(TaggingByIntegrationTypeRecordSynced event) { }}
@EventTyperecord TaggingByIntegrationTypeRecordSynced(String id) {}defmodule MyApp.Events.TaggingByIntegrationTypeExample do use Cratis.Chronicle.Events.EventType, id: "tagging-by-integration-type-example", tags: ["Notifications", "ExternalAPI", "MessageQueue", "FileSystem"]
defstruct [:data]endimport { tag } from '@cratis/chronicle';
@tag('Notifications')@tag('ExternalAPI')@tag('MessageQueue')@tag('FileSystem')class TaggingByIntegrationTypeExample {}By communication channel
Section titled “By communication channel”using Cratis.Chronicle;
[Tag("Email")][Tag("SMS")][Tag("Push")][Tag("Webhook")]public record TaggingByCommunicationChannelExample;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Email")@Tag("SMS")@Tag("Push")@Tag("Webhook")@Reactorclass TaggingByCommunicationChannelExample { fun on(event: TaggingByCommunicationChannelMessageSent) { }}
@EventTypedata class TaggingByCommunicationChannelMessageSent(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Email")@Tag("SMS")@Tag("Push")@Tag("Webhook")@Reactorclass TaggingByCommunicationChannelExample { void on(TaggingByCommunicationChannelMessageSent event) { }}
@EventTyperecord TaggingByCommunicationChannelMessageSent(String id) {}defmodule MyApp.Events.TaggingByCommunicationChannelExample do use Cratis.Chronicle.Events.EventType, id: "tagging-by-communication-channel-example", tags: ["Email", "SMS", "Push", "Webhook"]
defstruct [:data]endimport { tag } from '@cratis/chronicle';
@tag('Email')@tag('SMS')@tag('Push')@tag('Webhook')class TaggingByCommunicationChannelExample {}By stakeholder
Section titled “By stakeholder”using Cratis.Chronicle;
[Tag("Customer")][Tag("Operations")][Tag("Finance")][Tag("Support")][Tag("Executive")]public record TaggingByStakeholderExample;import io.cratis.chronicle.events.EventTypeimport io.cratis.chronicle.observation.Reactorimport io.cratis.chronicle.observation.Tag
@Tag("Customer")@Tag("Operations")@Tag("Finance")@Tag("Support")@Tag("Executive")@Reactorclass TaggingByStakeholderExample { fun on(event: TaggingByStakeholderReportRequested) { }}
@EventTypedata class TaggingByStakeholderReportRequested(val id: String = "")import io.cratis.chronicle.events.EventType;import io.cratis.chronicle.observation.Reactor;import io.cratis.chronicle.observation.Tag;
@Tag("Customer")@Tag("Operations")@Tag("Finance")@Tag("Support")@Tag("Executive")@Reactorclass TaggingByStakeholderExample { void on(TaggingByStakeholderReportRequested event) { }}
@EventTyperecord TaggingByStakeholderReportRequested(String id) {}defmodule MyApp.Events.TaggingByStakeholderExample do use Cratis.Chronicle.Events.EventType, id: "tagging-by-stakeholder-example", tags: ["Customer", "Operations", "Finance", "Support", "Executive"]
defstruct [:data]endimport { tag } from '@cratis/chronicle';
@tag('Customer')@tag('Operations')@tag('Finance')@tag('Support')@tag('Executive')class TaggingByStakeholderExample {}By environment or context
Section titled “By environment or context”using Cratis.Chronicle.Events;using Cratis.Chronicle.EventSequences;
[EventType]public record TaggingDynamicTagsEventOccurred(string Data);
public class TaggingDynamicTagsService(IEventLog eventLog){ public Task RecordProductionCritical(EventSourceId eventSourceId) => eventLog.Append(eventSourceId, new TaggingDynamicTagsEventOccurred("production issue"), tags: ["production", "critical"]);
public Task RecordDevelopmentTest(EventSourceId eventSourceId) => eventLog.Append(eventSourceId, new TaggingDynamicTagsEventOccurred("test run"), tags: ["development", "testing"]);
public Task RecordBatchMigration(EventSourceId eventSourceId) => eventLog.Append(eventSourceId, new TaggingDynamicTagsEventOccurred("batch migration"), tags: ["migration", "batch-process"]);}import io.cratis.chronicle.eventSequences.AppendOptionsimport io.cratis.chronicle.eventSequences.IEventLogimport io.cratis.chronicle.events.EventType
@EventTypedata class TaggingDynamicTagsEventOccurred(val data: String)
class TaggingDynamicTagsService(private val eventLog: IEventLog) { suspend fun recordProductionCritical(eventSourceId: String) = eventLog.append( eventSourceId, TaggingDynamicTagsEventOccurred("production issue"), AppendOptions(tags = listOf("production", "critical")) )
suspend fun recordDevelopmentTest(eventSourceId: String) = eventLog.append( eventSourceId, TaggingDynamicTagsEventOccurred("test run"), AppendOptions(tags = listOf("development", "testing")) )
suspend fun recordBatchMigration(eventSourceId: String) = eventLog.append( eventSourceId, TaggingDynamicTagsEventOccurred("batch migration"), AppendOptions(tags = listOf("migration", "batch-process")) )}import io.cratis.chronicle.eventSequences.IEventLog;import io.cratis.chronicle.events.EventType;
import io.cratis.chronicle.java.AppendOptionsBuilder;import io.cratis.chronicle.java.EventLogJavaBridge;
@EventTyperecord TaggingDynamicTagsEventOccurred(String data) {}
class TaggingDynamicTagsService { private final IEventLog eventLog;
TaggingDynamicTagsService(IEventLog eventLog) { this.eventLog = eventLog; }
void recordProductionCritical(String eventSourceId) { EventLogJavaBridge.append( eventLog, eventSourceId, new TaggingDynamicTagsEventOccurred("production issue"), new AppendOptionsBuilder().tag("production").tag("critical").build()); }
void recordDevelopmentTest(String eventSourceId) { EventLogJavaBridge.append( eventLog, eventSourceId, new TaggingDynamicTagsEventOccurred("test run"), new AppendOptionsBuilder().tag("development").tag("testing").build()); }
void recordBatchMigration(String eventSourceId) { EventLogJavaBridge.append( eventLog, eventSourceId, new TaggingDynamicTagsEventOccurred("batch migration"), new AppendOptionsBuilder().tag("migration").tag("batch-process").build()); }}defmodule MyApp.Events.TaggingDynamicPatternsEventOccurred do use Cratis.Chronicle.Events.EventType, id: "tagging-dynamic-patterns-event-occurred"
defstruct [:data]end
defmodule MyApp.TaggingDynamicPatternsService do alias MyApp.Events.TaggingDynamicPatternsEventOccurred
def record_production_critical(event_source_id) do Cratis.Chronicle.append( event_source_id, %TaggingDynamicPatternsEventOccurred{data: "production issue"}, tags: ["production", "critical"] ) end
def record_development_test(event_source_id) do Cratis.Chronicle.append( event_source_id, %TaggingDynamicPatternsEventOccurred{data: "test run"}, tags: ["development", "testing"] ) end
def record_batch_migration(event_source_id) do Cratis.Chronicle.append( event_source_id, %TaggingDynamicPatternsEventOccurred{data: "batch migration"}, tags: ["migration", "batch-process"] ) endendimport { eventType, IEventStore } from '@cratis/chronicle';import { field } from '@cratis/fundamentals';
@eventType()class TaggingDynamicTagsEventOccurred { @field(String) readonly data: string;
constructor(data: string) { this.data = data; }}
class TaggingDynamicTagsService { constructor(private readonly store: IEventStore) {}
async recordProductionCritical(eventSourceId: string): Promise<void> { await this.store.eventLog.append( eventSourceId, new TaggingDynamicTagsEventOccurred('production issue'), { tags: ['production', 'critical'] }); }
async recordDevelopmentTest(eventSourceId: string): Promise<void> { await this.store.eventLog.append( eventSourceId, new TaggingDynamicTagsEventOccurred('test run'), { tags: ['development', 'testing'] }); }
async recordBatchMigration(eventSourceId: string): Promise<void> { await this.store.eventLog.append( eventSourceId, new TaggingDynamicTagsEventOccurred('batch migration'), { tags: ['migration', 'batch-process'] }); }}Using tags
Section titled “Using tags”To restrict which events a reducer or reactor receives, configure event-tag filtering. The filter reads tags stored with each event, not the labels on the observer definition.
Chronicle does not use observer labels to activate, select or group observers. For examples focused on reactor definitions, continue with tagging reactors. To carry a batch or session identifier into an append, see appending with named tags.