Skip to content

Commit

Permalink
Use WithExplicitBucketBoundaries in the prometheus example (#4686)
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole authored Nov 2, 2023
1 parent 437bc82 commit e3d0c50
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/prometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand Down
24 changes: 6 additions & 18 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e3d0c50

Please sign in to comment.