prometheus

package module
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package prometheus provides a bridge from Prometheus to OpenTelemetry.

The Prometheus Bridge allows using the Prometheus Golang client library with the OpenTelemetry SDK. This enables prometheus instrumentation libraries to be used with OpenTelemetry exporters, including OTLP.

Prometheus histograms are translated to OpenTelemetry exponential histograms when native histograms are enabled in the Prometheus client. To enable Prometheus native histograms, set the (currently experimental) NativeHistogram... options of the prometheus HistogramOpts when creating prometheus histograms.

While the Prometheus Bridge has some overhead, it can significantly reduce the combined overall CPU and Memory footprint when sending to an OpenTelemetry Collector. See the benchmarks for more details.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMetricProducer

func NewMetricProducer(opts ...Option) metric.Producer

NewMetricProducer returns a metric.Producer that fetches metrics from Prometheus. This can be used to allow Prometheus instrumentation to be added to an OpenTelemetry export pipeline.

Example
package main

import (
	"go.opentelemetry.io/contrib/bridges/prometheus"
	"go.opentelemetry.io/otel/sdk/metric"
)

func main() {
	// Create a Promethes bridge "Metric Producer" which adds metrics from the
	// prometheus.DefaultGatherer. Add the WithGatherer option to add metrics
	// from other registries.
	bridge := prometheus.NewMetricProducer()
	// This reader is used as a stand-in for a reader that will actually export
	// data. See https://pkg.go.dev/go.opentelemetry.io/otel/exporters for
	// exporters that can be used as or with readers. The metric.WithProducer
	// option adds metrics from the Prometheus bridge to the reader.
	reader := metric.NewManualReader(metric.WithProducer(bridge))
	// Create an OTel MeterProvider with our reader. Metrics from OpenTelemetry
	// instruments are combined with metrics from Prometheus instruments in
	// exported batches of metrics.
	_ = metric.NewMeterProvider(metric.WithReader(reader))
}
Output:

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option sets producer option values.

func WithGatherer

func WithGatherer(gatherer prometheus.Gatherer) Option

WithGatherer configures which prometheus Gatherer the Bridge will gather from. If no registerer is used the prometheus DefaultGatherer is used.

Jump to

Keyboard shortcuts

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