Documentation
¶
Overview ¶
Package tracing provides OpenTelemetry integration for mink.
This package enables distributed tracing for event sourcing operations, including command execution, event store operations, and projections.
Basic usage with command bus:
tp := sdktrace.NewTracerProvider(...) otel.SetTracerProvider(tp) tracer := tracing.NewTracer() bus := mink.NewCommandBus() bus.Use(tracing.CommandMiddleware(tracer))
The tracing middleware captures:
- Command type and execution duration
- Success/failure status
- Error details when commands fail
- Correlation and causation IDs
Index ¶
- Constants
- func AddEvent(ctx context.Context, name string, opts ...trace.EventOption)
- func CommandMiddleware(tracer *Tracer) mink.Middleware
- func SetAttributes(ctx context.Context, attrs ...attribute.KeyValue)
- func SetError(ctx context.Context, err error)
- func SpanFromContext(ctx context.Context) trace.Span
- type EventStoreMiddleware
- func (m *EventStoreMiddleware) Append(ctx context.Context, streamID string, events []adapters.EventRecord, ...) ([]adapters.StoredEvent, error)
- func (m *EventStoreMiddleware) Close() error
- func (m *EventStoreMiddleware) GetLastPosition(ctx context.Context) (uint64, error)
- func (m *EventStoreMiddleware) GetStreamInfo(ctx context.Context, streamID string) (*adapters.StreamInfo, error)
- func (m *EventStoreMiddleware) Initialize(ctx context.Context) error
- func (m *EventStoreMiddleware) Load(ctx context.Context, streamID string, fromVersion int64) ([]adapters.StoredEvent, error)
- type ProjectionMiddleware
- type Tracer
- type TracerOption
Constants ¶
const ( // TracerName is the name of the mink tracer. TracerName = "github.com/AshkanYarmoradi/go-mink" // DefaultServiceName is the default service name for spans. DefaultServiceName = "mink" )
Variables ¶
This section is empty.
Functions ¶
func AddEvent ¶
func AddEvent(ctx context.Context, name string, opts ...trace.EventOption)
AddEvent adds an event to the current span.
func CommandMiddleware ¶
func CommandMiddleware(tracer *Tracer) mink.Middleware
CommandMiddleware creates middleware that traces command execution.
func SetAttributes ¶
SetAttributes sets attributes on the current span.
Types ¶
type EventStoreMiddleware ¶
type EventStoreMiddleware struct {
// contains filtered or unexported fields
}
EventStoreMiddleware wraps an EventStoreAdapter with tracing.
func NewEventStoreMiddleware ¶
func NewEventStoreMiddleware(adapter adapters.EventStoreAdapter, tracer *Tracer) *EventStoreMiddleware
NewEventStoreMiddleware wraps an adapter with tracing.
func (*EventStoreMiddleware) Append ¶
func (m *EventStoreMiddleware) Append(ctx context.Context, streamID string, events []adapters.EventRecord, expectedVersion int64) ([]adapters.StoredEvent, error)
Append stores events with tracing.
func (*EventStoreMiddleware) Close ¶
func (m *EventStoreMiddleware) Close() error
Close closes the adapter with tracing.
func (*EventStoreMiddleware) GetLastPosition ¶
func (m *EventStoreMiddleware) GetLastPosition(ctx context.Context) (uint64, error)
GetLastPosition returns the last global position with tracing.
func (*EventStoreMiddleware) GetStreamInfo ¶
func (m *EventStoreMiddleware) GetStreamInfo(ctx context.Context, streamID string) (*adapters.StreamInfo, error)
GetStreamInfo returns stream metadata with tracing.
func (*EventStoreMiddleware) Initialize ¶
func (m *EventStoreMiddleware) Initialize(ctx context.Context) error
Initialize initializes the adapter with tracing.
func (*EventStoreMiddleware) Load ¶
func (m *EventStoreMiddleware) Load(ctx context.Context, streamID string, fromVersion int64) ([]adapters.StoredEvent, error)
Load retrieves events with tracing.
type ProjectionMiddleware ¶
type ProjectionMiddleware struct {
// contains filtered or unexported fields
}
ProjectionMiddleware wraps an inline projection with tracing.
func NewProjectionMiddleware ¶
func NewProjectionMiddleware(projection mink.InlineProjection, tracer *Tracer) *ProjectionMiddleware
NewProjectionMiddleware wraps an inline projection with tracing.
func (*ProjectionMiddleware) Apply ¶
func (m *ProjectionMiddleware) Apply(ctx context.Context, event mink.StoredEvent) error
Apply applies an event with tracing.
func (*ProjectionMiddleware) HandledEvents ¶
func (m *ProjectionMiddleware) HandledEvents() []string
HandledEvents returns the handled event types.
func (*ProjectionMiddleware) Name ¶
func (m *ProjectionMiddleware) Name() string
Name returns the projection name.
type Tracer ¶
type Tracer struct {
// contains filtered or unexported fields
}
Tracer wraps OpenTelemetry tracer for mink operations.
func NewTracer ¶
func NewTracer(opts ...TracerOption) *Tracer
NewTracer creates a new Tracer with the global TracerProvider.
func (*Tracer) ServiceName ¶
ServiceName returns the configured service name.
type TracerOption ¶
type TracerOption func(*Tracer)
TracerOption configures a Tracer.
func WithServiceName ¶
func WithServiceName(name string) TracerOption
WithServiceName sets the service name for spans.
func WithTracerProvider ¶
func WithTracerProvider(tp trace.TracerProvider) TracerOption
WithTracerProvider sets a custom TracerProvider.