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 ¶
- Variables
- func NewSLogProvider(target *slog.Logger) log.LoggerProvider
- type Attr
- func Binary(k string, v []byte) Attr
- func Bool[T ~bool](k string, v T) Attr
- func Duration(k string, v time.Duration) Attr
- func Float[T constraints.Float](k string, v T) Attr
- func Int[T constraints.Integer](k string, v T) Attr
- func MessageTypeName(k string, id *uuidpb.UUID) Attr
- func String[T ~string](k string, v T) Attr
- func Stringer(k string, v fmt.Stringer) Attr
- func Time(k string, v time.Time) Attr
- func Type[T any](k string, v T) Attr
- func UUID(k string, v *uuidpb.UUID) Attr
- type Instrument
- type Provider
- type Recorder
- func (r *Recorder) Counter(name, unit, desc string) Instrument[int64]
- func (r *Recorder) Error(ctx context.Context, event, message string, err error, attrs ...Attr)
- func (r *Recorder) Histogram(name, unit, desc string) Instrument[int64]
- func (r *Recorder) Info(ctx context.Context, event, message string, attrs ...Attr)
- func (r *Recorder) StartSpan(ctx context.Context, name string, attrs ...Attr) (context.Context, *Span)
- func (r *Recorder) UpDownCounter(name, unit, desc string) Instrument[int64]
- type Span
- type TestingT
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 MessageTypeName ¶
MessageTypeName returns a string attribute set to the registered name of the
func Time ¶
Time returns a string attribute containing v in time.RFC3339Nano format.
type Instrument ¶
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 ¶
NewTestProvider returns a Provider that records logs to t.
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 ¶
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) 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 ¶
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.