telemetry

package
v1.15.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MPL-2.0 Imports: 22 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

View Source
const DefaultExportInterval = 10 * time.Second

DefaultExportInterval is a default time interval between export of aggregated metrics.

Variables

This section is empty.

Functions

func NewGaugeStore

func NewGaugeStore() *gaugeStore

NewGaugeStore returns an initialized empty gaugeStore.

func NewOTELReader

func NewOTELReader(client client.MetricsClient, url *url.URL, exportInterval time.Duration) 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 OTELExporter

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

OTELExporter is a custom implementation of a OTEL Metrics SDK metrics.Exporter. The exporter is used by a OTEL Metrics SDK PeriodicReader to export aggregated metrics. This allows us to use a custom client - HCP authenticated MetricsClient.

func NewOTELExporter

func NewOTELExporter(client hcpclient.MetricsClient, endpoint *url.URL) *OTELExporter

NewOTELExporter returns a configured OTELExporter

func (*OTELExporter) Aggregation

Aggregation returns the Aggregation to use for an instrument kind. The default implementation provided by the OTEL Metrics SDK library DefaultAggregationSelector panics. This custom version replicates that logic, but removes the panic.

func (*OTELExporter) Export

func (e *OTELExporter) Export(ctx context.Context, metrics *metricdata.ResourceMetrics) error

Export serializes and transmits metric data to a receiver.

func (*OTELExporter) ForceFlush

func (e *OTELExporter) ForceFlush(ctx context.Context) error

ForceFlush is a no-op, as the MetricsClient client holds no state.

func (*OTELExporter) Shutdown

func (e *OTELExporter) Shutdown(ctx context.Context) error

Shutdown is a no-op, as the MetricsClient is a HTTP client that requires no graceful shutdown.

func (*OTELExporter) Temporality

Temporality returns the Cumulative temporality for metrics aggregation. Telemetry Gateway stores metrics in Prometheus format, so use Cummulative aggregation as default.

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(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
	Ctx     context.Context
	Filters []string
	Labels  map[string]string
}

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