feat: harden community production foundation through story 1.5
This commit is contained in:
@@ -9,7 +9,7 @@ use axum::{
|
||||
};
|
||||
use opentelemetry::{
|
||||
global,
|
||||
trace::{TraceId, TracerProvider as _},
|
||||
trace::{SpanId, TraceId, TracerProvider as _},
|
||||
};
|
||||
use opentelemetry_sdk::{
|
||||
error::OTelSdkResult,
|
||||
@@ -61,6 +61,7 @@ async fn covers_valid_invalid_and_absent_traceparent_on_mcp_boundary() {
|
||||
|
||||
assert_eq!(valid.status, StatusCode::OK);
|
||||
assert_eq!(valid.request_id.as_deref(), Some("request-id-is-separate"));
|
||||
assert_eq!(valid.trace_id.as_deref(), Some(REMOTE_TRACE_ID));
|
||||
assert_eq!(invalid.status, StatusCode::OK);
|
||||
assert_eq!(absent.status, StatusCode::OK);
|
||||
assert!(valid.traceparent_response.is_none());
|
||||
@@ -80,6 +81,41 @@ async fn covers_valid_invalid_and_absent_traceparent_on_mcp_boundary() {
|
||||
assert_ne!(trace_ids[2], trace_ids[0]);
|
||||
assert_ne!(trace_ids[1], trace_ids[2]);
|
||||
assert!(!trace_ids.contains(&TraceId::INVALID));
|
||||
let request_spans = exported
|
||||
.lock()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|span| span.name.as_ref() == "mcp.request")
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(
|
||||
request_spans[0].parent_span_id.to_string(),
|
||||
"b7ad6b7169203331"
|
||||
);
|
||||
assert_eq!(request_spans[1].parent_span_id, SpanId::INVALID);
|
||||
assert_eq!(request_spans[2].parent_span_id, SpanId::INVALID);
|
||||
provider.shutdown().unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "current_thread")]
|
||||
async fn sampling_off_still_returns_a_local_trace_identity() {
|
||||
let _tracing_test_guard = TRACING_TEST_LOCK.lock().await;
|
||||
global::set_text_map_propagator(TraceContextPropagator::new());
|
||||
let provider = SdkTracerProvider::builder()
|
||||
.with_sampler(opentelemetry_sdk::trace::Sampler::AlwaysOff)
|
||||
.build();
|
||||
let tracer = provider.tracer("mcp-request-context-sampling-off-test");
|
||||
let subscriber =
|
||||
tracing_subscriber::registry().with(tracing_opentelemetry::layer().with_tracer(tracer));
|
||||
let app = build_test_app(test_registry().await, Duration::ZERO, None);
|
||||
|
||||
let response = send_health(app, None, None)
|
||||
.with_subscriber(subscriber)
|
||||
.await;
|
||||
|
||||
let trace_id = response.trace_id.expect("local trace id");
|
||||
assert_eq!(trace_id.len(), 32);
|
||||
assert_ne!(trace_id, "00000000000000000000000000000000");
|
||||
provider.shutdown().unwrap();
|
||||
}
|
||||
|
||||
@@ -98,6 +134,14 @@ async fn replaces_multiple_request_id_headers_with_one_uuid_v7() {
|
||||
"x-request-id",
|
||||
HeaderValue::from_static("second-request-id"),
|
||||
);
|
||||
request.headers_mut().append(
|
||||
"traceparent",
|
||||
HeaderValue::from_static("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"),
|
||||
);
|
||||
request.headers_mut().append(
|
||||
"traceparent",
|
||||
HeaderValue::from_static("00-1af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"),
|
||||
);
|
||||
|
||||
let response = app
|
||||
.oneshot(request)
|
||||
@@ -112,6 +156,9 @@ async fn replaces_multiple_request_id_headers_with_one_uuid_v7() {
|
||||
uuid::Uuid::parse_str(generated).unwrap().get_version(),
|
||||
Some(uuid::Version::SortRand)
|
||||
);
|
||||
let trace_id = response.headers()["x-trace-id"].to_str().unwrap();
|
||||
assert_ne!(trace_id, "0af7651916cd43dd8448eb211c80319c");
|
||||
assert_ne!(trace_id, "1af7651916cd43dd8448eb211c80319c");
|
||||
}
|
||||
|
||||
async fn send_health(
|
||||
@@ -143,6 +190,11 @@ async fn send_health(
|
||||
.get("traceparent")
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::to_owned),
|
||||
trace_id: response
|
||||
.headers()
|
||||
.get("x-trace-id")
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::to_owned),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +202,7 @@ struct ProbeResponse {
|
||||
status: StatusCode,
|
||||
request_id: Option<String>,
|
||||
traceparent_response: Option<String>,
|
||||
trace_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user