// WrapRegistererWith returns a Registerer wrapping the provided // Registerer. Collectors registered with the returned Registerer will be // registered with the wrapped Registerer in a modified way. The modified // Collector adds the provided Labels to all Metrics it collects (as // ConstLabels). The Metrics collected by the unmodified Collector must not // duplicate any of those labels. Wrapping a nil value is valid, resulting // in a no-op Registerer. // // WrapRegistererWith provides a way to add fixed labels to a subset of // Collectors. It should not be used to add fixed labels to all metrics // exposed. See also // https://prometheus.io/docs/instrumenting/writing_exporters/#target-labels-not-static-scraped-labels // // Conflicts between Collectors registered through the original Registerer with // Collectors registered through the wrapping Registerer will still be // detected. Any AlreadyRegisteredError returned by the Register method of // either Registerer will contain the ExistingCollector in the form it was // provided to the respective registry. // // The Collector example demonstrates a use of WrapRegistererWith. func WrapRegistererWith(labels Labels, reg Registerer) Registerer { … } // WrapRegistererWithPrefix returns a Registerer wrapping the provided // Registerer. Collectors registered with the returned Registerer will be // registered with the wrapped Registerer in a modified way. The modified // Collector adds the provided prefix to the name of all Metrics it collects. // Wrapping a nil value is valid, resulting in a no-op Registerer. // // WrapRegistererWithPrefix is useful to have one place to prefix all metrics of // a sub-system. To make this work, register metrics of the sub-system with the // wrapping Registerer returned by WrapRegistererWithPrefix. It is rarely useful // to use the same prefix for all metrics exposed. In particular, do not prefix // metric names that are standardized across applications, as that would break // horizontal monitoring, for example the metrics provided by the Go collector // (see NewGoCollector) and the process collector (see NewProcessCollector). (In // fact, those metrics are already prefixed with “go_” or “process_”, // respectively.) // // Conflicts between Collectors registered through the original Registerer with // Collectors registered through the wrapping Registerer will still be // detected. Any AlreadyRegisteredError returned by the Register method of // either Registerer will contain the ExistingCollector in the form it was // provided to the respective registry. func WrapRegistererWithPrefix(prefix string, reg Registerer) Registerer { … } type wrappingRegisterer … func (r *wrappingRegisterer) Register(c Collector) error { … } func (r *wrappingRegisterer) MustRegister(cs ...Collector) { … } func (r *wrappingRegisterer) Unregister(c Collector) bool { … } type wrappingCollector … func (c *wrappingCollector) Collect(ch chan<- Metric) { … } func (c *wrappingCollector) Describe(ch chan<- *Desc) { … } func (c *wrappingCollector) unwrapRecursively() Collector { … } type wrappingMetric … func (m *wrappingMetric) Desc() *Desc { … } func (m *wrappingMetric) Write(out *dto.Metric) error { … } func wrapDesc(desc *Desc, prefix string, labels Labels) *Desc { … }