@@ -5,6 +5,7 @@ use crate::ByteArrayRef;
55use crate :: MetadataRef ;
66
77use serde_json:: json;
8+ use std:: collections:: HashMap ;
89use std:: fmt;
910use std:: net:: SocketAddr ;
1011use std:: str:: FromStr ;
@@ -17,6 +18,7 @@ use temporal_sdk_core::telemetry::{build_otlp_metric_exporter, start_prometheus_
1718use temporal_sdk_core:: CoreRuntime ;
1819use temporal_sdk_core:: TokioRuntimeBuilder ;
1920use temporal_sdk_core_api:: telemetry:: metrics:: CoreMeter ;
21+ use temporal_sdk_core_api:: telemetry:: HistogramBucketOverrides ;
2022use temporal_sdk_core_api:: telemetry:: MetricTemporality ;
2123use temporal_sdk_core_api:: telemetry:: { CoreLog , CoreLogConsumer } ;
2224use temporal_sdk_core_api:: telemetry:: {
@@ -85,6 +87,9 @@ pub struct OpenTelemetryOptions {
8587 metric_temporality : OpenTelemetryMetricTemporality ,
8688 durations_as_seconds : bool ,
8789 protocol : OpenTelemetryProtocol ,
90+ /// Histogram bucket overrides in form of
91+ /// <metric1>\n<float>,<float>,<float>\n<metric2>\n<float>,<float>,<float>
92+ histogram_bucket_overrides : MetadataRef ,
8893}
8994
9095#[ repr( C ) ]
@@ -105,6 +110,9 @@ pub struct PrometheusOptions {
105110 counters_total_suffix : bool ,
106111 unit_suffix : bool ,
107112 durations_as_seconds : bool ,
113+ /// Histogram bucket overrides in form of
114+ /// <metric1>\n<float>,<float>,<float>\n<metric2>\n<float>,<float>,<float>
115+ histogram_bucket_overrides : MetadataRef ,
108116}
109117
110118#[ derive( Clone ) ]
@@ -378,7 +386,12 @@ fn create_meter(
378386 OpenTelemetryMetricTemporality :: Delta => MetricTemporality :: Delta ,
379387 } )
380388 . global_tags ( options. global_tags . to_string_map_on_newlines ( ) )
381- . use_seconds_for_durations ( otel_options. durations_as_seconds ) ;
389+ . use_seconds_for_durations ( otel_options. durations_as_seconds )
390+ . histogram_bucket_overrides ( HistogramBucketOverrides {
391+ overrides : parse_histogram_bucket_overrides (
392+ & otel_options. histogram_bucket_overrides ,
393+ ) ?,
394+ } ) ;
382395 if otel_options. metric_periodicity_millis > 0 {
383396 build. metric_periodicity ( Duration :: from_millis (
384397 otel_options. metric_periodicity_millis . into ( ) ,
@@ -398,7 +411,12 @@ fn create_meter(
398411 . global_tags ( options. global_tags . to_string_map_on_newlines ( ) )
399412 . counters_total_suffix ( prom_options. counters_total_suffix )
400413 . unit_suffix ( prom_options. unit_suffix )
401- . use_seconds_for_durations ( prom_options. durations_as_seconds ) ;
414+ . use_seconds_for_durations ( prom_options. durations_as_seconds )
415+ . histogram_bucket_overrides ( HistogramBucketOverrides {
416+ overrides : parse_histogram_bucket_overrides (
417+ & prom_options. histogram_bucket_overrides ,
418+ ) ?,
419+ } ) ;
402420 Ok ( start_prometheus_metric_exporter ( build. build ( ) ?) ?. meter )
403421 } else if let Some ( custom_meter) = custom_meter {
404422 Ok ( Arc :: new ( custom_meter) )
@@ -408,3 +426,19 @@ fn create_meter(
408426 ) )
409427 }
410428}
429+
430+ fn parse_histogram_bucket_overrides (
431+ raw : & MetadataRef ,
432+ ) -> anyhow:: Result < HashMap < String , Vec < f64 > > > {
433+ raw. to_string_map_on_newlines ( )
434+ . into_iter ( )
435+ . map ( |( k, v) | {
436+ let vals: anyhow:: Result < Vec < f64 > > = v
437+ . split ( ',' )
438+ . map ( str:: parse :: < f64 > )
439+ . collect :: < Result < _ , _ > > ( ) // Result<Vec<f64>, ParseFloatError>
440+ . map_err ( Into :: into) ;
441+ vals. map ( |vals| ( k, vals) )
442+ } )
443+ . collect ( )
444+ }
0 commit comments