CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.
Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
resources/list admission fix for bound template publications.
Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
`just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
a real MCP Inspector 2.12.0 client smoke.
Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
runs only on main), story events run the changed packages, the full workspace suite
stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
release entry of the tag instead of dying with the runner workspace.
Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.
Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
150 lines
5.4 KiB
Rust
150 lines
5.4 KiB
Rust
use axum::{
|
|
extract::{MatchedPath, Request},
|
|
http::{HeaderName, HeaderValue},
|
|
middleware::Next,
|
|
response::Response,
|
|
};
|
|
use crank_core::{CorrelationContext, RequestId, TraceContext};
|
|
use crank_metrics::ExemplarTraceId;
|
|
use crank_observability::with_request_correlation;
|
|
use tracing::{Instrument, info, info_span};
|
|
|
|
pub const REQUEST_ID_HEADER: HeaderName = HeaderName::from_static("x-request-id");
|
|
pub const TRACE_ID_HEADER: HeaderName = HeaderName::from_static("x-trace-id");
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct RequestContext {
|
|
pub correlation: CorrelationContext,
|
|
}
|
|
|
|
impl RequestContext {
|
|
pub fn request_id(&self) -> &str {
|
|
self.correlation.request_id().as_str()
|
|
}
|
|
|
|
pub fn trace_id(&self) -> &str {
|
|
self.correlation.trace_id().as_str()
|
|
}
|
|
}
|
|
|
|
pub async fn apply_request_context(mut request: Request, next: Next) -> Response {
|
|
let (request_id, remote_parent) = resolve_correlation(request.headers());
|
|
let method = request.method().clone();
|
|
let route = request
|
|
.extensions()
|
|
.get::<MatchedPath>()
|
|
.map_or("unmatched", MatchedPath::as_str)
|
|
.to_owned();
|
|
// Explicit root: a contextual span would inherit whatever OTel context happens to be
|
|
// current on this worker thread, and a telemetry-suppressed ambient context makes the
|
|
// span non-recording, so the request trace is silently dropped before the exporter.
|
|
// The inbound `traceparent` parent is installed right below on the span builder.
|
|
let span = info_span!(
|
|
target: "crank::trace",
|
|
parent: None,
|
|
"http.request",
|
|
request_id = %request_id,
|
|
trace_id = tracing::field::Empty,
|
|
);
|
|
if let Some(remote_parent) = remote_parent.as_ref() {
|
|
set_canonical_parent(&span, remote_parent);
|
|
}
|
|
let trace_context = crank_trace::trace_context_for_span(&span).unwrap_or_else(|| {
|
|
remote_parent
|
|
.as_ref()
|
|
.map_or_else(TraceContext::generate, TraceContext::continue_local)
|
|
});
|
|
span.record("trace_id", trace_context.trace_id().as_str());
|
|
let context = RequestContext {
|
|
correlation: CorrelationContext::new(request_id, trace_context),
|
|
};
|
|
request.extensions_mut().insert(context.clone());
|
|
|
|
with_request_correlation(
|
|
context.correlation.request_id().to_string(),
|
|
context.correlation.trace_id().to_string(),
|
|
async move {
|
|
let mut response = next.run(request).instrument(span).await;
|
|
info!(
|
|
name: "admin.request.completed",
|
|
request_id = %context.correlation.request_id(),
|
|
trace_id = %context.correlation.trace_id(),
|
|
method = %method,
|
|
route,
|
|
status = response.status().as_u16(),
|
|
"admin request completed"
|
|
);
|
|
if let Ok(value) = HeaderValue::from_str(context.correlation.request_id().as_str()) {
|
|
response.headers_mut().insert(REQUEST_ID_HEADER, value);
|
|
}
|
|
if let Ok(value) = HeaderValue::from_str(context.correlation.trace_id().as_str()) {
|
|
response.headers_mut().insert(TRACE_ID_HEADER, value);
|
|
}
|
|
if context.correlation.trace_context().is_sampled()
|
|
&& let Some(exemplar) =
|
|
ExemplarTraceId::parse(context.correlation.trace_id().as_str())
|
|
{
|
|
response.extensions_mut().insert(exemplar);
|
|
}
|
|
response
|
|
},
|
|
)
|
|
.await
|
|
}
|
|
|
|
fn resolve_correlation(headers: &axum::http::HeaderMap) -> (RequestId, Option<TraceContext>) {
|
|
let _tracestate_accepted = one_auxiliary_header_within_budget(
|
|
headers,
|
|
"tracestate",
|
|
TraceContext::tracestate_within_budget,
|
|
);
|
|
let _baggage_accepted =
|
|
one_auxiliary_header_within_budget(headers, "baggage", TraceContext::baggage_within_budget);
|
|
let mut request_ids = headers.get_all(REQUEST_ID_HEADER).iter();
|
|
let request_id = request_ids.next().and_then(|value| value.to_str().ok());
|
|
let request_id = if request_ids.next().is_some() {
|
|
RequestId::generate()
|
|
} else {
|
|
RequestId::resolve(request_id)
|
|
};
|
|
|
|
let mut traceparents = headers.get_all("traceparent").iter();
|
|
let traceparent = traceparents.next().and_then(|value| value.to_str().ok());
|
|
let remote_parent = if traceparents.next().is_some() {
|
|
None
|
|
} else {
|
|
traceparent.and_then(|value| TraceContext::parse(value).ok())
|
|
};
|
|
(request_id, remote_parent)
|
|
}
|
|
|
|
fn one_auxiliary_header_within_budget(
|
|
headers: &axum::http::HeaderMap,
|
|
name: &'static str,
|
|
validate: fn(&str) -> bool,
|
|
) -> bool {
|
|
let mut values = headers.get_all(name).iter();
|
|
let value = values.next().and_then(|value| value.to_str().ok());
|
|
values.next().is_none() && value.is_some_and(validate)
|
|
}
|
|
|
|
fn set_canonical_parent(span: &tracing::Span, context: &TraceContext) {
|
|
crank_trace::set_parent_from_trace_context(span, context);
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
#[test]
|
|
fn accepts_visible_ascii_request_ids() {
|
|
assert!(crank_core::RequestId::is_valid("req_test_123"));
|
|
assert!(crank_core::RequestId::is_valid("trace-123/abc"));
|
|
}
|
|
|
|
#[test]
|
|
fn rejects_empty_or_control_request_ids() {
|
|
assert!(!crank_core::RequestId::is_valid(""));
|
|
assert!(!crank_core::RequestId::is_valid("bad value"));
|
|
assert!(!crank_core::RequestId::is_valid("bad\nvalue"));
|
|
}
|
|
}
|