55#[ allow( deprecated) ]
66#[ cfg( feature = "gen-tonic-messages" ) ]
77pub mod tonic {
8- use std:: any:: Any ;
9- use std:: fmt;
8+ use std:: fmt:: Debug ;
109
1110 use opentelemetry:: { otel_debug, Key , Value } ;
1211 use opentelemetry_sdk:: metrics:: data:: {
13- Exemplar as SdkExemplar , ExponentialHistogram as SdkExponentialHistogram ,
14- Gauge as SdkGauge , Histogram as SdkHistogram , Metric as SdkMetric , ResourceMetrics ,
12+ AggregatedMetrics , Exemplar as SdkExemplar ,
13+ ExponentialHistogram as SdkExponentialHistogram , Gauge as SdkGauge ,
14+ Histogram as SdkHistogram , Metric as SdkMetric , MetricData , ResourceMetrics ,
1515 ScopeMetrics as SdkScopeMetrics , Sum as SdkSum ,
1616 } ;
1717 use opentelemetry_sdk:: metrics:: Temporality ;
@@ -152,46 +152,27 @@ pub mod tonic {
152152 description : metric. description . to_string ( ) ,
153153 unit : metric. unit . to_string ( ) ,
154154 metadata : vec ! [ ] , // internal and currently unused
155- data : metric. data . as_any ( ) . try_into ( ) . ok ( ) ,
155+ data : Some ( match & metric. data {
156+ AggregatedMetrics :: F64 ( data) => data. into ( ) ,
157+ AggregatedMetrics :: U64 ( data) => data. into ( ) ,
158+ AggregatedMetrics :: I64 ( data) => data. into ( ) ,
159+ } ) ,
156160 }
157161 }
158162 }
159163
160- impl TryFrom < & dyn Any > for TonicMetricData {
161- type Error = ( ) ;
162-
163- fn try_from ( data : & dyn Any ) -> Result < Self , Self :: Error > {
164- if let Some ( hist) = data. downcast_ref :: < SdkHistogram < i64 > > ( ) {
165- Ok ( TonicMetricData :: Histogram ( hist. into ( ) ) )
166- } else if let Some ( hist) = data. downcast_ref :: < SdkHistogram < u64 > > ( ) {
167- Ok ( TonicMetricData :: Histogram ( hist. into ( ) ) )
168- } else if let Some ( hist) = data. downcast_ref :: < SdkHistogram < f64 > > ( ) {
169- Ok ( TonicMetricData :: Histogram ( hist. into ( ) ) )
170- } else if let Some ( hist) = data. downcast_ref :: < SdkExponentialHistogram < i64 > > ( ) {
171- Ok ( TonicMetricData :: ExponentialHistogram ( hist. into ( ) ) )
172- } else if let Some ( hist) = data. downcast_ref :: < SdkExponentialHistogram < u64 > > ( ) {
173- Ok ( TonicMetricData :: ExponentialHistogram ( hist. into ( ) ) )
174- } else if let Some ( hist) = data. downcast_ref :: < SdkExponentialHistogram < f64 > > ( ) {
175- Ok ( TonicMetricData :: ExponentialHistogram ( hist. into ( ) ) )
176- } else if let Some ( sum) = data. downcast_ref :: < SdkSum < u64 > > ( ) {
177- Ok ( TonicMetricData :: Sum ( sum. into ( ) ) )
178- } else if let Some ( sum) = data. downcast_ref :: < SdkSum < i64 > > ( ) {
179- Ok ( TonicMetricData :: Sum ( sum. into ( ) ) )
180- } else if let Some ( sum) = data. downcast_ref :: < SdkSum < f64 > > ( ) {
181- Ok ( TonicMetricData :: Sum ( sum. into ( ) ) )
182- } else if let Some ( gauge) = data. downcast_ref :: < SdkGauge < u64 > > ( ) {
183- Ok ( TonicMetricData :: Gauge ( gauge. into ( ) ) )
184- } else if let Some ( gauge) = data. downcast_ref :: < SdkGauge < i64 > > ( ) {
185- Ok ( TonicMetricData :: Gauge ( gauge. into ( ) ) )
186- } else if let Some ( gauge) = data. downcast_ref :: < SdkGauge < f64 > > ( ) {
187- Ok ( TonicMetricData :: Gauge ( gauge. into ( ) ) )
188- } else {
189- otel_debug ! (
190- name: "TonicMetricData::UnknownAggregator" ,
191- message= "Unknown aggregator type" ,
192- unknown_type= format!( "{:?}" , data) ,
193- ) ;
194- Err ( ( ) )
164+ impl < T > From < & MetricData < T > > for TonicMetricData
165+ where
166+ T : Numeric + Debug ,
167+ {
168+ fn from ( data : & MetricData < T > ) -> Self {
169+ match data {
170+ MetricData :: Gauge ( gauge) => TonicMetricData :: Gauge ( gauge. into ( ) ) ,
171+ MetricData :: Sum ( sum) => TonicMetricData :: Sum ( sum. into ( ) ) ,
172+ MetricData :: Histogram ( hist) => TonicMetricData :: Histogram ( hist. into ( ) ) ,
173+ MetricData :: ExponentialHistogram ( hist) => {
174+ TonicMetricData :: ExponentialHistogram ( hist. into ( ) )
175+ }
195176 }
196177 }
197178 }
@@ -286,7 +267,7 @@ pub mod tonic {
286267
287268 impl < T > From < & SdkSum < T > > for TonicSum
288269 where
289- T : fmt :: Debug + Into < TonicExemplarValue > + Into < TonicDataPointValue > + Copy ,
270+ T : Debug + Into < TonicExemplarValue > + Into < TonicDataPointValue > + Copy ,
290271 {
291272 fn from ( sum : & SdkSum < T > ) -> Self {
292273 TonicSum {
@@ -310,7 +291,7 @@ pub mod tonic {
310291
311292 impl < T > From < & SdkGauge < T > > for TonicGauge
312293 where
313- T : fmt :: Debug + Into < TonicExemplarValue > + Into < TonicDataPointValue > + Copy ,
294+ T : Debug + Into < TonicExemplarValue > + Into < TonicDataPointValue > + Copy ,
314295 {
315296 fn from ( gauge : & SdkGauge < T > ) -> Self {
316297 TonicGauge {
0 commit comments