Tests for the log's fields and the metrics Grafana reads (#403)
Three tests for what the dashboard and the alert rules read and nothing checked: every ipx_ metric named in grafana/dashboard.py and alerts.py (read out of them at compile time) is served by render, with the ones written only once known (counts, the last scan, a job under way) set first; ipx's JSON log lines for a scan's events carry ev, feed, new, bytes, msg and error.type, and inside a span trace_id and span_id; the directory's snapshot line carries instance, accepted and the refused_ counts. The JSON layer was built the same way in both services' setup; it is otel::json_layer now, so the tests run the layer production does. The log tests set the global subscriber, as production does: under a scoped one WithTrace finds no current span (#408). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,27 @@ pub fn with_ids<R>(
|
||||
/// The JSON log line with the trace and span it belongs to (#91), so a line in Loki leads to its
|
||||
/// trace in Tempo. The JSON formatter cannot take a field of its own, so the ids go on the end of
|
||||
/// the object it writes; the directory's lines carry them too (#375). A line outside any traced span, or with no trace exporter, is unchanged.
|
||||
/// One JSON object a line for Loki, each event's fields its own and the trace and span ids beside
|
||||
/// them, for ipx and the directory both: the dashboard and the alert rules read these fields.
|
||||
/// `current_span` adds the span's own fields under `span`, which ipx keeps and the directory
|
||||
/// dropped (#363).
|
||||
pub fn json_layer<S, W>(writer: W, current_span: bool) -> impl tracing_subscriber::Layer<S>
|
||||
where
|
||||
S: tracing::Subscriber + for<'a> tracing_subscriber::registry::LookupSpan<'a>,
|
||||
W: for<'w> tracing_subscriber::fmt::MakeWriter<'w> + Send + Sync + 'static,
|
||||
{
|
||||
tracing_subscriber::fmt::layer()
|
||||
.fmt_fields(tracing_subscriber::fmt::format::JsonFields::new())
|
||||
.event_format(WithTrace(
|
||||
tracing_subscriber::fmt::format()
|
||||
.json()
|
||||
.flatten_event(true)
|
||||
.with_current_span(current_span)
|
||||
.with_span_list(false),
|
||||
))
|
||||
.with_writer(writer)
|
||||
}
|
||||
|
||||
pub struct WithTrace<F>(pub F);
|
||||
|
||||
impl<S, N, F> tracing_subscriber::fmt::FormatEvent<S, N> for WithTrace<F>
|
||||
|
||||
Reference in New Issue
Block a user