telemetry

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package telemetry is an internal API for observability/instrumentation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReadDirection is an attribute that indicates a read operation.
	ReadDirection = String("network.io.direction", "read")

	// WriteDirection is an attribute that indicates a write operation.
	WriteDirection = String("network.io.direction", "write")
)

Functions

func HandleID

func HandleID() string

HandleID returns a unique identifier for an open instance of a persistence primitive, such as a journal.

It includes a counter component for easy visual identification by humans, and a UUID component for global correlation in observability tools.

Types

type Attr

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

Attr is a telemetry attribute.

func Binary added in v0.11.0

func Binary(k string, v []byte) Attr

Binary returns a string attribute containing v, represented as a Go string (with backslash escaped sequences). If the value is longer than 64 bytes, it is truncated to 64 bytes and the key is suffixed with "_truncated".

func Bool

func Bool[T ~bool](k string, v T) Attr

Bool returns a boolean attribute.

func Float

func Float[T constraints.Float](k string, v T) Attr

Float returns a float64 attribute.

func If

func If(cond bool, attr Attr) Attr

If conditionally includes an attribute.

func Int

func Int[T constraints.Integer](k string, v T) Attr

Int returns an int64 attribute.

func String

func String[T ~string](k string, v T) Attr

String returns a string attribute.

func Stringer

func Stringer(k string, v fmt.Stringer) Attr

Stringer returns a string attribute. The value is the result of calling v.String().

func Type

func Type[T any](k string, v T) Attr

Type returns a string attribute set to the name of T.

type Instrument added in v0.11.0

type Instrument[T any] func(context.Context, T, ...Attr)

Instrument is a function that records a metric value of type T.

type Provider

type Provider struct {
	TracerProvider trace.TracerProvider
	MeterProvider  metric.MeterProvider
	LoggerProvider log.LoggerProvider
}

Provider provides Recorder instances scoped to particular subsystems.

func (*Provider) Recorder

func (p *Provider) Recorder(pkg string, attrs ...Attr) *Recorder

Recorder returns a new Recorder instance.

pkg is the path to the Go package that is performing the instrumentation. If it is an internal package, use the package path of the public parent package instead.

type Recorder

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

Recorder records traces, metrics and logs for a particular subsystem.

func (*Recorder) Counter added in v0.11.0

func (r *Recorder) Counter(name, unit, desc string) Instrument[int64]

Counter returns a new monotonic counter instrument.

func (*Recorder) Error added in v0.11.0

func (r *Recorder) Error(
	ctx context.Context,
	event string,
	err error,
	body ...Attr,
)

Error logs an error message to the log and as a span event.

It marks the span as an error and emits increments the "errors" metric.

func (*Recorder) Histogram added in v0.11.0

func (r *Recorder) Histogram(name, unit, desc string) Instrument[int64]

Histogram returns a new histogram instrument.

func (*Recorder) Info added in v0.11.0

func (r *Recorder) Info(
	ctx context.Context,
	event, message string,
	body ...Attr,
)

Info logs an informational message to the log and as a span event.

func (*Recorder) StartSpan

func (r *Recorder) StartSpan(
	ctx context.Context,
	name string,
	attrs ...Attr,
) (context.Context, *Span)

StartSpan starts a new span and records the operation to the recorder's operation counter and "in-flight" gauge instruments.

func (*Recorder) UpDownCounter added in v0.11.0

func (r *Recorder) UpDownCounter(name, unit, desc string) Instrument[int64]

UpDownCounter returns a new counter instrument that can increase or decrease.

type Span

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

Span represents a single named and timed operation of a workflow.

func (*Span) End

func (s *Span) End()

End completes the span and decrements the "in-flight" gauge instrument.

func (*Span) SetAttributes

func (s *Span) SetAttributes(attrs ...Attr)

SetAttributes adds the given attributes to the underlying OpenTelemetry span and any future log messages.

Jump to

Keyboard shortcuts

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