Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move view example into prometheus example, and deprecate /example/view #4649

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
2 changes: 1 addition & 1 deletion example/prometheus/go.mod
Expand Up @@ -7,6 +7,7 @@ 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 @@ -20,7 +21,6 @@ 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
32 changes: 25 additions & 7 deletions example/prometheus/main.go
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
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
@@ -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