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
3 changes: 3 additions & 0 deletions .changesets/feat_trace_session_id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### feat: Add mcp-session-id header to HTTP request trace attributes - @swcollard PR #421

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
13 changes: 12 additions & 1 deletion crates/apollo-mcp-server/src/server/states/starting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,25 @@ impl Starting {
"mcp_server",
method = %request.method(),
uri = %request.uri(),
session_id = tracing::field::Empty,
status_code = tracing::field::Empty,
)
})
.on_response(
|response: &axum::http::Response<_>,
_latency: std::time::Duration,
span: &tracing::Span| {
span.record("status", tracing::field::display(response.status()));
span.record(
"status_code",
tracing::field::display(response.status()),
);
if let Some(session_id) = response
.headers()
.get("mcp-session-id")
.and_then(|v| v.to_str().ok())
{
span.record("session_id", tracing::field::display(session_id));
}
Comment on lines +237 to +243
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made it! 😄

},
),
);
Expand Down