telemetry

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 24 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

func CleanMetricName(metricName string) string

CleanMetricName cleans metric name from invalid characters.

func ContextWithTelemeter

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

ContextWithTelemeter returns a new context with the provided Telemeter attached.

func NewMetricsExporter

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

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

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

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

func NewMeter

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

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

Count adds to counter provided value.

func (*Meter) Time

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

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

type Telemeter struct {
	*Tracer
	*Meter
	// contains filtered or unexported fields
}

func NewTelemeter

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

NewTelemeter initializes the telemetry collector.

func TelemeterFromContext

func TelemeterFromContext(ctx context.Context) *Telemeter

TelemeterFromContext retrieves the Telemeter from the context. Returns a zero-value Telemeter (safe no-op) if not present or nil.

func (*Telemeter) Collect

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

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

Shutdown shutdowns the telemetry provider.

type Tracer

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

func NewTracer

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

NewTracer creates and configures the traces collection.

func (*Tracer) Trace

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