You've already forked opentelemetry-go
							
							
				mirror of
				https://github.com/open-telemetry/opentelemetry-go.git
				synced 2025-10-31 00:07:40 +02:00 
			
		
		
		
	Add Base2ExponentialHistogram example (#4518)
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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), | ||||
| 	) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user