File: example_test.go

package info (click to toggle)
golang-opentelemetry-contrib 0.56.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,884 kB
  • sloc: makefile: 278; sh: 211; sed: 1
file content (25 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package prometheus_test

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

func ExampleNewMetricProducer() {
	// 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))
}