telemetry

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorInstrumentNotFound is the error msg template which will be used for invalid instrument IDs on updates
	ErrorInstrumentNotFound string = "instrument with name %s not found"
	// ErrorValueNotCastable is the error msg template which will be used if an instrument is found, but it is
	// of a different type than the expected one.
	ErrorValueNotCastable string = "unable to cast to %T: %+v"

	// UnitMilliseconds is the unit label for milliseconds
	UnitMilliseconds = "ms"
	// UnitBytes is the unit label for bytes
	UnitBytes = "By"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsProvider added in v0.2.0

type MetricsProvider interface {
	// Configure metrics provider
	Configure(ctx context.Context) error
	// WrapHTTPHandler Wrap an HTTP handler with metrics
	WrapHTTPHandler(ctx context.Context, handler http.Handler) http.Handler
	// GetHTTPMetricsHandler Get a handler which can be exposed as "/metrics" endpoint
	GetHTTPMetricsHandler() (http.Handler, error)
	// GetGrpcInstrumentationHandler returns the instrumentation handler for a gRPC server
	GetGrpcInstrumentationHandler() stats.Handler
	// UpdateHistogramMetric write a value with labels to a histogram
	UpdateHistogramMetric(ctx context.Context, metric constants.MetricInstrument, value any, labels map[string]string)
	// UpdateGaugeMetric write a value with labels to a gauge
	UpdateGaugeMetric(ctx context.Context, metric constants.MetricInstrument, value any, labels map[string]string)
	// UpdateCounterMetric Increment a counter by a value
	UpdateCounterMetric(ctx context.Context, metric constants.MetricInstrument, value any, labels map[string]string)
	// Shutdown Gracefully shutdown
	Shutdown(ctx context.Context)
}

MetricsProvider is able to record and publish metrics

func NewMetricsProvider added in v0.2.0

func NewMetricsProvider(ctx context.Context, name, format, protocol, endpoint string) (MetricsProvider, error)

NewMetricsProvider creates a new metrics struct exporting metrics using the specified format and the protocol to use If the Prometheus format is chosen, the protocol attribute will be ignored

func NewNoopMetricProvider added in v0.2.0

func NewNoopMetricProvider() MetricsProvider

NewNoopMetricProvider instantiates a MetricsProvider which does nothing. This impl is used if no metrics provided is configured

type PassThroughResponseWriter

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

PassThroughResponseWriter wraps a http.ResponseWriter but the status code and body can be accessed. This is useful for e.g. logging and tracing

func NewPassThroughResponseWriter

func NewPassThroughResponseWriter(w http.ResponseWriter) *PassThroughResponseWriter

NewPassThroughResponseWriter wraps the given http.ResponseWriter

func (*PassThroughResponseWriter) Body

func (w *PassThroughResponseWriter) Body() []byte

Body returns the response body

func (*PassThroughResponseWriter) Header

Header returns the response http.Header

func (*PassThroughResponseWriter) StatusCode

func (w *PassThroughResponseWriter) StatusCode() int

StatusCode returns the response status code

func (*PassThroughResponseWriter) Write

func (w *PassThroughResponseWriter) Write(b []byte) (int, error)

Write records the data and passes the buffer to the underlying http.ResponseWriter

func (*PassThroughResponseWriter) WriteHeader

func (w *PassThroughResponseWriter) WriteHeader(statusCode int)

WriteHeader records the statusCode and passes it on to the underlying http.ResponseWriter

type SpanFunction added in v0.2.0

type SpanFunction func(ctx context.Context, args ...any) (any, error)

SpanFunction represents a function, which will be wrapped in a tracing span

type TraceProvider added in v0.2.0

type TraceProvider interface {
	// Configure trace provider
	Configure(ctx context.Context) error
	// WrapHTTPHandler Wrap an HTTP handler with span creation
	WrapHTTPHandler(ctx context.Context, handler http.Handler, spanName string) http.Handler
	// GetGrpcInstrumentationHandler returns the instrumentation handler for a gRPC server
	GetGrpcInstrumentationHandler() stats.Handler
	// ExecuteWithRootSpan starts a new root span and executes the function
	ExecuteWithRootSpan(ctx context.Context, function SpanFunction, spanName string, labels map[string]string, args ...any) (any, error)
	// ExecuteWithChildSpan starts a new child span and executes the function
	ExecuteWithChildSpan(ctx context.Context, function SpanFunction, spanName string, labels map[string]string, args ...any) (any, error)
	// Shutdown Gracefully shutdown
	Shutdown(ctx context.Context)
}

TraceProvider is able to record and publish traces

func NewNoopTraceProvider added in v0.2.0

func NewNoopTraceProvider() TraceProvider

NewNoopTraceProvider instantiates a TraceProvider which does nothing. This impl is used if tracing is not configured.

func NewTraceProvider added in v0.2.0

func NewTraceProvider(ctx context.Context, name, protocol, endpoint string) (TraceProvider, error)

NewTraceProvider tries to create a new trace provider using the provided protocol and push endpoint

Jump to

Keyboard shortcuts

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