Skip to content

Commit

Permalink
Add user and org labels to observed exemplars
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
colega committed Feb 15, 2022
1 parent 933588f commit 9cb616a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion instrument/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9cb616a

Please sign in to comment.