@@ -7,7 +7,7 @@ use crate::runtime::telemetry::sampler::SamplerOption;
7
7
use apollo_mcp_server:: generated:: telemetry:: TelemetryAttribute ;
8
8
use opentelemetry:: { Key , KeyValue , global, trace:: TracerProvider as _} ;
9
9
use opentelemetry_otlp:: WithExportConfig ;
10
- use opentelemetry_sdk:: metrics:: { Instrument , Stream } ;
10
+ use opentelemetry_sdk:: metrics:: { Instrument , Stream , Temporality } ;
11
11
use opentelemetry_sdk:: {
12
12
Resource ,
13
13
metrics:: { MeterProviderBuilder , PeriodicReader , SdkMeterProvider } ,
@@ -44,17 +44,34 @@ pub struct MetricsExporters {
44
44
omitted_attributes : Option < HashSet < TelemetryAttribute > > ,
45
45
}
46
46
47
+ #[ derive( Debug , Deserialize , JsonSchema ) ]
48
+ pub enum MetricTemporality {
49
+ Cumulative ,
50
+ Delta ,
51
+ }
52
+
53
+ impl MetricTemporality {
54
+ pub fn to_sdk ( & self ) -> Temporality {
55
+ match self {
56
+ MetricTemporality :: Cumulative => Temporality :: Cumulative ,
57
+ MetricTemporality :: Delta => Temporality :: Delta ,
58
+ }
59
+ }
60
+ }
61
+
47
62
#[ derive( Debug , Deserialize , JsonSchema ) ]
48
63
pub struct OTLPMetricExporter {
49
64
endpoint : String ,
50
65
protocol : String ,
66
+ temporality : MetricTemporality ,
51
67
}
52
68
53
69
impl Default for OTLPMetricExporter {
54
70
fn default ( ) -> Self {
55
71
Self {
56
72
endpoint : "http://localhost:4317" . into ( ) ,
57
73
protocol : "grpc" . into ( ) ,
74
+ temporality : MetricTemporality :: Cumulative ,
58
75
}
59
76
}
60
77
}
@@ -122,10 +139,12 @@ fn init_meter_provider(telemetry: &Telemetry) -> Result<SdkMeterProvider, anyhow
122
139
"grpc" => opentelemetry_otlp:: MetricExporter :: builder ( )
123
140
. with_tonic ( )
124
141
. with_endpoint ( otlp. endpoint . clone ( ) )
142
+ . with_temporality ( otlp. temporality . to_sdk ( ) )
125
143
. build ( ) ?,
126
144
"http/protobuf" => opentelemetry_otlp:: MetricExporter :: builder ( )
127
145
. with_http ( )
128
146
. with_endpoint ( otlp. endpoint . clone ( ) )
147
+ . with_temporality ( otlp. temporality . to_sdk ( ) )
129
148
. build ( ) ?,
130
149
other => {
131
150
return Err ( anyhow:: anyhow!(
@@ -331,6 +350,7 @@ mod tests {
331
350
otlp : Some ( OTLPMetricExporter {
332
351
protocol : "bogus" . to_string ( ) ,
333
352
endpoint : "http://localhost:4317" . to_string ( ) ,
353
+ temporality : MetricTemporality :: Cumulative ,
334
354
} ) ,
335
355
omitted_attributes : None ,
336
356
} ) ,
@@ -354,6 +374,7 @@ mod tests {
354
374
otlp : Some ( OTLPMetricExporter {
355
375
protocol : "http/protobuf" . to_string ( ) ,
356
376
endpoint : "http://localhost:4318/v1/metrics" . to_string ( ) ,
377
+ temporality : MetricTemporality :: Delta ,
357
378
} ) ,
358
379
omitted_attributes : None ,
359
380
} ) ,
0 commit comments