telemetry

package
v1.10.1 Latest Latest
Warning

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

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

Documentation

Overview

Package telemetry is the small amount of OpenTelemetry glue fabriq's core shares with the root module: the tracer, the helpers that keep background work off the trace that started it, the producer-to-consumer span link, an error marker that never copies error text onto a span, and the observer interfaces through which a host records fabriq's duration metrics.

Core records no metrics itself and installs no provider. Spans go to the global tracer provider (forge.New installs one); durations go to whatever observer the host wires in (fabriq's forge extension records them on its Prometheus registry). A nil observer records nothing.

Index

Constants

View Source
const (
	ResultOK       = "ok"
	ResultError    = "error"
	ResultInvalid  = "invalid"
	ResultConflict = "conflict"
	ResultNotFound = "not_found"
)

Result values shared by fabriq's duration metrics and span attributes.

View Source
const (
	AttrEntity     = attribute.Key("fabriq.entity")
	AttrProjection = attribute.Key("fabriq.projection")
	AttrResult     = attribute.Key("fabriq.result")
	AttrBatchSize  = attribute.Key("fabriq.batch_size")
	AttrMutations  = attribute.Key("fabriq.mutations")
	AttrOp         = attribute.Key("fabriq.command.op")
	AttrModelKind  = attribute.Key("fabriq.model.kind")
	AttrInputs     = attribute.Key("fabriq.model.inputs")
	// AttrConsumerGroup is the OTel messaging semconv key for a consumer
	// group (proj:graph, proj:search, ...).
	AttrConsumerGroup = attribute.Key("messaging.consumer.group.name")
	// AttrMessagingSystem is the OTel messaging semconv system key.
	AttrMessagingSystem = attribute.Key("messaging.system")
)

Attribute keys fabriq puts on spans. Values are counts, booleans and bounded enum strings, plus the entity name (spans only, never a metric label: runtime dynamic entities make it unbounded).

View Source
const ScopeName = "github.com/xraph/fabriq/core"

ScopeName is the instrumentation scope of every span core starts.

Variables

This section is empty.

Functions

func Classify

func Classify(err error) string

Classify maps an error onto the bounded result enum the duration metrics use: ok, not_found, conflict or error.

func Detach

func Detach(ctx context.Context) context.Context

Detach returns ctx with its span removed. Cancellation, deadlines and values (the tenant) survive; only the trace parent goes. Every long-lived loop calls it once where its ctx is made, so queries an idle tick runs never land in the boot or request trace the loop was started from (grove starts a db.client span under any valid span context, even an ended one).

func ErrorType

func ErrorType(err error) string

ErrorType names err for an exception.type attribute: a known sentinel's name, else the Go type of the innermost wrapped error.

func Fail

func Fail(span trace.Span, class string, err error)

Fail marks span as failed. The status description is class, a short fixed string chosen by the caller, and the exception event carries only the error's type. Error text never reaches the span: driver and library messages quote values (keys, payload fragments, DSNs).

func LinkFromTraceparent

func LinkFromTraceparent(traceparent string) (trace.Link, bool)

LinkFromTraceparent turns a stored W3C traceparent into a span link. ok is false for an empty or malformed value.

func StartConsumer

func StartConsumer(ctx context.Context, name, traceparent string, attrs ...attribute.KeyValue) (context.Context, trace.Span)

StartConsumer starts the span for one consumed message: a new root of kind Consumer, linked (not parented) to the producer context stored in traceparent. The request that produced the message has usually finished by the time it is consumed, so the consumer's work gets its own trace and the link leads back to the producer.

func StartRoot

func StartRoot(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartRoot starts a new root span on core's tracer from a detached copy of ctx, for one unit of background work. opts may add a kind, links and attributes.

func Tracer

func Tracer() trace.Tracer

Tracer returns core's tracer from the global provider. It is looked up per call so a provider installed after package init (forge.New, a test's recorder) is always the one in use.

func WithoutBaggage

func WithoutBaggage(ctx context.Context) context.Context

WithoutBaggage drops inbound W3C baggage from ctx. Calls that leave for a third party (a model provider behind an Embedder or Summarizer) start from it, so a client's baggage never travels to that provider.

Types

type ApplyObserver

type ApplyObserver interface {
	ObserveApply(projection, result string, elapsed time.Duration)
}

ApplyObserver receives one observation per envelope a projection consumer applies. projection is graph, search, analytics or insights; result is ok or error.

type CommandObserver

type CommandObserver interface {
	ObserveCommand(op, result string, elapsed time.Duration)
}

CommandObserver receives one observation per command batch the executor runs. op is create, update, delete, upsert, mixed for a batch that combines several, or unknown for an op value the executor doesn't define (such a batch always fails validation, so its result is invalid). result is ok, invalid, conflict, not_found or error.

Directories

Path Synopsis
Package telemetrytest holds test helpers for fabriq's tracing: a span recorder installed as the global tracer provider, and a scan that proves a value never reached a span.
Package telemetrytest holds test helpers for fabriq's tracing: a span recorder installed as the global tracer provider, and a scan that proves a value never reached a span.

Jump to

Keyboard shortcuts

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