Skip to content

Commit 28f36d8

Browse files
swcollardDaleSeo
authored andcommitted
Trace operation parsing and tool generation
Add status code to the http trace
1 parent 8681f20 commit 28f36d8

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

crates/apollo-mcp-registry/src/platform_api/operation_collections/collection_poller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl From<&OperationCollectionDefaultEntry> for OperationData {
248248
}
249249
}
250250

251-
#[derive(Clone)]
251+
#[derive(Clone, Debug)]
252252
pub enum CollectionSource {
253253
Id(String, PlatformApiConfig),
254254
Default(String, PlatformApiConfig),

crates/apollo-mcp-server/src/operations/operation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl Operation {
4848
self.inner
4949
}
5050

51+
#[tracing::instrument(skip(graphql_schema, custom_scalar_map))]
5152
pub fn from_document(
5253
raw_operation: RawOperation,
5354
graphql_schema: &GraphqlSchema,
@@ -138,6 +139,7 @@ impl Operation {
138139
}
139140

140141
/// Generate a description for an operation based on documentation in the schema
142+
#[tracing::instrument(skip(comments, tree_shaker, graphql_schema))]
141143
fn tool_description(
142144
comments: Option<String>,
143145
tree_shaker: &mut SchemaTreeShaker,
@@ -335,6 +337,7 @@ impl graphql::Executable for Operation {
335337
}
336338

337339
#[allow(clippy::type_complexity)]
340+
#[tracing::instrument(skip_all)]
338341
pub fn operation_defs(
339342
source_text: &str,
340343
allow_mutations: bool,
@@ -424,6 +427,7 @@ pub fn operation_name(
424427
.to_string())
425428
}
426429

430+
#[tracing::instrument(skip(source_text))]
427431
pub fn variable_description_overrides(
428432
source_text: &str,
429433
operation_definition: &Node<OperationDefinition>,
@@ -455,6 +459,7 @@ pub fn variable_description_overrides(
455459
argument_overrides_map
456460
}
457461

462+
#[tracing::instrument(skip(source_text))]
458463
pub fn find_opening_parens_offset(
459464
source_text: &str,
460465
operation_definition: &Node<OperationDefinition>,
@@ -512,6 +517,7 @@ fn tool_character_length(tool: &Tool) -> Result<usize, serde_json::Error> {
512517
+ tool_schema_string.len())
513518
}
514519

520+
#[tracing::instrument(skip_all)]
515521
fn get_json_schema(
516522
operation: &Node<OperationDefinition>,
517523
schema_argument_descriptions: &HashMap<String, Vec<String>>,

crates/apollo-mcp-server/src/operations/operation_source.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::RawOperation;
2222
const OPERATION_DOCUMENT_EXTENSION: &str = "graphql";
2323

2424
/// The source of the operations exposed as MCP tools
25-
#[derive(Clone)]
25+
#[derive(Clone, Debug)]
2626
pub enum OperationSource {
2727
/// GraphQL document files
2828
Files(Vec<PathBuf>),
@@ -38,6 +38,7 @@ pub enum OperationSource {
3838
}
3939

4040
impl OperationSource {
41+
#[tracing::instrument]
4142
pub async fn into_stream(self) -> impl Stream<Item = Event> {
4243
match self {
4344
OperationSource::Files(paths) => Self::stream_file_changes(paths).boxed(),
@@ -73,6 +74,7 @@ impl OperationSource {
7374
}
7475
}
7576

77+
#[tracing::instrument]
7678
fn stream_file_changes(paths: Vec<PathBuf>) -> impl Stream<Item = Event> {
7779
let path_count = paths.len();
7880
let state = Arc::new(Mutex::new(HashMap::<PathBuf, Vec<RawOperation>>::new()));

crates/apollo-mcp-server/src/server/states/starting.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,27 @@ impl Starting {
215215
//start OpenTelemetry trace on incoming request
216216
.layer(OtelAxumLayer::default())
217217
// Add tower-http tracing layer for additional HTTP-level tracing
218-
.layer(TraceLayer::new_for_http().make_span_with(
219-
|request: &axum::http::Request<_>| {
220-
tracing::info_span!(
221-
"http_request",
222-
method = %request.method(),
223-
uri = %request.uri(),
224-
)
225-
},
226-
));
218+
.layer(
219+
TraceLayer::new_for_http()
220+
.make_span_with(|request: &axum::http::Request<_>| {
221+
tracing::info_span!(
222+
"mcp_server",
223+
method = %request.method(),
224+
uri = %request.uri(),
225+
status_code = tracing::field::Empty,
226+
)
227+
})
228+
.on_response(
229+
|response: &axum::http::Response<_>,
230+
_latency: std::time::Duration,
231+
span: &tracing::Span| {
232+
span.record(
233+
"status_code",
234+
tracing::field::display(response.status()),
235+
);
236+
},
237+
),
238+
);
227239

228240
// Add health check endpoint if configured
229241
if let Some(health_check) = health_check.filter(|h| h.config().enabled) {

0 commit comments

Comments
 (0)