obs

package
v1.0.2-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package obs is packtrail's OpenTelemetry instrumentation. It uses the OTel API only: the application chooses the SDK and exporters, and without one every span and instrument is a no-op. The wire format of trace context is the W3C traceparent header, as before.

Index

Constants

View Source
const (
	AttrExecID        = attribute.Key("packtrail.exec.id")
	AttrFlow          = attribute.Key("packtrail.flow.name")
	AttrFlowHash      = attribute.Key("packtrail.flow.hash")
	AttrNode          = attribute.Key("packtrail.node")
	AttrTaskKey       = attribute.Key("packtrail.task.key")
	AttrGeneration    = attribute.Key("packtrail.task.generation")
	AttrAttempt       = attribute.Key("packtrail.task.attempt")
	AttrKind          = attribute.Key("packtrail.worker.kind")
	AttrCommandType   = attribute.Key("packtrail.command.type")
	AttrCommandID     = attribute.Key("packtrail.command.id")
	AttrEvents        = attribute.Key("packtrail.events")
	AttrConflicts     = attribute.Key("packtrail.conflicts")
	AttrPartition     = attribute.Key("packtrail.partition")
	AttrOutcome       = attribute.Key("packtrail.job.outcome")
	AttrStatus        = attribute.Key("packtrail.execution.status")
	AttrSignal        = attribute.Key("packtrail.signal.name")
	AttrSchedule      = attribute.Key("packtrail.schedule.name")
	AttrSourceExecID  = attribute.Key("packtrail.source.exec.id")
	AttrDeliveries    = attribute.Key("packtrail.job.deliveries")
	AttrRetryable     = attribute.Key("packtrail.job.retryable")
	AttrMessagingDest = attribute.Key("messaging.destination.name")
)

Attribute keys of spans and metrics.

View Source
const Scope = "github.com/henomis/packtrail"

Scope is the instrumentation scope of packtrail's tracer and meter.

Variables

This section is empty.

Functions

func ContextWithTraceparent

func ContextWithTraceparent(ctx context.Context, tp string) context.Context

ContextWithTraceparent returns ctx with tp as its remote parent; ctx unchanged when tp is "" or invalid.

func Extract

func Extract(ctx context.Context, h nats.Header) context.Context

Extract returns ctx with the trace context of a NATS header.

func Fail

func Fail(span trace.Span, err error)

Fail marks span as failed by err (nil: nothing).

func Meter

func Meter(mp metric.MeterProvider) metric.Meter

Meter is packtrail's meter from mp, the global provider when nil.

func ObserveEngine

func ObserveEngine(m metric.Meter, counters func() metrics.Snapshot,
	lag func(context.Context) metrics.Snapshot,
) (metric.Registration, error)

ObserveEngine registers the engine's observable instruments: its counters (read from counters, cheap) and the dispatcher's lag and stall (read from lag, which may do I/O). The registration ends with Unregister.

func SpanContext

func SpanContext(tp string) trace.SpanContext

SpanContext is the span context tp carries; invalid when tp is not one.

func Traceparent

func Traceparent(ctx context.Context) string

Traceparent is the W3C traceparent of the span in ctx, "" when ctx holds no valid span context.

func Tracer

func Tracer(tp trace.TracerProvider) trace.Tracer

Tracer is packtrail's tracer from tp, the global provider when nil.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine holds the engine's synchronous instruments.

func NewEngine

func NewEngine(m metric.Meter) *Engine

NewEngine creates the engine's instruments on m (nil: no-op).

func (*Engine) Command

func (e *Engine) Command(ctx context.Context, cmdType string, d time.Duration)

Command records the handling of one command.

func (*Engine) Ended

func (e *Engine) Ended(ctx context.Context, flow, status string, d time.Duration)

Ended records an execution that reached status after d.

func (*Engine) Started

func (e *Engine) Started(ctx context.Context, flow string)

Started records an execution started.

type HeaderCarrier

type HeaderCarrier nats.Header

HeaderCarrier adapts a NATS header to OTel propagation.

func (HeaderCarrier) Get

func (h HeaderCarrier) Get(key string) string

Get implements propagation.TextMapCarrier.

func (HeaderCarrier) Keys

func (h HeaderCarrier) Keys() []string

Keys implements propagation.TextMapCarrier.

func (HeaderCarrier) Set

func (h HeaderCarrier) Set(key, value string)

Set implements propagation.TextMapCarrier.

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker holds a worker's instruments.

func NewWorker

func NewWorker(m metric.Meter) *Worker

NewWorker creates a worker's instruments on m (nil: no-op).

func (*Worker) Begin

func (w *Worker) Begin(ctx context.Context, kind string, wait time.Duration) func(outcome string, d time.Duration)

Begin records a job starting after waiting wait in its queue (wait < 0: a redelivery, not recorded). The returned function records its end.

Jump to

Keyboard shortcuts

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