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
8 changes: 6 additions & 2 deletions server/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ pub async fn list_traces(
count(*) FILTER (WHERE status_code = 2) AS error_count
FROM spans
WHERE ($1::text IS NULL OR service = $1)
AND ($2::timestamptz IS NULL OR start_time >= $2)
-- default to a recent window when unbounded so this can't turn into a
-- full-table GROUP BY (which times out); the UI always passes a range.
AND start_time >= COALESCE($2::timestamptz, now() - interval '24 hours')
AND ($3::timestamptz IS NULL OR start_time <= $3)
AND ($6::jsonb IS NULL
OR trace_id IN (SELECT trace_id FROM spans WHERE attributes @> $6))
Expand Down Expand Up @@ -866,7 +868,9 @@ pub async fn service_red(
percentile_cont(0.99) WITHIN GROUP (ORDER BY duration_ms) AS p99_ms
FROM spans
WHERE service IS NOT NULL
AND ($1::timestamptz IS NULL OR start_time >= $1)
-- default to a recent window when unbounded so the per-service
-- percentile aggregate can't full-scan the spans table and time out.
AND start_time >= COALESCE($1::timestamptz, now() - interval '24 hours')
AND ($2::timestamptz IS NULL OR start_time <= $2)
GROUP BY service
ORDER BY spans DESC",
Expand Down
9 changes: 9 additions & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ fn otel_request_span(req: &Request<Body>) -> tracing::Span {
let parent = opentelemetry::global::get_text_map_propagator(|p| {
p.extract(&HeaderExtractor(req.headers()))
});
// TEMP DEBUG (remove after diagnosing the missing traefik→watcher edge):
// log whether an upstream traceparent actually reached the app, to tell apart
// "traefik isn't injecting it" from "the linkerd sidecar strips it".
tracing::info!(
target: "tp_debug",
path = %req.uri().path(),
traceparent_present = req.headers().contains_key("traceparent"),
"incoming request trace-context"
);
span.set_parent(parent);
span
}
Expand Down
12 changes: 8 additions & 4 deletions server/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async fn ingest_and_query_a_trace() {
};
let router = app(pool);

let start = nanos_ago(5);
let req = ExportTraceServiceRequest {
resource_spans: vec![ResourceSpans {
resource: Some(Resource {
Expand All @@ -261,8 +262,9 @@ async fn ingest_and_query_a_trace() {
trace_id: vec![1u8; 16],
span_id: vec![2u8; 8],
name: "GET /checkout".to_string(),
start_time_unix_nano: 1_000_000_000,
end_time_unix_nano: 1_050_000_000,
// recent (within the list's default window), +50ms duration
start_time_unix_nano: start,
end_time_unix_nano: start + 50_000_000,
..Default::default()
}],
..Default::default()
Expand Down Expand Up @@ -1668,9 +1670,11 @@ async fn time_window_filters_traces_and_logs() {
let (_, logs) = get_json(&router, &format!("/api/logs?from={from}")).await;
assert_eq!(logs.as_array().unwrap().len(), 1, "only the recent log");

// No window → both.
// No window → defaults to the recent (24h) window, so the 3-day-old trace is
// excluded and only the recent one comes back.
let (_, all) = get_json(&router, "/api/traces").await;
assert_eq!(all.as_array().unwrap().len(), 2);
assert_eq!(all.as_array().unwrap().len(), 1);
assert_eq!(all[0]["trace_id"], "recent");
}

#[tokio::test]
Expand Down