Skip to content

Commit

Permalink
[receiver/simpleprometheus] update example to use Meter directly (#9364)
Browse files Browse the repository at this point in the history
* [simpleprometheus] update example to use Meter directly

This is a follow up to #9337.

* update example to avoid using global
  • Loading branch information
Alex Boten committed Jun 3, 2022
1 parent 9f14eb0 commit 3fc0a28
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -26,7 +26,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
"go.opentelemetry.io/otel/sdk/metric/export/aggregation"
Expand All @@ -35,7 +35,7 @@ import (
"go.uber.org/zap"
)

func initMeter() {
func initMeter() metric.Meter {
config := prometheus.Config{}
c := controller.New(
processor.NewFactory(
Expand All @@ -55,16 +55,16 @@ func initMeter() {
go func() {
_ = http.ListenAndServe(":8080", nil)
}()
return exporter.MeterProvider().Meter("federation/prom-counter")
}

func main() {
// set up prometheus
initMeter()
meter := initMeter()
// logging
logger, _ := zap.NewProduction()
defer logger.Sync()
logger.Info("Start Prometheus metrics app")
meter := global.MeterProvider().Meter("federation/prom-counter")
valueRecorder, err := meter.SyncInt64().Histogram("prom_counter")
if err != nil {
log.Panicf("failed to initialize histogram %v", err)
Expand Down

0 comments on commit 3fc0a28

Please sign in to comment.