Skip to content

Commit 73e404c

Browse files
committed
Conditionally set session id, fix mismatch of status_code attribute
1 parent 24e5cea commit 73e404c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,25 @@ impl Starting {
222222
"mcp_server",
223223
method = %request.method(),
224224
uri = %request.uri(),
225-
session_id = %request.headers().get("mcp-session-id").and_then(|v| v.to_str().ok()).unwrap_or(""),
225+
session_id = tracing::field::Empty,
226226
status_code = tracing::field::Empty,
227227
)
228228
})
229229
.on_response(
230230
|response: &axum::http::Response<_>,
231231
_latency: std::time::Duration,
232232
span: &tracing::Span| {
233-
span.record("status", tracing::field::display(response.status()));
233+
span.record(
234+
"status_code",
235+
tracing::field::display(response.status()),
236+
);
237+
if let Some(session_id) = response
238+
.headers()
239+
.get("mcp-session-id")
240+
.and_then(|v| v.to_str().ok())
241+
{
242+
span.record("session_id", tracing::field::display(session_id));
243+
}
234244
},
235245
),
236246
);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ impl TelemetryAttribute {
3232
TelemetryAttribute::SessionId => {
3333
Key::from_static_str(TelemetryAttribute::SessionId.as_str())
3434
}
35+
TelemetryAttribute::StatusCode => {
36+
Key::from_static_str(TelemetryAttribute::StatusCode.as_str())
37+
}
3538
}
3639
}
3740

crates/apollo-mcp-server/telemetry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ raw_operation = "Graphql operation text and metadata used for Tool generation"
88
client_name = "The client name that initializes with the MCP Server"
99
client_version = "The client version that initializes with the MCP Server"
1010
session_id = "The value of the Mcp-Session-Id header in the HTTP request"
11+
status_code = "The HTTP status code returned by requests using the Streamable HTTP Transport"
1112

1213
[metrics.apollo.mcp]
1314
"initialize.count" = "Number of times initialize has been called"

0 commit comments

Comments
 (0)