1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-03 22:52:30 +02:00
This commit is contained in:
jmacd 2020-05-21 09:53:34 -07:00
parent 48a8a869fe
commit 3d2493463c
2 changed files with 7 additions and 3 deletions

View File

@ -354,6 +354,11 @@ func (c *collector) toDesc(record export.Record, labelKeys []string) *prometheus
return prometheus.NewDesc(sanitize(desc.Name()), desc.Description(), labelKeys, nil)
}
// mergeLabels merges the export.Record's labels and resources into a
// single set, giving precedence to the record's labels in case of
// duplicate keys. This outputs one or both of the keys and the
// values as a slice, and either argument may be nil to avoid
// allocating an unnecessary slice.
func mergeLabels(record export.Record, keys, values *[]string) {
if keys != nil {
*keys = make([]string, 0, record.Labels().Len()+record.Resource().Len())

View File

@ -99,9 +99,8 @@ func Merge(a, b *Resource) *Resource {
return a
}
// Note: 'b' is listed first so that 'a' will overwrite with
// last-value-wins in label.Key()
// combine := append(b.Attributes(), a.Attributes()...)
// Note: 'a' labels will overwrite 'b' with last-value-wins in label.Key()
// Meaning this is equivalent to: append(b.Attributes(), a.Attributes()...)
mi := label.NewMergeIterator(a.LabelSet(), b.LabelSet())
combine := make([]kv.KeyValue, 0, a.Len()+b.Len())
for mi.Next() {