Skip to content

Commit

Permalink
Merge pull request #237 from colega/user-and-org-labels-on-exemplars
Browse files Browse the repository at this point in the history
Add user and org labels to observed exemplars
  • Loading branch information
bboreham authored Apr 28, 2022
2 parents 00e2e23 + 9cb616a commit f83ccc7
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 f83ccc7

Please sign in to comment.