opentelemetry-go icon indicating copy to clipboard operation
opentelemetry-go copied to clipboard

metric.WithExplicitBucketBoundaries is not working as expected

Open huliang-microsoft opened this issue 1 year ago • 4 comments

Description

metric.WithExplicitBucketBoundaries is not working with metric historgram.

Update 5/26/2024: Looks like I can set the histogram bucket in exporter selector but not the metric itself. Is this expected? So we cannot create per histogram metric buckets? and must be using the same buckets for all hostogram?

func MyAggregationSelector(ik metric.InstrumentKind) metric.Aggregation {
	switch ik {
	case metric.InstrumentKindCounter, metric.InstrumentKindUpDownCounter, metric.InstrumentKindObservableCounter, metric.InstrumentKindObservableUpDownCounter:
		return metric.AggregationSum{}
	case metric.InstrumentKindObservableGauge:
		return metric.AggregationLastValue{}
	case metric.InstrumentKindHistogram:
		return metric.AggregationExplicitBucketHistogram{
			Boundaries: []float64{0, 1, 2, 3, 4, 5, 6},
			NoMinMax:   false,
		}
	}
	panic("unknown instrument kind")
}


func createExporter() {
        ...........
	exporter, err := otlpmetrichttp.New(
		ctx,
		otlpmetrichttp.WithHeaders(kv),
		otlpmetrichttp.WithEndpointURL("http://localhost:4318"),
		otlpmetrichttp.WithTemporalitySelector(
			func(metric.InstrumentKind) metricdata.Temporality {
				return metricdata.DeltaTemporality
			},
		),
		otlpmetrichttp.WithAggregationSelector(MyAggregationSelector),
	)
}

Environment

  • OS: Ubuntu 22.04
  • Architecture: x86
  • Go Version: 1.22
  • opentelemetry-go version: 1.24

Steps To Reproduce

The code I am using

meter := otel.Meter("my.session"),
histogram, err = meter.Float64Histogram(
    "my hist",
    metric.WithDescription("my histogram."),
    metric.WithUnit("s"),
    metric.WithExplicitBucketBoundaries(.005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10),
)

Expected behavior

I expected the boundaries will be used but I see the data in collector is still using the default buckets. But the Description and Unit are set correctly. The otel collector I am using is otel/opentelemetry-collector-contrib:0.93.0

Descriptor:
     -> Name: my hist
     -> Description: my histogram.
     -> Unit: s
     -> DataType: Histogram
     -> AggregationTemporality: Cumulative
...
ExplicitBounds #0: 0.000000
ExplicitBounds #1: 5.000000
ExplicitBounds #2: 10.000000
ExplicitBounds #3: 25.000000
ExplicitBounds #4: 50.000000
ExplicitBounds #5: 75.000000
ExplicitBounds #6: 100.000000
ExplicitBounds #7: 250.000000
ExplicitBounds #8: 500.000000
ExplicitBounds #9: 750.000000
ExplicitBounds #10: 1000.000000
ExplicitBounds #11: 2500.000000
ExplicitBounds #12: 5000.000000
ExplicitBounds #13: 7500.000000
ExplicitBounds #14: 10000.000000
Buckets #0, Count: 0
Buckets #1, Count: 10
Buckets #2, Count: 0
Buckets #3, Count: 0
Buckets #4, Count: 0
Buckets #5, Count: 0
Buckets #6, Count: 0
Buckets #7, Count: 0
Buckets #8, Count: 0
Buckets #9, Count: 0
Buckets #10, Count: 0
Buckets #11, Count: 0
Buckets #12, Count: 0
Buckets #13, Count: 0
Buckets #14, Count: 0
Buckets #15, Count: 0

huliang-microsoft avatar May 26 '24 06:05 huliang-microsoft

Please provide a complete example that can be run. I'm not able to reproduce your issue.

MrAlias avatar May 28 '24 14:05 MrAlias

Thanks for the response @MrAlias , I dont know how to provide a complete example? A link to some github repo? I can create one if it is needed. Are you saying you can set the buckets by this method when creating the histogram?

metric.WithExplicitBucketBoundaries(.005, .01, .025, .05, .075, .1, .25, .5, .75, 1, 2.5, 5, 7.5, 10),

Did you mean that you can set the buckets like this and observe the updated buckets on a collector side?

huliang-microsoft avatar Jun 08 '24 07:06 huliang-microsoft

A complete example would be a simple main.go that reproduces the issue.

dmathieu avatar Jun 10 '24 07:06 dmathieu

I am faced with the same problem. The buckets don't apply to the metrics.

koungkub avatar Jun 10 '24 08:06 koungkub

I think I know what went wrong in my case. There is a package version mismatch. After I upgraded all pakcages to 1.27, this setting works.

huliang-microsoft avatar Jul 08 '24 23:07 huliang-microsoft