1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-20 03:30:02 +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) 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) { func mergeLabels(record export.Record, keys, values *[]string) {
if keys != nil { if keys != nil {
*keys = make([]string, 0, record.Labels().Len()+record.Resource().Len()) *keys = make([]string, 0, record.Labels().Len()+record.Resource().Len())

View File

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