Skip to content

Commit

Permalink
Add Base2ExponentialHistogram example (#4518)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Sep 18, 2023
1 parent 2373e9b commit a5190f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sdk/metric/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions sdk/metric/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
)
}

0 comments on commit a5190f6

Please sign in to comment.