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)
| 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. |
| 72 | func 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 |