tracing

package
v0.5.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
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

func SetAttributes(ctx context.Context, attrs ...attribute.KeyValue)

SetAttributes sets attributes on the current span.

func SetError

func SetError(ctx context.Context, err error)

SetError sets an error on the current span.

func SpanFromContext

func SpanFromContext(ctx context.Context) trace.Span

SpanFromContext returns the current span from context.

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

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

func (t *Tracer) ServiceName() string

ServiceName returns the configured service name.

func (*Tracer) StartSpan

func (t *Tracer) StartSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartSpan starts a new span with the given name.

func (*Tracer) Tracer

func (t *Tracer) Tracer() trace.Tracer

Tracer returns the underlying OpenTelemetry tracer.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL