mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-30 21:20:04 +02:00
Move view example into prometheus example, and deprecate /example/view (#4649)
* move view example into prometheus example, and deprecate /example/view * fix lint --------- Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
parent
16643aea30
commit
cab95bcdef
@ -15,6 +15,7 @@ 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
|
||||
|
||||
@ -22,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- 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
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
@ -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()
|
||||
@ -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()
|
||||
@ -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()
|
||||
|
@ -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,3 +1,4 @@
|
||||
// Deprecated: see go.opentelemetry.io/otel/example/prometheus instead.
|
||||
module go.opentelemetry.io/otel/example/view
|
||||
|
||||
go 1.20
|
||||
|
Loading…
Reference in New Issue
Block a user