otel: go.opentelemetry.io/otel/exporters/metric/prometheus Index | Examples | Files

package prometheus

import "go.opentelemetry.io/otel/exporters/metric/prometheus"



Package Files

prometheus.go sanitize.go

type Config Uses

type Config struct {
    // Registry is the prometheus registry that will be used as the default Registerer and
    // Gatherer if these are not specified.
    // If not set a new empty Registry is created.
    Registry *prometheus.Registry

    // Registerer is the prometheus registerer to register
    // metrics with.
    // If not specified the Registry will be used as default.
    Registerer prometheus.Registerer

    // Gatherer is the prometheus gatherer to gather
    // metrics with.
    // If not specified the Registry will be used as default.
    Gatherer prometheus.Gatherer

    // DefaultSummaryQuantiles is the default summary quantiles
    // to use. Use nil to specify the system-default summary quantiles.
    DefaultSummaryQuantiles []float64

    // DefaultHistogramBoundaries defines the default histogram bucket
    // boundaries.
    DefaultHistogramBoundaries []float64

Config is a set of configs for the tally reporter.

type Exporter Uses

type Exporter struct {
    // contains filtered or unexported fields

Exporter supports Prometheus pulls. It does not implement the sdk/export/metric.Exporter interface--instead it creates a pull controller and reads the latest checkpointed data on-scrape.

func InstallNewPipeline Uses

func InstallNewPipeline(config Config, options ...pull.Option) (*Exporter, error)

InstallNewPipeline instantiates a NewExportPipeline and registers it globally. Typically called as:

hf, err := prometheus.InstallNewPipeline(prometheus.Config{...})

if err != nil {
http.HandleFunc("/metrics", hf)
defer pipeline.Stop()
... Done

func NewExportPipeline Uses

func NewExportPipeline(config Config, options ...pull.Option) (*Exporter, error)

NewExportPipeline sets up a complete export pipeline with the recommended setup, using the recommended selector and standard processor. See the pull.Options.


// Create a meter
exporter, err := prometheus.NewExportPipeline(
    pull.WithResource(resource.New(label.String("R", "V"))),
if err != nil {
meter := exporter.MeterProvider().Meter("example")
ctx := context.Background()

// Use two instruments
counter := otel.Must(meter).NewInt64Counter(
    otel.WithDescription("Counts things"),
recorder := otel.Must(meter).NewInt64ValueRecorder(
    otel.WithDescription("Records values"),

counter.Add(ctx, 100, label.String("key", "value"))
recorder.Record(ctx, 100, label.String("key", "value"))

// GET the HTTP endpoint
var input bytes.Buffer
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", &input)
if err != nil {
exporter.ServeHTTP(resp, req)
data, err := ioutil.ReadAll(resp.Result().Body)
if err != nil {


# HELP a_counter Counts things
# TYPE a_counter counter
a_counter{R="V",key="value"} 100
# HELP a_valuerecorder Records values
# TYPE a_valuerecorder histogram
a_valuerecorder_bucket{R="V",key="value",le="+Inf"} 1
a_valuerecorder_sum{R="V",key="value"} 100
a_valuerecorder_count{R="V",key="value"} 1

func (*Exporter) Controller Uses

func (e *Exporter) Controller() *pull.Controller

Controller returns the controller object that coordinates collection for the SDK.

func (*Exporter) ExportKindFor Uses

func (e *Exporter) ExportKindFor(*otel.Descriptor, aggregation.Kind) export.ExportKind

func (*Exporter) MeterProvider Uses

func (e *Exporter) MeterProvider() otel.MeterProvider

MeterProvider returns the MeterProvider of this exporter.

func (*Exporter) ServeHTTP Uses

func (e *Exporter) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Exporter) SetController Uses

func (e *Exporter) SetController(config Config, options ...pull.Option)

SetController sets up a standard *pull.Controller as the metric provider for this exporter.

Package prometheus imports 16 packages (graph) and is imported by 8 packages. Updated 2020-10-17. Refresh now. Tools for package owners.