From 9cb616a412add3f67c869bea90c5246afb191abb Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Tue, 15 Feb 2022 15:55:36 +0100 Subject: [PATCH] Add user and org labels to observed exemplars Exemplars provide information about traces, and traces usually reference to the user that served the request, however, searching the user in the trace is usually a tedious task, and it would be nice to be able to overwiew whether the slow requests (exemplars) from your panel corresponds to the same user. Signed-off-by: Oleg Zaytsev --- instrument/instrument.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/instrument/instrument.go b/instrument/instrument.go index 07aa033c..1a1352c8 100644 --- a/instrument/instrument.go +++ b/instrument/instrument.go @@ -68,9 +68,16 @@ func (c *HistogramCollector) After(ctx context.Context, method, statusCode strin // (this will always work for a HistogramVec). func ObserveWithExemplar(ctx context.Context, histogram prometheus.Observer, seconds float64) { if traceID, ok := tracing.ExtractSampledTraceID(ctx); ok { + lbls := prometheus.Labels{"traceID": traceID} + if userID, err := user.ExtractUserID(ctx); err == nil { + lbls["user"] = userID + } + if orgID, err := user.ExtractOrgID(ctx); err == nil { + lbls["organization"] = orgID + } histogram.(prometheus.ExemplarObserver).ObserveWithExemplar( seconds, - prometheus.Labels{"traceID": traceID}, + lbls, ) return }