systemprompt-api 0.21.1

Axum-based HTTP server and API gateway for systemprompt.io AI governance infrastructure. Exposes governed agents, MCP, A2A, and admin endpoints with rate limiting and RBAC.
Documentation
//! Trace-id propagation middleware.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

use axum::extract::Request;
use axum::middleware::Next;
use axum::response::Response;
use systemprompt_models::RequestContext;

pub async fn inject_trace_header(request: Request, next: Next) -> Response {
    let trace_id = request
        .extensions()
        .get::<RequestContext>()
        .map(|ctx| ctx.trace_id().as_str().to_owned());

    let mut response = next.run(request).await;

    if let Some(id) = trace_id
        && let Ok(header_value) = id.parse()
    {
        response.headers_mut().insert("x-trace-id", header_value);
    }

    response
}