telemetry

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 23 Imported by: 3

Documentation

Overview

Package telemetry provides an API for reporting engine-level telemtry data.

It wraps OpenTelemetry's tracing, metrics and logging APIs to provide a simplified and consistent interface for following the Dogma project's instrumentation conventions.

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 NewSLogProvider added in v0.19.16

func NewSLogProvider(target *slog.Logger) log.LoggerProvider

NewSLogProvider returns a log.LoggerProvider thats writes logs to the provided slog.Logger.

Types

type Attr

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

Attr is a telemetry attribute.

func Binary

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 Duration

func Duration(k string, v time.Duration) Attr

Duration returns a string attributing containing v in human readable format.

func Float

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

Float returns a float64 attribute.

func Int

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

Int returns an int64 attribute.

func MessageTypeName

func MessageTypeName(k string, id *uuidpb.UUID) Attr

MessageTypeName returns a string attribute set to the registered name of the

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 Time

func Time(k string, v time.Time) Attr

Time returns a string attribute containing v in time.RFC3339Nano format.

func Type

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

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

func UUID

func UUID(k string, v *uuidpb.UUID) Attr

UUID returns an attribute that is the string representation of a UUID.

type Instrument

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
	// contains filtered or unexported fields
}

Provider provides Recorder instances scoped to particular subsystems.

The zero value of a *Provider is equivalent to a provider configured with no-op tracer, meter and logging providers.

func NewTestProvider

func NewTestProvider(t TestingT) *Provider

NewTestProvider returns a Provider that records logs to t.

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.

func (*Provider) WithAttrs added in v0.20.0

func (p *Provider) WithAttrs(attrs ...Attr) *Provider

WithAttrs returns a copy of p with the given attributes appended to its existing attributes.

type Recorder

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

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

func (*Recorder) Counter

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

Counter returns a new monotonic counter instrument.

func (*Recorder) Error

func (r *Recorder) Error(
	ctx context.Context,
	event, message string,
	err error,
	attrs ...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

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

Histogram returns a new histogram instrument.

func (*Recorder) Info

func (r *Recorder) Info(
	ctx context.Context,
	event, message string,
	attrs ...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

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.

type TestingT

type TestingT interface {
	Helper()
	Log(...any)
}

TestingT is the subset of testing.TB that is used by the test provider.

Jump to

Keyboard shortcuts

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