telemetry

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package telemetry implements functionality to collect, aggregate, convert and export telemetry data in OpenTelemetry Protocol (OTLP) format.

The entrypoint is the OpenTelemetry (OTEL) go-metrics sink which: - Receives metric data. - Aggregates metric data using the OTEL Go Metrics SDK. - Exports metric data using a configurable OTEL exporter.

The package also provides an OTEL exporter implementation to be used within the sink, which: - Transforms metric data from the Metrics SDK OTEL representation to OTLP format. - Exports OTLP metric data to an external endpoint using a configurable client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGaugeStore

func NewGaugeStore() *gaugeStore

NewGaugeStore returns an initialized empty gaugeStore.

func NewOTELReader

func NewOTELReader(client MetricsClient, endpointProvider EndpointProvider) otelsdk.Reader

NewOTELReader returns a configured OTEL PeriodicReader to export metrics every X seconds. It configures the reader with a custom OTELExporter with a MetricsClient to transform and export metrics in OTLP format to an external url.

Types

type ConfigProvider

type ConfigProvider interface {
	// GetLabels should return a set of OTEL attributes added by default all metrics.
	GetLabels() map[string]string

	// GetFilters should return filtesr that are required to enable metric processing.
	// Filters act as an allowlist to collect only the required metrics.
	GetFilters() *regexp.Regexp
}

ConfigProvider is required to provide custom metrics processing.

type EndpointProvider

type EndpointProvider interface {
	GetEndpoint() *url.URL
}

EndpointProvider provides the endpoint where metrics are exported to by the OTELExporter. EndpointProvider exposes the GetEndpoint() interface method to fetch the endpoint. This abstraction layer offers flexibility, in particular for dynamic configuration or changes to the endpoint.

type MetricsClient

type MetricsClient interface {
	ExportMetrics(ctx context.Context, protoMetrics *metricpb.ResourceMetrics, endpoint string) error
}

MetricsClient exports Consul metrics in OTLP format to the desired endpoint.

type OTELSink

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

OTELSink captures and aggregates telemetry data as per the OpenTelemetry (OTEL) specification. Metric data is exported in OpenTelemetry Protocol (OTLP) wire format. This should be used as a Go Metrics backend, as it implements the MetricsSink interface.

func NewOTELSink

func NewOTELSink(ctx context.Context, opts *OTELSinkOpts) (*OTELSink, error)

NewOTELSink returns a sink which fits the Go Metrics MetricsSink interface. It sets up a MeterProvider and Meter, key pieces of the OTEL Metrics SDK which enable us to create OTEL Instruments to record measurements.

func (*OTELSink) AddSample

func (o *OTELSink) AddSample(key []string, val float32)

AddSample emits a Consul histogram metric.

func (*OTELSink) AddSampleWithLabels

func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gometrics.Label)

AddSampleWithLabels emits a Consul sample metric that gets registed by an OpenTelemetry Histogram instrument.

func (*OTELSink) EmitKey

func (o *OTELSink) EmitKey(key []string, val float32)

EmitKey unsupported.

func (*OTELSink) IncrCounter

func (o *OTELSink) IncrCounter(key []string, val float32)

IncrCounter emits a Consul counter metric.

func (*OTELSink) IncrCounterWithLabels

func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gometrics.Label)

IncrCounterWithLabels emits a Consul counter metric that gets registed by an OpenTelemetry Histogram instrument.

func (*OTELSink) SetGauge

func (o *OTELSink) SetGauge(key []string, val float32)

SetGauge emits a Consul gauge metric.

func (*OTELSink) SetGaugeWithLabels

func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometrics.Label)

AddSampleWithLabels emits a Consul gauge metric that gets registed by an OpenTelemetry Histogram instrument.

type OTELSinkOpts

type OTELSinkOpts struct {
	Reader         otelsdk.Reader
	ConfigProvider ConfigProvider
}

OTELSinkOpts is used to provide configuration when initializing an OTELSink using NewOTELSink.

Jump to

Keyboard shortcuts

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