MCPcopy
hub / github.com/prometheus/client_golang / WithExemplarFromContext

Function WithExemplarFromContext

prometheus/promhttp/option.go:72–76  ·  view source on GitHub ↗

WithExemplarFromContext allows to inject function that will get exemplar from context that will be put to counter and histogram metrics. If the function returns nil labels or the metric does not support exemplars, no exemplar will be added (noop), but metric will continue to observe/increment.

(getExemplarFn func(requestCtx context.Context) prometheus.Labels)

Source from the content-addressed store, hash-verified

70// If the function returns nil labels or the metric does not support exemplars, no exemplar will be added (noop), but
71// metric will continue to observe/increment.
72func WithExemplarFromContext(getExemplarFn func(requestCtx context.Context) prometheus.Labels) Option {
73 return optionApplyFunc(func(o *options) {
74 o.getExemplarFn = getExemplarFn
75 })
76}
77
78// WithLabelFromCtx registers a label for dynamic resolution with access to context.
79// See the example for ExampleInstrumentHandlerWithLabelResolver for example usage

Calls 1

optionApplyFuncFuncType · 0.85