telemetry

package
v0.97.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package telemetry provides a way to collect telemetry from function execution - metrics and traces.

Index

Constants

View Source
const (
	ErrorsCounter = "errors"
)
View Source
const (
	TraceParentEnv = "TRACEPARENT"
)

Variables

This section is empty.

Functions

func CleanMetricName added in v0.66.7

func CleanMetricName(metricName string) string

CleanMetricName cleans metric name from invalid characters.

func ContextWithTelemeter added in v0.77.0

func ContextWithTelemeter(ctx context.Context, telemeter *Telemeter) context.Context

ContextWithTelemeter returns a new context with the provided Telemeter attached.

func NewMetricsExporter added in v0.66.7

func NewMetricsExporter(ctx context.Context, writer io.Writer, opts *Options) (metric.Exporter, error)

NewMetricsExporter - create a new exporter based on the telemetry options.

func NewTraceExporter added in v0.66.7

func NewTraceExporter(ctx context.Context, writer io.Writer, opts *Options) (sdktrace.SpanExporter, error)

NewTraceExporter creates a new exporter based on the telemetry options.

func TraceParentFromContext added in v0.78.4

func TraceParentFromContext(ctx context.Context, telemetry *Options) string

TraceParentFromContext returns the W3C traceparent header value from the context's span, or an error if not available.

Types

type ErrorMissingEnvVariable

type ErrorMissingEnvVariable struct {
	Vars []string
}

ErrorMissingEnvVariable error for missing environment variable.

func (*ErrorMissingEnvVariable) Error

func (e *ErrorMissingEnvVariable) Error() string

type Meter added in v0.77.0

type Meter struct {
	otelmetric.Meter
	// contains filtered or unexported fields
}

func NewMeter added in v0.77.0

func NewMeter(ctx context.Context, appName, appVersion string, writer io.Writer, opts *Options) (*Meter, error)

NewMeter creates and configures the metrics collection.

func (*Meter) Count added in v0.77.0

func (meter *Meter) Count(ctx context.Context, name string, value int64)

Count adds to counter provided value.

func (*Meter) Time added in v0.77.0

func (meter *Meter) Time(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error

Time collects time for function execution

type Options added in v0.77.0

type Options struct {
	// TraceExporter is the type of trace exporter to be used.
	TraceExporter string
	// TraceExporterHTTPEndpoint is the endpoint to which traces will be sent.
	TraceExporterHTTPEndpoint string
	// TraceParent is used as a parent trace context.
	TraceParent string
	// MetricExporter is the type of metrics exporter.
	MetricExporter string
	// TraceExporterInsecureEndpoint is useful for collecting traces locally. If set to true, the exporter will not validate the server certificate.
	TraceExporterInsecureEndpoint bool
	// MetricExporterInsecureEndpoint is useful for local metrics collection. if set to true, the exporter will not validate the server's certificate.
	MetricExporterInsecureEndpoint bool
}

Options are Telemetry options.

type Telemeter added in v0.77.0

type Telemeter struct {
	*Tracer
	*Meter
}

func NewTelemeter added in v0.77.0

func NewTelemeter(ctx context.Context, appName, appVersion string, writer io.Writer, opts *Options) (*Telemeter, error)

NewTelemeter initializes the telemetry collector.

func TelemeterFromContext added in v0.77.0

func TelemeterFromContext(ctx context.Context) *Telemeter

TelemeterFromContext retrieves the Telemeter from the context, or nil if not present.

func (*Telemeter) Collect added in v0.77.0

func (tlm *Telemeter) Collect(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error

Collect collects telemetry from function execution metrics and traces.

func (*Telemeter) Shutdown added in v0.77.0

func (tlm *Telemeter) Shutdown(ctx context.Context) error

Shutdown shutdowns the telemetry provider.

type Tracer added in v0.77.0

type Tracer struct {
	trace.Tracer
	// contains filtered or unexported fields
}

func NewTracer added in v0.77.0

func NewTracer(ctx context.Context, appName, appVersion string, writer io.Writer, opts *Options) (*Tracer, error)

NewTracer creates and configures the traces collection.

func (*Tracer) Trace added in v0.77.0

func (tracer *Tracer) Trace(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error

Trace collects traces for method execution.

Jump to

Keyboard shortcuts

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