Skip to content

Commit 7ec1208

Browse files
swcollardDaleSeo
authored andcommitted
Add basic config file options to otel telemetry (#330)
* Add basic config file options to otel telemetry * Happy path unit test for telemetry config * Changeset * Taplo format * Refactor to add a couple more tests * Update unit test for clippy after rust upgrade * Rename unit tests
1 parent bcd7172 commit 7ec1208

File tree

9 files changed

+382
-139
lines changed

9 files changed

+382
-139
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Add basic config file options to otel telemetry - @swcollard PR #330
2+
3+
Adds new Configuration options for setting up configuration beyond the standard OTEL environment variables needed before.
4+
5+
* Renames trace->telemetry
6+
* Adds OTLP options for metrics and tracing to choose grpc or http upload protocols and setting the endpoints
7+
* This configuration is all optional, so by default nothing will be logged

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo-mcp-server/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ jwks = "0.4.0"
3232
lz-str = "0.2.1"
3333
opentelemetry = "0.30.0"
3434
opentelemetry-appender-log = "0.30.0"
35-
opentelemetry-otlp = "0.30.0"
35+
opentelemetry-otlp = { version = "0.30.0", features = [
36+
"grpc-tonic",
37+
"tonic",
38+
"http-proto",
39+
"metrics",
40+
"trace",
41+
] }
3642
opentelemetry-resource-detectors = "0.9.0"
3743
opentelemetry-semantic-conventions = "0.30.0"
3844
opentelemetry-stdout = "0.30.0"

crates/apollo-mcp-server/src/graphql.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -449,27 +449,27 @@ mod test {
449449
.find(|scope_metrics| scope_metrics.scope().name() == "apollo.mcp")
450450
{
451451
for metric in scope_metrics.metrics() {
452-
if metric.name() == "apollo.mcp.operation.count" {
453-
if let AggregatedMetrics::U64(MetricData::Sum(data)) = metric.data() {
454-
for point in data.data_points() {
455-
let attributes = point.attributes();
456-
let mut attr_map = std::collections::HashMap::new();
457-
for kv in attributes {
458-
attr_map.insert(kv.key.as_str(), kv.value.as_str());
459-
}
460-
assert_eq!(
461-
attr_map.get("operation.id").map(|s| s.as_ref()),
462-
Some("mock_operation")
463-
);
464-
assert_eq!(
465-
attr_map.get("operation.type").map(|s| s.as_ref()),
466-
Some("persisted_query")
467-
);
468-
assert_eq!(
469-
attr_map.get("success"),
470-
Some(&std::borrow::Cow::Borrowed("false"))
471-
);
452+
if metric.name() == "apollo.mcp.operation.count"
453+
&& let AggregatedMetrics::U64(MetricData::Sum(data)) = metric.data()
454+
{
455+
for point in data.data_points() {
456+
let attributes = point.attributes();
457+
let mut attr_map = std::collections::HashMap::new();
458+
for kv in attributes {
459+
attr_map.insert(kv.key.as_str(), kv.value.as_str());
472460
}
461+
assert_eq!(
462+
attr_map.get("operation.id").map(|s| s.as_ref()),
463+
Some("mock_operation")
464+
);
465+
assert_eq!(
466+
attr_map.get("operation.type").map(|s| s.as_ref()),
467+
Some("persisted_query")
468+
);
469+
assert_eq!(
470+
attr_map.get("success"),
471+
Some(&std::borrow::Cow::Borrowed("false"))
472+
);
473473
}
474474
}
475475
}

crates/apollo-mcp-server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn main() -> anyhow::Result<()> {
4141
None => runtime::read_config_from_env().unwrap_or_default(),
4242
};
4343

44-
let _guard = runtime::trace::init_tracing_subscriber(&config)?;
44+
let _guard = runtime::telemetry::init_tracing_subscriber(&config)?;
4545

4646
info!(
4747
"Apollo MCP Server v{} // (c) Apollo Graph, Inc. // Licensed under MIT",

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod operation_source;
1212
mod overrides;
1313
mod schema_source;
1414
mod schemas;
15-
pub mod trace;
15+
pub mod telemetry;
1616

1717
use std::path::Path;
1818

@@ -270,6 +270,11 @@ mod test {
270270
path: None,
271271
rotation: Hourly,
272272
},
273+
telemetry: Telemetry {
274+
exporters: None,
275+
service_name: None,
276+
version: None,
277+
},
273278
operations: Infer,
274279
overrides: Overrides {
275280
disable_type_description: false,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use url::Url;
88

99
use super::{
1010
OperationSource, SchemaSource, endpoint::Endpoint, graphos::GraphOSConfig,
11-
introspection::Introspection, logging::Logging, overrides::Overrides,
11+
introspection::Introspection, logging::Logging, overrides::Overrides, telemetry::Telemetry,
1212
};
1313

1414
/// Configuration for the MCP server
@@ -43,6 +43,9 @@ pub struct Config {
4343
/// Logging configuration
4444
pub logging: Logging,
4545

46+
/// Telemetry configuration
47+
pub telemetry: Telemetry,
48+
4649
/// Operations
4750
pub operations: OperationSource,
4851

0 commit comments

Comments
 (0)