otelcmd

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: MIT Imports: 14 Imported by: 2

README

otelcmd-stream-go

Go Reference GoReportCard codecov

otelcmd-stream-go provides OpenTelemetry support for cmd-stream-go.

How To

cmd-stream-go with OpenTelemetry

Documentation

Index

Constants

View Source
const ScopeName = "github.com/cmd-stream/otelcmd-stream-go"

ScopeName is the instrumentation scope name.

Variables

This section is empty.

Functions

func Apply

func Apply[T any](ops []SetOption[T], o *Options[T])

func ElapsedTime

func ElapsedTime(startTime time.Time) float64

func Version

func Version() string

Version is the current release version of the otelcmd-stream instrumentation.

Types

type CmdMetricAttributesFn

type CmdMetricAttributesFn[T any] func(sentCmd hooks.SentCmd[T],
	status semconv.CmdStreamCommandStatus,
	elapsedTime float64,
) []attribute.KeyValue

type Hooks

type Hooks[T any] struct {
	// contains filtered or unexported fields
}

Hooks is an implementation of the hooks.Hooks interface from the sender module. It provides OpenTelemetry-based instrumentation for the cmd-stream sender.

func (*Hooks[T]) BeforeSend

func (h *Hooks[T]) BeforeSend(ctx context.Context, cmd core.Cmd[T]) (context.Context, error)

func (*Hooks[T]) OnError

func (h *Hooks[T]) OnError(ctx context.Context, sentCmd hooks.SentCmd[T],
	err error)

func (*Hooks[T]) OnResult

func (h *Hooks[T]) OnResult(ctx context.Context, sentCmd hooks.SentCmd[T],
	recvResult hooks.ReceivedResult, err error)

func (*Hooks[T]) OnTimeout

func (h *Hooks[T]) OnTimeout(ctx context.Context, sentCmd hooks.SentCmd[T],
	err error)

type HooksFactory

type HooksFactory[T any] struct {
	// contains filtered or unexported fields
}

HooksFactory is an implementation of the hooks.HooksFactory interface from the sender module. It is responsible for creating Hooks instances configured with OpenTelemetry tracing and metrics options.

func NewHooksFactory

func NewHooksFactory[T any](ops ...SetOption[T]) HooksFactory[T]

NewHooksFactory creates a new HooksFactory.

func (HooksFactory[T]) New

func (f HooksFactory[T]) New() hooks.Hooks[T]

type Invoker

type Invoker[T any] struct {
	// contains filtered or unexported fields
}

Invoker is an implementation of the handler.Invoker interface from the handler module. It adds OpenTelemetry-based instrumentation for command handling on the server side.

func NewInvoker

func NewInvoker[T any](invoker handler.Invoker[T], ops ...SetOption[T]) Invoker[T]

NewInvoker creates a new invoker that wraps the specified one, adding OpenTelemetry-based instrumentation.

func (Invoker[T]) Invoke

func (i Invoker[T]) Invoke(ctx context.Context, seq core.Seq, at time.Time,
	bytesRead int, cmd core.Cmd[T], proxy core.Proxy) (err error)

type Options

type Options[T any] struct {
	ServerAddr        net.Addr
	Tracer            trace.Tracer
	Meter             metric.Meter
	SpanStartOptions  []trace.SpanStartOption
	SpanNameFormatter SpanNameFormatterFn[T]

	Propagator     propagation.TextMapPropagator
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider

	SpanAttributesFn            SpanAttributesFn[T]
	SpanResultEventAttributesFn SpanResultEventAttributesFn[T]

	CmdMetricAttributesFn    CmdMetricAttributesFn[T]
	ResultMetricAttributesFn ResultMetricAttributesFn[T]
}

func (Options[T]) CmdMetricAttributes

func (o Options[T]) CmdMetricAttributes(sentCmd hooks.SentCmd[T],
	status semconv.CmdStreamCommandStatus,
	elapsedTime float64,
) (attrs []attribute.KeyValue)

CmdMetricAttributes returns metric attributes for the sent Command, given its status and elapsed time. It calls the user-provided CmdMetricAttributesFn if set; otherwise, returns nil.

func (Options[T]) ResultMetricAttributes

func (o Options[T]) ResultMetricAttributes(sentCmd hooks.SentCmd[T],
	recvResult hooks.ReceivedResult,
	elapsedTime float64,
) (attrs []attribute.KeyValue)

ResultMetricAttributes returns metric attributes for the received Result, given the corresponding sent Command and elapsed time. It calls the user-provided ResultMetricAttributesFn if set; otherwise, returns nil.

func (Options[T]) SpanAttributes

func (o Options[T]) SpanAttributes(peerAddr net.Addr,
	sentCmd hooks.SentCmd[T]) (attrs []attribute.KeyValue)

SpanAttributes returns span attributes for the given peer address and sent Command. It calls the user-provided SpanAttributesFn if set; otherwise, it returns nil.

func (Options[T]) SpanResultEventAttributes

func (o Options[T]) SpanResultEventAttributes(sentCmd hooks.SentCmd[T],
	recvResult hooks.ReceivedResult) (attrs []attribute.KeyValue)

SpanResultEventAttributes returns span event attributes for the given sent Command and received result. It calls the user-provided SpanResultEventAttributesFn if set; otherwise, it returns nil.

type Proxy

type Proxy[T any] struct {
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy[T any](proxy core.Proxy, callback ProxyCallbackFn) *Proxy[T]

func (*Proxy[T]) LocalAddr

func (p *Proxy[T]) LocalAddr() net.Addr

func (*Proxy[T]) RemoteAddr

func (p *Proxy[T]) RemoteAddr() net.Addr

func (*Proxy[T]) Send

func (p *Proxy[T]) Send(seq core.Seq, result core.Result) (n int, err error)

func (*Proxy[T]) SendWithDeadline

func (p *Proxy[T]) SendWithDeadline(seq core.Seq, result core.Result,
	deadline time.Time) (n int, err error)

type ProxyCallbackFn

type ProxyCallbackFn func(recvResult hooks.ReceivedResult)

type ResultMetricAttributesFn

type ResultMetricAttributesFn[T any] func(sentCmd hooks.SentCmd[T],
	recvResult hooks.ReceivedResult,
	elapsedTime float64,
) []attribute.KeyValue

type SetOption

type SetOption[T any] func(o *Options[T])

func WithCmdMetricAttributesFn

func WithCmdMetricAttributesFn[T any](fn CmdMetricAttributesFn[T]) SetOption[T]

WithCmdMetricAttributesFn sets the function that returns Command metric attributes.

func WithMeterProvider

func WithMeterProvider[T any](mp metric.MeterProvider) SetOption[T]

WithMeterProvider sets the OpenTelemetry MeterProvider.

func WithPropagator

func WithPropagator[T any](p propagation.TextMapPropagator) SetOption[T]

WithPropagator sets the OpenTelemetry TextMapPropagator.

func WithResultMetricAttributesFn

func WithResultMetricAttributesFn[T any](fn ResultMetricAttributesFn[T]) SetOption[T]

WithResultMetricAttributesFn sets the function that returns Result metric attributes.

func WithServerAddr

func WithServerAddr[T any](addr net.Addr) SetOption[T]

WithServerAddr sets the server address.

func WithSpanAttributesFn

func WithSpanAttributesFn[T any](fn SpanAttributesFn[T]) SetOption[T]

WithSpanAttributesFn sets the function that returns additional span attributes.

func WithSpanNameFormatter

func WithSpanNameFormatter[T any](f SpanNameFormatterFn[T]) SetOption[T]

WithSpanNameFormatter sets the function used to format span names.

func WithSpanResultEventAttributesFn

func WithSpanResultEventAttributesFn[T any](
	fn SpanResultEventAttributesFn[T]) SetOption[T]

WithSpanResultEventAttributesFn sets the function that returns additional span event attributes.

func WithSpanStartOption

func WithSpanStartOption[T any](s trace.SpanStartOption) SetOption[T]

WithSpanStartOption appends a SpanStartOption to be applied when starting spans.

func WithTracerProvider

func WithTracerProvider[T any](tp trace.TracerProvider) SetOption[T]

WithTracerProvider sets the OpenTelemetry TracerProvider.

type SpanAttributesFn

type SpanAttributesFn[T any] func(remoteAddr net.Addr,
	sentCmd hooks.SentCmd[T]) []attribute.KeyValue

type SpanNameFormatterFn

type SpanNameFormatterFn[T any] func(cmd core.Cmd[T]) string

type SpanResultEventAttributesFn

type SpanResultEventAttributesFn[T any] func(sentCmd hooks.SentCmd[T],
	recvResult hooks.ReceivedResult) []attribute.KeyValue

type TraceCmd

type TraceCmd[T any, V core.Cmd[T]] struct {
	MapCarrier *map[string]string
	Cmd        V
}

TraceCmd wraps a core.Cmd and carries tracing context for propagation.

func NewTraceCmd

func NewTraceCmd[T any, V core.Cmd[T]](cmd V) TraceCmd[T, V]

NewTraceCmd creates a new TraceCmd.

func (TraceCmd[T, V]) Carrier

func (c TraceCmd[T, V]) Carrier() (carrier map[string]string)

func (TraceCmd[T, V]) Exec

func (c TraceCmd[T, V]) Exec(ctx context.Context, seq core.Seq, at time.Time,
	receiver T, proxy core.Proxy) error

func (TraceCmd[T, V]) InnerCmd

func (c TraceCmd[T, V]) InnerCmd() core.Cmd[T]

func (TraceCmd[T, V]) SetCarrier

func (c TraceCmd[T, V]) SetCarrier(carrier map[string]string)

func (TraceCmd[T, V]) TypeStr

func (c TraceCmd[T, V]) TypeStr() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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