Skip to content

Commit

Permalink
move view example into prometheus example, and deprecate /example/view
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Oct 20, 2023
1 parent 1e1cc90 commit d7f4769
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add the `go.opentelemetry.io/otel/trace/embedded` package to be embedded in the exported trace API interfaces. (#4620)
- Add the `go.opentelemetry.io/otel/trace/noop` package as a default no-op implementation of the trace API. (#4620)
- Add context propagation in `go.opentelemetry.io/otel/example/dice`. (#4644)
- Add view configuration to `go.opentelemetry.io/otel/example/prometheus`. (#4649)

### Deprecated

- Deprecate `go.opentelemetry.io/otel/bridge/opencensus.NewTracer` in favor of `opencensus.InstallTraceBridge`. (#4567)
- Deprecate `go.opentelemetry.io/otel/example/fib` package is in favor of `go.opentelemetry.io/otel/example/dice`. (#4618)
- Deprecate `go.opentelemetry.io/otel/trace.NewNoopTracerProvider`.
Use the added `NewTracerProvider` function in `go.opentelemetry.io/otel/trace/noop` instead. (#4620)
- Deprecate `go.opentelemetry.io/otel/example/view` package in favor of `go.opentelemetry.io/otel/example/prometheus`. (#4649)

### Changed

Expand Down
32 changes: 25 additions & 7 deletions example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ 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"
)

const meterName = "github.com/open-telemetry/opentelemetry-go/example/prometheus"

func main() {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
ctx := context.Background()
Expand All @@ -43,8 +46,23 @@ func main() {
if err != nil {
log.Fatal(err)
}
provider := metric.NewMeterProvider(metric.WithReader(exporter))
meter := provider.Meter("github.com/open-telemetry/opentelemetry-go/example/prometheus")
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},
},
},
)),
)
meter := provider.Meter(meterName)

// Start the prometheus HTTP server and pass the exporter Collector to it
go serveMetrics()
Expand Down Expand Up @@ -75,14 +93,14 @@ func main() {
}

// This is the equivalent of prometheus.NewHistogramVec
histogram, err := meter.Float64Histogram("baz", api.WithDescription("a very nice histogram"))
histogram, err := meter.Float64Histogram("baz", api.WithDescription("a histogram with custom buckets and rename"))
if err != nil {
log.Fatal(err)
}
histogram.Record(ctx, 23, opt)
histogram.Record(ctx, 7, opt)
histogram.Record(ctx, 101, opt)
histogram.Record(ctx, 105, opt)
histogram.Record(ctx, 136, opt)
histogram.Record(ctx, 64, opt)
histogram.Record(ctx, 701, opt)
histogram.Record(ctx, 830, opt)

ctx, _ = signal.NotifyContext(ctx, os.Interrupt)
<-ctx.Done()
Expand Down
2 changes: 2 additions & 0 deletions example/view/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
// limitations under the License.

// Package main provides a code sample of using metric views to customize instruments.
//
// Deprecated: See [go.opentelemetry.io/otel/example/prometheus] instead.
package main
1 change: 1 addition & 0 deletions example/view/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Deprecated: see go.opentelemetry.io/otel/example/prometheus instead.
module go.opentelemetry.io/otel/example/view

go 1.20
Expand Down

0 comments on commit d7f4769

Please sign in to comment.