1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +02:00

Add Base2ExponentialHistogram example (#4518)

This commit is contained in:
Robert Pająk 2023-09-18 10:05:33 +02:00 committed by GitHub
parent 2373e9b1e9
commit a5190f632f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -48,8 +48,8 @@ func (AggregationDrop) err() error { return nil }
// make an aggregation selection based on instrument kind that differs from
// the default. This Aggregation ensures the default is used.
//
// See the "go.opentelemetry.io/otel/sdk/metric".DefaultAggregationSelector
// for information about the default instrument kind selection mapping.
// See the [DefaultAggregationSelector] for information about the default
// instrument kind selection mapping.
type AggregationDefault struct{} // AggregationDefault has no parameters.
var _ Aggregation = AggregationDefault{}
@ -161,7 +161,7 @@ type AggregationBase2ExponentialHistogram struct {
// signed 32-bit integer index could be used.
//
// MaxScale has a minimum value of -10. Using a value of -10 means only
// two buckets will be use.
// two buckets will be used.
MaxScale int32
// NoMinMax indicates whether to not record the min and max of the

View File

@ -85,6 +85,8 @@ func ExampleView() {
re := regexp.MustCompile(`[._](ms|byte)$`)
var view metric.View = func(i metric.Instrument) (metric.Stream, bool) {
// In a custom View function, you need to explicitly copy
// the name, description, and unit.
s := metric.Stream{Name: i.Name, Description: i.Description, Unit: i.Unit}
// Any instrument that does not have a unit suffix defined, but has a
// dimensional unit defined, update the name with a unit suffix.
@ -220,3 +222,26 @@ func ExampleNewView_wildcard() {
// name: computation.time.ms
// unit: ms
}
func ExampleNewView_exponentialHistogram() {
// Create a view that makes the "latency" instrument
// to be reported as an exponential histogram.
view := metric.NewView(
metric.Instrument{
Name: "latency",
Scope: instrumentation.Scope{Name: "http"},
},
metric.Stream{
Aggregation: metric.AggregationBase2ExponentialHistogram{
MaxSize: 160,
MaxScale: 20,
},
},
)
// The created view can then be registered with the OpenTelemetry metric
// SDK using the WithView option.
_ = metric.NewMeterProvider(
metric.WithView(view),
)
}