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 client.MetricsClient, url *url.URL, exportInterval time.Duration) otelsdk.Reader
- 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 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 ¶
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(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.