Debian Codegraph @

bridges/prometheus/example_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package prometheus_test
5
6 import (
7 "go.opentelemetry.io/otel/sdk/metric"
8
9 "go.opentelemetry.io/contrib/bridges/prometheus"
10 )
11
12 func ExampleNewMetricProducer() {
13 // Create a Promethes bridge "Metric Producer" which adds metrics from the
14 // prometheus.DefaultGatherer. Add the WithGatherer option to add metrics
15 // from other registries.
16 bridge := prometheus.NewMetricProducer()
17 // This reader is used as a stand-in for a reader that will actually export
18 // data. See https://pkg.go.dev/go.opentelemetry.io/otel/exporters for
19 // exporters that can be used as or with readers. The metric.WithProducer
20 // option adds metrics from the Prometheus bridge to the reader.
21 reader := metric.NewManualReader(metric.WithProducer(bridge))
22 // Create an OTel MeterProvider with our reader. Metrics from OpenTelemetry
23 // instruments are combined with metrics from Prometheus instruments in
24 // exported batches of metrics.
25 _ = metric.NewMeterProvider(metric.WithReader(reader))
26 }