Cratis Chronicle event correlation, identity, and causation
Cratis Chronicle records correlation, identity and causation alongside each event so you can trace a change back to the operation and actor that produced it. When investigating an unexpected event, these answer different questions:
- A correlation ID groups work belonging to one logical operation, such as an HTTP request or message handler invocation.
- An identity records who caused the change: a user, system or service.
- Causation records the chain of operations that led to the event.
Establish this context at the start of a request or background job, then let the client attach it to appends within that context. Carry it explicitly when work crosses a boundary that does not preserve the client’s context.
Correlation ID
Section titled “Correlation ID”using Cratis.Execution;
public class CorrelationIdentityCausationCorrelation(ICorrelationIdAccessor accessor, ICorrelationIdModifier modifier){ public CorrelationId GetCurrent() => accessor.Current;
public void SetForRequest() => modifier.Modify(CorrelationId.New());}import io.cratis.chronicle.correlation.correlationIdManagerimport java.util.UUID
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationCorrelation { fun getCurrent(): UUID = correlationIdManager.current
fun setForRequest() = correlationIdManager.set(UUID.randomUUID())}import io.cratis.chronicle.correlation.CorrelationIdManagerKt;import java.util.UUID;
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationCorrelation { UUID getCurrent() { return CorrelationIdManagerKt.getCorrelationIdManager().getCurrent(); }
void setForRequest() { CorrelationIdManagerKt.getCorrelationIdManager().set(UUID.randomUUID()); }}defmodule MyApp.CorrelationIdentityCausationCorrelation do alias Cratis.Chronicle.Correlation.CorrelationId
def get_current do Cratis.Chronicle.current_correlation_id() end
def set_for_request do Cratis.Chronicle.set_correlation_id(CorrelationId.create()) endendimport { correlationIdManager, CorrelationId } from '@cratis/chronicle';
class CorrelationIdentityCausationCorrelation { getCurrent(): CorrelationId { return correlationIdManager.current; }
setForRequest(): void { correlationIdManager.setCurrent(CorrelationId.create()); }}Use the same correlation ID for work that belongs to one operation. The client scopes that value according to its runtime: Kotlin uses per-thread context (ThreadLocal), Elixir uses the process dictionary, and TypeScript uses AsyncLocalStorage for the active asynchronous call context. Starting a new thread, process or independent context requires you to carry the value across explicitly.
Identity
Section titled “Identity”using Cratis.Chronicle.Identities;
public class CorrelationIdentityCausationIdentity(IIdentityProvider identityProvider){ public void SetForRequest(string subject, string name, string userName) => identityProvider.SetCurrentIdentity(new Identity(subject, name, userName));
public Identity GetCurrent() => identityProvider.GetCurrent();}import io.cratis.chronicle.identity.Identityimport io.cratis.chronicle.identity.identityProvider
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationIdentity { fun setForRequest(subject: String, name: String, userName: String) { identityProvider.setCurrentIdentity(Identity(subject, name, userName)) }
fun getCurrent(): Identity = identityProvider.currentIdentity}import io.cratis.chronicle.identity.Identity;import io.cratis.chronicle.identity.IdentityProviderKt;
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationIdentity { void setForRequest(String subject, String name, String userName) { IdentityProviderKt.getIdentityProvider().setCurrentIdentity(new Identity(subject, name, userName, null)); }
Identity getCurrent() { return IdentityProviderKt.getIdentityProvider().getCurrentIdentity(); }}defmodule MyApp.CorrelationIdentityCausationIdentity do alias Cratis.Chronicle.Identity
def set_for_request(subject, name, user_name) do Cratis.Chronicle.set_identity(Identity.new(subject, name, user_name)) end
def get_current do Cratis.Chronicle.current_identity() endendimport { identityProvider, Identity } from '@cratis/chronicle';
class CorrelationIdentityCausationIdentity { setForRequest(subject: string, name: string, userName: string): void { identityProvider.setCurrentIdentity(new Identity(subject, name, userName)); }
getCurrent(): Identity { return identityProvider.getCurrent(); }}An identity has a stable subject and a display name. Use the subject to identify the actor, and the display name to present it to a reader. This identity subject identifies who caused the event; the event’s compliance subject identifies who the event is about.
The clients provide predefined identities, or sentinels, for System, NotSet and Unknown, with language-specific naming. An on-behalf-of chain records delegation when one identity acts for another. Helpers such as withoutDuplicates() and without_duplicates/1 remove repeated subjects from that chain while retaining their first occurrence.
Renaming an identity
Section titled “Renaming an identity”When someone’s display name changes, rename the identity instead of changing their past events. Events refer to the identity by its stable key, so metadata reads can show the updated name for existing history.
using Cratis.Chronicle;
public static class RenamingAnIdentity{ public static async Task Rename(IEventStore eventStore) { await eventStore.Identities.Rename("subject-42", "Jane Austen"); }}import io.cratis.chronicle.IEventStore
class CorrelationIdentityCausationRenamingAnIdentity { suspend fun rename(eventStore: IEventStore) { eventStore.identities.rename("subject-42", "Jane Austen") }}import io.cratis.chronicle.IEventStore;
import io.cratis.chronicle.java.IdentityManagerServiceJavaBridge;
class CorrelationIdentityCausationRenamingAnIdentity { void rename(IEventStore eventStore) { IdentityManagerServiceJavaBridge.rename(eventStore.getIdentities(), "subject-42", "Jane Austen"); }}defmodule MyApp.CorrelationIdentityCausationRenamingAnIdentity do alias Cratis.Chronicle.Identities
def rename do Identities.rename("subject-42", "Jane Austen") endendimport { IEventStore } from '@cratis/chronicle';
async function renameAnIdentity(eventStore: IEventStore): Promise<void> { await eventStore.identities.rename('subject-42', 'Jane Austen');}Keep the existing subject when renaming so earlier events continue to resolve to the same identity.
Identity resolution on metadata reads
Section titled “Identity resolution on metadata reads”Metadata reads resolve caused-by identities directly from storage instead of a kernel node’s identity cache. A rename is visible on the next metadata read, including for events appended before the rename. Each chain link has a Resolution status:
| Status | Meaning | Name |
|---|---|---|
Resolved |
The identity exists and has a display name. | The current name. |
NameUnavailable |
The identity exists but its display name is empty. | null. |
Missing |
The stored identity identifier no longer resolves. | null. |
NotSet |
No caused-by identity was set. | null. |
System |
The subject is Chronicle’s well-known system identity. | null. |
Chronicle never substitutes the subject for an unavailable name. OnBehalfOf retains the chain order and resolves each link separately.
InitiatorType classifies the first identity in the chain. A resolved identity is an Agent when acting on behalf of another identity, or a User without that chain. Chronicle’s system identity is System; the well-known unknown identity and missing or unset identities are Unknown. An unavailable display name does not change whether an identity acts as an agent.
Application-defined service identities are not automatically classified as systems. Recognize
them by their subjects in your application, rather than relying on display names or the
User classification.
Erasing personally identifiable information (PII) deletes encryption keys for protected event and read-model data, not identity display names. The rename API requires a non-empty display name and leaves the subject and username unchanged, so it is not an identity-erasure operation. Your application must authorize access before calling the metadata API.
Caller-derived authorship
Section titled “Caller-derived authorship”For a signed-in Chronicle user (an internal password token, Identity cookie, or protected bearer ticket), sequence commands always record the authenticated user as CausedBy. A supplied causedBy, including its onBehalfOf chain, is ignored. This applies to append, batch append, append-once, revision, and redaction commands.
Application callers using client credentials may still supply an end-user identity and an onBehalfOf chain. When omitted, the application principal is recorded. Unmarked external-authority tokens and anonymous requests retain the same supplied-identity behavior; external authorities are responsible for their own identity and delegation policy. The chronicle_principal_kind=user claim is reserved for Chronicle user principals, not a delegation permission.
Existing Identity application cookies acquire the user marker during claims transformation. Refreshing an existing Chronicle user refresh token also adds the marker, and newly issued password tokens retain it when refreshed. An already-issued access token without the marker keeps its supplied-identity behavior until replaced. For uniform authorship, update every request-serving server node; older nodes do not enforce this rule. No request, protobuf, or grain contract changes are required.
Causation
Section titled “Causation”using Cratis.Chronicle.Auditing;
public class CorrelationIdentityCausationCausation(ICausationManager causationManager){ public void RecordPlaceOrder(string orderId) => causationManager.Add( "MyApp.Commands.PlaceOrder", new Dictionary<string, string> { ["orderId"] = orderId });}import io.cratis.chronicle.auditing.CausationTypeimport io.cratis.chronicle.auditing.causationManager
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationCausation { fun recordPlaceOrder(orderId: String) { causationManager.add(CausationType("MyApp.Commands.PlaceOrder"), mapOf("orderId" to orderId)) }}import io.cratis.chronicle.java.CausationManagerJavaBridge;
import java.util.Map;
import static io.cratis.chronicle.auditing.CausationManagerKt.getCausationManager;
// Per thread, not per request or coroutine; clear in finally on thread-pooled paths.class CorrelationIdentityCausationCausation { void recordPlaceOrder(String orderId) { CausationManagerJavaBridge.add( getCausationManager(), "MyApp.Commands.PlaceOrder", Map.of("orderId", orderId)); }}defmodule MyApp.CorrelationIdentityCausationCausation do alias Cratis.Chronicle.Auditing.CausationManager
def record_place_order(order_id) do CausationManager.add("MyApp.Commands.PlaceOrder", %{order_id: order_id}) endendimport { causationManager, CausationType } from '@cratis/chronicle';
class CorrelationIdentityCausationCausation { recordPlaceOrder(orderId: string): void { causationManager.add(new CausationType('MyApp.Commands.PlaceOrder'), { orderId }); }}Add causation entries as an operation progresses so the event records how it was reached. In TypeScript, causationManager.add(type, properties) adds an entry to the current chain. For root-cause setup, scoped entries and reading the chain, continue with your client’s reference below.
Client-specific reference
Section titled “Client-specific reference”Use your client’s reference to wire context into request handling and check what happens when work crosses thread, process or asynchronous-context boundaries:
- .NET client —
Cratis.Execution.ICorrelationIdAccessor/ICorrelationIdModifier,Cratis.Chronicle.Identities.IIdentityProvider,Cratis.Chronicle.Auditing.ICausationManager - Kotlin client —
io.cratis.chronicle.correlation,io.cratis.chronicle.identity,io.cratis.chronicle.auditing - Elixir client —
Chronicle.CorrelationId,Chronicle.Identity,Chronicle.Auditing.CausationManager - TypeScript client —
correlationIdManager,identityProvider,causationManager