test(relay): capture access logs with the production JSON formatter

The capture helpers built a generic flattened JSON layer, which could drift
from the TraceContextJson formatter main.rs installs.

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
Duncan
2026-10-26 21:05:26 -04:00
committed by Will Pfleger
parent f97e9c367c
commit 0ea5c9d8c4
2 changed files with 5 additions and 4 deletions

View File

@@ -1331,7 +1331,7 @@ pub(crate) mod tests {
tracing_subscriber::registry().with(
tracing_subscriber::fmt::layer()
.json()
.flatten_event(true)
.event_format(crate::telemetry::TraceContextLookup::default().json_formatter(false))
.with_writer(move || writer.clone()),
)
}
@@ -1346,7 +1346,7 @@ pub(crate) mod tests {
(r, out)
}
/// Run `f` with JSON logs (flattened, as in production) captured.
/// Run `f` with JSON logs captured, using production's JSON formatter.
pub(crate) fn capture<R>(f: impl FnOnce() -> R) -> (R, Captured) {
let _lock = crate::test_support::tracing_dispatch_lock();
let out = Captured::default();

View File

@@ -2697,7 +2697,7 @@ pub(crate) mod tests {
}
}
/// Each parsed REQ and COUNT frame advances its read counter by exactly
/// Each parsed REQ, sync and COUNT frame advances its read counter by exactly
/// one, even when refused; other frames count nothing.
#[tokio::test(flavor = "current_thread")]
async fn dispatcher_counts_each_req_and_count_frame_once() {
@@ -2714,13 +2714,14 @@ pub(crate) mod tests {
for raw in [
serde_json::json!(["REQ", "r", {"kinds": [1]}]),
serde_json::json!(["COUNT", "c", {"kinds": [1]}]),
serde_json::json!(["REQ", "y", {"artifact": "current", "#h": [uuid::Uuid::new_v4().to_string()]}]),
serde_json::json!(["CLOSE", "r"]),
] {
handle_text_message(raw.to_string(), Arc::clone(&conn), Arc::clone(&state)).await;
}
let scrape = handle.render();
for kind in ["req", "count"] {
for kind in ["req", "count", "sync"] {
assert!(
scrape.contains(&format!("buzz_ws_reads_total{{type=\"{kind}\"}} 1\n")),
"{scrape}"