Class ExemplarLabelsSupplier
Supplier of additional Labels that are merged into every
automatically-sampled Exemplar across the entire application.
This is the global counterpart to the per-metric exemplarLabelsSupplier(...) builder
method. Registering a supplier here affects all metrics, including metrics registered by
third-party libraries that the application does not control. This makes it the right tool when
you cannot modify the code that creates the metrics.
The supplier is invoked on the metric hot path (rate-limited by the exemplar sampler), each time an Exemplar is sampled from a valid, sampled span context. It should therefore be cheap and non-blocking. It may return dynamic, request-scoped values, for example an identifier read from a thread-local:
ExemplarLabelsSupplier.setExemplarLabelsSupplier(
() -> Labels.of("management_id", currentManagementId()));
Labels returned by the supplier that collide with trace_id/span_id (or, when a
per-metric supplier is also configured, with that supplier's labels) are silently dropped rather
than causing an error: the per-metric supplier takes precedence over the global one, and the
reserved trace_id/span_id labels always win. If the supplier throws, the
exception is swallowed and the Exemplar is created without the additional labels, so a
misbehaving supplier never breaks metric collection.
-
Method Summary
Modifier and TypeMethodDescriptionReturns the registered global supplier, ornullif none has been set.static voidsetExemplarLabelsSupplier(Supplier<Labels> supplier) Register a global supplier of additional exemplar labels.
-
Method Details
-
setExemplarLabelsSupplier
Register a global supplier of additional exemplar labels. Passnullto remove a previously registered supplier. The most recently registered supplier wins. -
getExemplarLabelsSupplier
Returns the registered global supplier, ornullif none has been set.
-