@@ -280,6 +280,18 @@ func createInt64Counter(setOfMetrics map[string]bool, metricName string, meter o
280280 return ret
281281}
282282
283+ func createInt64UpDownCounter (setOfMetrics map [string ]bool , metricName string , meter otelmetric.Meter , options ... otelmetric.Int64UpDownCounterOption ) otelmetric.Int64UpDownCounter {
284+ if _ , ok := setOfMetrics [metricName ]; ! ok {
285+ return noop.Int64UpDownCounter {}
286+ }
287+ ret , err := meter .Int64UpDownCounter (string (metricName ), options ... )
288+ if err != nil {
289+ logger .Errorf ("failed to register metric \" %v\" , will not record: %v" , metricName , err )
290+ return noop.Int64UpDownCounter {}
291+ }
292+ return ret
293+ }
294+
283295func createFloat64Counter (setOfMetrics map [string ]bool , metricName string , meter otelmetric.Meter , options ... otelmetric.Float64CounterOption ) otelmetric.Float64Counter {
284296 if _ , ok := setOfMetrics [metricName ]; ! ok {
285297 return noop.Float64Counter {}
@@ -350,11 +362,12 @@ func optionFromLabels(labelKeys []string, optionalLabelKeys []string, optionalLa
350362// registryMetrics implements MetricsRecorder for the client and server stats
351363// handlers.
352364type registryMetrics struct {
353- intCounts map [* estats.MetricDescriptor ]otelmetric.Int64Counter
354- floatCounts map [* estats.MetricDescriptor ]otelmetric.Float64Counter
355- intHistos map [* estats.MetricDescriptor ]otelmetric.Int64Histogram
356- floatHistos map [* estats.MetricDescriptor ]otelmetric.Float64Histogram
357- intGauges map [* estats.MetricDescriptor ]otelmetric.Int64Gauge
365+ intCounts map [* estats.MetricDescriptor ]otelmetric.Int64Counter
366+ floatCounts map [* estats.MetricDescriptor ]otelmetric.Float64Counter
367+ intHistos map [* estats.MetricDescriptor ]otelmetric.Int64Histogram
368+ floatHistos map [* estats.MetricDescriptor ]otelmetric.Float64Histogram
369+ intGauges map [* estats.MetricDescriptor ]otelmetric.Int64Gauge
370+ intUpDownCounts map [* estats.MetricDescriptor ]otelmetric.Int64UpDownCounter
358371
359372 optionalLabels []string
360373}
@@ -365,6 +378,7 @@ func (rm *registryMetrics) registerMetrics(metrics *stats.MetricSet, meter otelm
365378 rm .intHistos = make (map [* estats.MetricDescriptor ]otelmetric.Int64Histogram )
366379 rm .floatHistos = make (map [* estats.MetricDescriptor ]otelmetric.Float64Histogram )
367380 rm .intGauges = make (map [* estats.MetricDescriptor ]otelmetric.Int64Gauge )
381+ rm .intUpDownCounts = make (map [* estats.MetricDescriptor ]otelmetric.Int64UpDownCounter )
368382
369383 for metric := range metrics .Metrics () {
370384 desc := estats .DescriptorForMetric (metric )
@@ -385,6 +399,8 @@ func (rm *registryMetrics) registerMetrics(metrics *stats.MetricSet, meter otelm
385399 rm .floatHistos [desc ] = createFloat64Histogram (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ), otelmetric .WithExplicitBucketBoundaries (desc .Bounds ... ))
386400 case estats .MetricTypeIntGauge :
387401 rm .intGauges [desc ] = createInt64Gauge (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ))
402+ case estats .MetricTypeIntUpDownCount :
403+ rm .intUpDownCounts [desc ] = createInt64UpDownCounter (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ))
388404 }
389405 }
390406}
@@ -397,6 +413,14 @@ func (rm *registryMetrics) RecordInt64Count(handle *estats.Int64CountHandle, inc
397413 }
398414}
399415
416+ func (rm * registryMetrics ) RecordInt64UpDownCount (handle * estats.Int64UpDownCountHandle , incr int64 , labels ... string ) {
417+ desc := handle .Descriptor ()
418+ if ic , ok := rm .intUpDownCounts [desc ]; ok {
419+ ao := optionFromLabels (desc .Labels , desc .OptionalLabels , rm .optionalLabels , labels ... )
420+ ic .Add (context .TODO (), incr , ao )
421+ }
422+ }
423+
400424func (rm * registryMetrics ) RecordFloat64Count (handle * estats.Float64CountHandle , incr float64 , labels ... string ) {
401425 desc := handle .Descriptor ()
402426 if fc , ok := rm .floatCounts [desc ]; ok {
0 commit comments