From 667a1efb040518521743c7611b29b13ed0c98817 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Thu, 12 Oct 2023 14:28:29 +1100 Subject: [PATCH] Add trace ID to log lines emitted during rule evaluation Signed-off-by: Charles Korn --- rules/group.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rules/group.go b/rules/group.go index 0365b699c..857e06954 100644 --- a/rules/group.go +++ b/rules/group.go @@ -442,6 +442,10 @@ func (g *Group) Eval(ctx context.Context, ts time.Time) { rule.SetEvaluationTimestamp(t) }(time.Now()) + if sp.SpanContext().IsSampled() && sp.SpanContext().HasTraceID() { + logger = log.WithPrefix(g.logger, "traceID", sp.SpanContext().TraceID()) + } + g.metrics.EvalTotal.WithLabelValues(GroupKey(g.File(), g.Name())).Inc() vector, err := rule.Eval(ctx, ts, g.opts.QueryFunc, g.opts.ExternalURL, g.Limit())