Skip to content

Commit 65b6ba9

Browse files
committed
feat: Add mcp-session-id header to HTTP request trace attributes
1 parent a33d5c0 commit 65b6ba9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### feat: Add mcp-session-id header to HTTP request trace attributes - @swcollard PR #421
2+
3+
Includes the value of the [Mcp-Session-Id](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#session-management) HTTP header as an attribute of the trace for HTTP requests to the MCP Server

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,25 @@ impl Starting {
222222
"mcp_server",
223223
method = %request.method(),
224224
uri = %request.uri(),
225+
session_id = tracing::field::Empty,
225226
status_code = tracing::field::Empty,
226227
)
227228
})
228229
.on_response(
229230
|response: &axum::http::Response<_>,
230231
_latency: std::time::Duration,
231232
span: &tracing::Span| {
232-
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+
}
233244
},
234245
),
235246
);

0 commit comments

Comments
 (0)