Skip to content

Commit e1d8dcd

Browse files
swcollardDaleSeo
andcommitted
feat: Add configuration option for metric temporality
Update config file docs to add information about Temporality Co-authored-by: Dale Seo <[email protected]>
1 parent 4781d95 commit e1d8dcd

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### feat: Add configuration option for metric temporality - @swcollard PR #413
2+
3+
Creates a new configuration option for telemetry to set the Metric temporality to either Cumulative (default) or Delta.
4+
5+
* Cumulative - The metric value will be the overall value since the start of the measurement.
6+
* Delta - The metric will be the difference in the measurement since the last time it was reported.
7+
8+
Some observability vendors require that one is used over the other so we want to support the configuration in the MCP Server.

crates/apollo-mcp-server/src/runtime/telemetry.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::runtime::telemetry::sampler::SamplerOption;
77
use apollo_mcp_server::generated::telemetry::TelemetryAttribute;
88
use opentelemetry::{Key, KeyValue, global, trace::TracerProvider as _};
99
use opentelemetry_otlp::WithExportConfig;
10-
use opentelemetry_sdk::metrics::{Instrument, Stream};
10+
use opentelemetry_sdk::metrics::{Instrument, Stream, Temporality};
1111
use opentelemetry_sdk::{
1212
Resource,
1313
metrics::{MeterProviderBuilder, PeriodicReader, SdkMeterProvider},
@@ -44,17 +44,38 @@ pub struct MetricsExporters {
4444
omitted_attributes: Option<HashSet<TelemetryAttribute>>,
4545
}
4646

47+
#[derive(Debug, Deserialize, JsonSchema)]
48+
pub enum MetricTemporality {
49+
Cumulative,
50+
Delta,
51+
}
52+
53+
impl OTLPMetricExporter {
54+
pub fn to_temporality(&self) -> Temporality {
55+
match self
56+
.temporality
57+
.as_ref()
58+
.unwrap_or(&MetricTemporality::Cumulative)
59+
{
60+
MetricTemporality::Cumulative => Temporality::Cumulative,
61+
MetricTemporality::Delta => Temporality::Delta,
62+
}
63+
}
64+
}
65+
4766
#[derive(Debug, Deserialize, JsonSchema)]
4867
pub struct OTLPMetricExporter {
4968
endpoint: String,
5069
protocol: String,
70+
temporality: Option<MetricTemporality>,
5171
}
5272

5373
impl Default for OTLPMetricExporter {
5474
fn default() -> Self {
5575
Self {
5676
endpoint: "http://localhost:4317".into(),
5777
protocol: "grpc".into(),
78+
temporality: Some(MetricTemporality::Cumulative),
5879
}
5980
}
6081
}
@@ -122,10 +143,12 @@ fn init_meter_provider(telemetry: &Telemetry) -> Result<SdkMeterProvider, anyhow
122143
"grpc" => opentelemetry_otlp::MetricExporter::builder()
123144
.with_tonic()
124145
.with_endpoint(otlp.endpoint.clone())
146+
.with_temporality(otlp.to_temporality())
125147
.build()?,
126148
"http/protobuf" => opentelemetry_otlp::MetricExporter::builder()
127149
.with_http()
128150
.with_endpoint(otlp.endpoint.clone())
151+
.with_temporality(otlp.to_temporality())
129152
.build()?,
130153
other => {
131154
return Err(anyhow::anyhow!(
@@ -331,6 +354,7 @@ mod tests {
331354
otlp: Some(OTLPMetricExporter {
332355
protocol: "bogus".to_string(),
333356
endpoint: "http://localhost:4317".to_string(),
357+
temporality: None,
334358
}),
335359
omitted_attributes: None,
336360
}),
@@ -354,6 +378,7 @@ mod tests {
354378
otlp: Some(OTLPMetricExporter {
355379
protocol: "http/protobuf".to_string(),
356380
endpoint: "http://localhost:4318/v1/metrics".to_string(),
381+
temporality: Some(MetricTemporality::Delta),
357382
}),
358383
omitted_attributes: None,
359384
}),

docs/source/config-file.mdx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,29 @@ transport:
244244

245245
#### Metrics
246246

247-
| Option | Type | Default | Description |
248-
| :-------------------- | :--------------- | :-------------------------- | :--------------------------------------------- |
249-
| `otlp` | `OTLP Exporter` | `null` (Exporting disabled) | Configuration for exporting metrics via OTLP. |
250-
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from metrics. |
247+
| Option | Type | Default | Description |
248+
| :-------------------- | :---------------------- | :-------------------------- | :--------------------------------------------- |
249+
| `otlp` | `OTLP Metric Exporter` | `null` (Exporting disabled) | Configuration for exporting metrics via OTLP. |
250+
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from metrics. |
251+
252+
253+
#### OTLP Metrics Exporter
254+
255+
| Option | Type | Default | Description |
256+
| :--------- | :--------------------------------------- | :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
257+
| `endpoint` | `URL` | `http://localhost:4137` | URL to export data to. Requires full path. |
258+
| `protocol` | `string` | `grpc` | Protocol for export. Only `grpc` and `http/protobuf` are supported. |
259+
| `temporality` | `MetricTemporality` | `Cumulative` | Optional OTel property that refers to the way additive quantities are expressed, in relation to time, indicating whether reported values incorporate previous measurements (Cumulative) or not (Delta). |
251260

252261
#### Traces
253262

254-
| Option | Type | Default | Description |
255-
| :-------------------- | :--------------- | :-------------------------- | :--------------------------------------------- |
256-
| `otlp` | `OTLP Exporter` | `null` (Exporting disabled) | Configuration for exporting traces via OTLP. |
257-
| `sampler` | `SamplerOption` | `ALWAYS_ON` | Configuration to control sampling of traces. |
258-
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from traces. |
263+
| Option | Type | Default | Description |
264+
| :-------------------- | :--------------------- | :-------------------------- | :--------------------------------------------- |
265+
| `otlp` | `OTLP Trace Exporter` | `null` (Exporting disabled) | Configuration for exporting traces via OTLP. |
266+
| `sampler` | `SamplerOption` | `ALWAYS_ON` | Configuration to control sampling of traces. |
267+
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from traces. |
259268

260-
#### OTLP Exporter
269+
#### OTLP Trace Exporter
261270

262271
| Option | Type | Default | Description |
263272
| :--------- | :-------- | :-------------------------- | :--------------------------------------------------------------- |

0 commit comments

Comments
 (0)