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
- func NewGaugeStore() *gaugeStore
- func NewOTELReader(client MetricsClient, endpointProvider EndpointProvider, ...) otelsdk.Reader
- type ConfigProvider
- type EndpointProvider
- type MetricsClient
- type OTELExporter
- func (e *OTELExporter) Aggregation(kind metric.InstrumentKind) aggregation.Aggregation
- func (e *OTELExporter) Export(ctx context.Context, metrics *metricdata.ResourceMetrics) error
- func (e *OTELExporter) ForceFlush(ctx context.Context) error
- func (e *OTELExporter) Shutdown(ctx context.Context) error
- func (e *OTELExporter) Temporality(_ metric.InstrumentKind) metricdata.Temporality
- type OTELSink
- func (o *OTELSink) AddSample(key []string, val float32)
- func (o *OTELSink) AddSampleWithLabels(key []string, val float32, labels []gometrics.Label)
- func (o *OTELSink) EmitKey(key []string, val float32)
- func (o *OTELSink) IncrCounter(key []string, val float32)
- func (o *OTELSink) IncrCounterWithLabels(key []string, val float32, labels []gometrics.Label)
- func (o *OTELSink) SetGauge(key []string, val float32)
- func (o *OTELSink) SetGaugeWithLabels(key []string, val float32, labels []gometrics.Label)
- type OTELSinkOpts
Constants ¶
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 MetricsClient, endpointProvider EndpointProvider, 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 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 ¶
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 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 MetricsClient, endpointProvider EndpointProvider) *OTELExporter
NewOTELExporter returns a configured OTELExporter.
func (*OTELExporter) Aggregation ¶
func (e *OTELExporter) Aggregation(kind metric.InstrumentKind) aggregation.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 ¶
func (e *OTELExporter) Temporality(_ metric.InstrumentKind) metricdata.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(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) AddSampleWithLabels ¶
AddSampleWithLabels emits a Consul sample metric that gets registed by an OpenTelemetry Histogram instrument.
func (*OTELSink) IncrCounter ¶
IncrCounter emits a Consul counter metric.
func (*OTELSink) IncrCounterWithLabels ¶
IncrCounterWithLabels emits a Consul counter 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.