Documentation ¶
Overview ¶
Package correlation contains extensions for eventually key components to support correlated events for tracing and debugging purposes.
You can read more about events correlation here: https://blog.arkency.com/correlation-id-and-causation-id-in-evented-systems/
Index ¶
- Constants
- func CausationIDContext(ctx context.Context) (string, bool)
- func IDContext(ctx context.Context) (string, bool)
- func WithCausationID(ctx context.Context, id string) context.Context
- func WithCorrelationID(ctx context.Context, id string) context.Context
- type EventStoreWrapper
- type Generator
- type Message
- type ProjectionWrapper
Constants ¶
const ( EventIDKey = "Event-Id" CorrelationIDKey = "Correlation-Id" CausationIDKey = "Causation-Id" )
Metadata keys used by the package.
Variables ¶
This section is empty.
Functions ¶
func CausationIDContext ¶
CausationIDContext returns the Causation id from the context, if it has been set using WithCausationID modifier.
func IDContext ¶
IDContext returns the Correlation id from the context, if it has been set using WithCorrelationID modifier.
func WithCausationID ¶
WithCausationID adds the specified causation id in the context, which will be used by the other extension components exposed by this package.
Types ¶
type EventStoreWrapper ¶
type EventStoreWrapper struct { eventstore.Store // contains filtered or unexported fields }
EventStoreWrapper is an extension component that adds support for Correlation, Causation and Event id recording in all Events committed to the underlying EventStore.
Check WrapEventStore for more information.
func WrapEventStore ¶
func WrapEventStore(es eventstore.Store, generator Generator) EventStoreWrapper
WrapEventStore wraps the provided eventstore.Store instance with an EventStoreWrapper extension.
EventStoreWrapper will add an Event id for each Event committed through this instance, using the specified Generator interface.
Also, it will add Correlation and Causation ids in the committed Events Metadata, if present in the context. You can check correlation.WithCorrelationID and correlation.WithCausationID functions, or correlation.ProjectionWrapper for more info.
func (EventStoreWrapper) Append ¶
func (esw EventStoreWrapper) Append( ctx context.Context, id eventstore.StreamID, expected eventstore.VersionCheck, events ...eventually.Event, ) (int64, error)
Append extracts or creates an Event, Correlation and Causation id from the context, applies it to all the Events provided and forwards it to the wrapped Event Store.
type Message ¶
type Message eventually.Message
Message extends an eventually.Message instance to fetch Correlation and Causation ids from the Message Metadata.
func (Message) CausationID ¶
CausationID returns the Causation id from the Message Metadata, if found.
func (Message) CorrelationID ¶
CorrelationID returns the Correlation id from the Message Metadata, if found.
type ProjectionWrapper ¶
type ProjectionWrapper struct {
// contains filtered or unexported fields
}
ProjectionWrapper is an extension component that adds Correlation and Causation ids to the context of the underlying projection.Applier instance, if found in the Message received in Apply.
Use WrapProjection to create a new instance.
func WrapProjection ¶
func WrapProjection(applier projection.Applier) ProjectionWrapper
WrapProjection wraps the specified projection.Applier instance with a ProjectionWrapper extension component.
func (ProjectionWrapper) Apply ¶
func (pw ProjectionWrapper) Apply(ctx context.Context, event eventstore.Event) error
Apply applies the provided Event to the wrapped projection.Applier, using an augmented context containing Correlation and Causation ids in the Event Metadata, if any.