Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changesets/feat_metric_temporality.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### feat: Add configuration option for metric temporality - @swcollard PR #413

Creates a new configuration option for telemetry to set the Metric temporality to either Cumulative (default) or Delta.

* Cumulative - The metric value will be the overall value since the start of the measurement.
* Delta - The metric will be the difference in the measurement since the last time it was reported.

Some observability vendors require that one is used over the other so we want to support the configuration in the MCP Server.
27 changes: 26 additions & 1 deletion crates/apollo-mcp-server/src/runtime/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::runtime::telemetry::sampler::SamplerOption;
use apollo_mcp_server::generated::telemetry::TelemetryAttribute;
use opentelemetry::{Key, KeyValue, global, trace::TracerProvider as _};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::metrics::{Instrument, Stream};
use opentelemetry_sdk::metrics::{Instrument, Stream, Temporality};
use opentelemetry_sdk::{
Resource,
metrics::{MeterProviderBuilder, PeriodicReader, SdkMeterProvider},
Expand Down Expand Up @@ -44,17 +44,38 @@ pub struct MetricsExporters {
omitted_attributes: Option<HashSet<TelemetryAttribute>>,
}

#[derive(Debug, Deserialize, JsonSchema)]
pub enum MetricTemporality {
Cumulative,
Delta,
}

impl OTLPMetricExporter {
pub fn to_temporality(&self) -> Temporality {
match self
.temporality
.as_ref()
.unwrap_or(&MetricTemporality::Cumulative)
{
MetricTemporality::Cumulative => Temporality::Cumulative,
MetricTemporality::Delta => Temporality::Delta,
}
}
}

#[derive(Debug, Deserialize, JsonSchema)]
pub struct OTLPMetricExporter {
endpoint: String,
protocol: String,
temporality: Option<MetricTemporality>,
}

impl Default for OTLPMetricExporter {
fn default() -> Self {
Self {
endpoint: "http://localhost:4317".into(),
protocol: "grpc".into(),
temporality: Some(MetricTemporality::Cumulative),
}
}
}
Expand Down Expand Up @@ -122,10 +143,12 @@ fn init_meter_provider(telemetry: &Telemetry) -> Result<SdkMeterProvider, anyhow
"grpc" => opentelemetry_otlp::MetricExporter::builder()
.with_tonic()
.with_endpoint(otlp.endpoint.clone())
.with_temporality(otlp.to_temporality())
.build()?,
"http/protobuf" => opentelemetry_otlp::MetricExporter::builder()
.with_http()
.with_endpoint(otlp.endpoint.clone())
.with_temporality(otlp.to_temporality())
.build()?,
other => {
return Err(anyhow::anyhow!(
Expand Down Expand Up @@ -331,6 +354,7 @@ mod tests {
otlp: Some(OTLPMetricExporter {
protocol: "bogus".to_string(),
endpoint: "http://localhost:4317".to_string(),
temporality: None,
}),
omitted_attributes: None,
}),
Expand All @@ -354,6 +378,7 @@ mod tests {
otlp: Some(OTLPMetricExporter {
protocol: "http/protobuf".to_string(),
endpoint: "http://localhost:4318/v1/metrics".to_string(),
temporality: Some(MetricTemporality::Delta),
}),
omitted_attributes: None,
}),
Expand Down
29 changes: 19 additions & 10 deletions docs/source/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,29 @@

#### Metrics

| Option | Type | Default | Description |
| :-------------------- | :--------------- | :-------------------------- | :--------------------------------------------- |
| `otlp` | `OTLP Exporter` | `null` (Exporting disabled) | Configuration for exporting metrics via OTLP. |
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from metrics. |
| Option | Type | Default | Description |
| :-------------------- | :---------------------- | :-------------------------- | :--------------------------------------------- |
| `otlp` | `OTLP Metric Exporter` | `null` (Exporting disabled) | Configuration for exporting metrics via OTLP. |
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from metrics. |

Check notice on line 250 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L250

Descriptions that are fragments should not have ending punctuation. ```suggestion | <code>omitted_attributes</code> | <code>List<String></code> | | List of attributes to be omitted from metrics | ```


#### OTLP Metrics Exporter

Check warning on line 253 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L253

Headings must use sentence case. ```suggestion #### OTLP metrics exporter ```

| Option | Type | Default | Description |
| :--------- | :--------------------------------------- | :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `endpoint` | `URL` | `http://localhost:4317` | URL to export data to. Requires full path. |

Check warning on line 257 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L257

The original description contains a grammatically incorrect fragment. The suggested change rephrases this for clarity and grammatical correctness. ```suggestion | <code>endpoint</code> | <code>URL</code> | <code>http://localhost:4317</code> | The URL to export data to. This must be a full path. | ```
| `protocol` | `string` | `grpc` | Protocol for export. Only `grpc` and `http/protobuf` are supported. |

Check notice on line 258 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L258

The original description begins with a fragment. This change rephrases it as a complete sentence for grammatical correctness. ```suggestion | <code>protocol</code> | <code>string</code> | <code>grpc</code> | The protocol for the export. Only <code>grpc</code> and <code>http/protobuf</code> are supported. | ```
| `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). |

Check warning on line 259 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L259

The original description is long and complex. The suggested change simplifies the language and improves readability. ```suggestion | <code>temporality</code> | <code>MetricTemporality</code> | <code>Cumulative</code> | Defines how additive quantities are expressed. <code>Cumulative</code> values include previous measurements, and <code>Delta</code> values do not. | ```

#### Traces

| Option | Type | Default | Description |
| :-------------------- | :--------------- | :-------------------------- | :--------------------------------------------- |
| `otlp` | `OTLP Exporter` | `null` (Exporting disabled) | Configuration for exporting traces via OTLP. |
| `sampler` | `SamplerOption` | `ALWAYS_ON` | Configuration to control sampling of traces. |
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from traces. |
| Option | Type | Default | Description |
| :-------------------- | :--------------------- | :-------------------------- | :--------------------------------------------- |
| `otlp` | `OTLP Trace Exporter` | `null` (Exporting disabled) | Configuration for exporting traces via OTLP. |
| `sampler` | `SamplerOption` | `ALWAYS_ON` | Configuration to control sampling of traces. |
| `omitted_attributes` | `List<String>` | | List of attributes to be omitted from traces. |

Check notice on line 267 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L267

Descriptions that are fragments should not have ending punctuation. ```suggestion | <code>omitted_attributes</code> | <code>List<String></code> | | List of attributes to be omitted from traces | ```

#### OTLP Exporter
#### OTLP Trace Exporter

Check warning on line 269 in docs/source/config-file.mdx

View check run for this annotation

Apollo Librarian / AI Style Review

docs/source/config-file.mdx#L269

Headings must use sentence case. ```suggestion #### OTLP trace exporter ```

| Option | Type | Default | Description |
| :--------- | :-------- | :-------------------------- | :--------------------------------------------------------------- |
Expand Down