From e3d0c50f099e26a6a077f4ac851b2200b703b772 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Thu, 2 Nov 2023 03:02:18 -0400 Subject: [PATCH] Use WithExplicitBucketBoundaries in the prometheus example (#4686) --- example/prometheus/go.mod | 2 +- example/prometheus/main.go | 24 ++++++------------------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/example/prometheus/go.mod b/example/prometheus/go.mod index 22c43d78c3e..56492f91d81 100644 --- a/example/prometheus/go.mod +++ b/example/prometheus/go.mod @@ -7,7 +7,6 @@ require ( go.opentelemetry.io/otel v1.19.0 go.opentelemetry.io/otel/exporters/prometheus v0.42.0 go.opentelemetry.io/otel/metric v1.19.0 - go.opentelemetry.io/otel/sdk v1.19.0 go.opentelemetry.io/otel/sdk/metric v1.19.0 ) @@ -21,6 +20,7 @@ require ( github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect + go.opentelemetry.io/otel/sdk v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.13.0 // indirect google.golang.org/protobuf v1.31.0 // indirect diff --git a/example/prometheus/main.go b/example/prometheus/main.go index 81f23085536..777135cebc2 100644 --- a/example/prometheus/main.go +++ b/example/prometheus/main.go @@ -29,7 +29,6 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/exporters/prometheus" api "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric" ) @@ -46,22 +45,7 @@ func main() { if err != nil { log.Fatal(err) } - provider := metric.NewMeterProvider( - metric.WithReader(exporter), - // View to customize histogram buckets and rename a single histogram instrument. - metric.WithView(metric.NewView( - metric.Instrument{ - Name: "baz", - Scope: instrumentation.Scope{Name: meterName}, - }, - metric.Stream{ - Name: "new_baz", - Aggregation: metric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{64, 128, 256, 512, 1024, 2048, 4096}, - }, - }, - )), - ) + provider := metric.NewMeterProvider(metric.WithReader(exporter)) meter := provider.Meter(meterName) // Start the prometheus HTTP server and pass the exporter Collector to it @@ -93,7 +77,11 @@ func main() { } // This is the equivalent of prometheus.NewHistogramVec - histogram, err := meter.Float64Histogram("baz", api.WithDescription("a histogram with custom buckets and rename")) + histogram, err := meter.Float64Histogram( + "baz", + api.WithDescription("a histogram with custom buckets and rename"), + api.WithExplicitBucketBoundaries(64, 128, 256, 512, 1024, 2048, 4096), + ) if err != nil { log.Fatal(err) }