Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions internal/metrics/otel_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ func (l LabelValue) Value() string {
return l.keyValue.Value.AsString()
}

func mergeLabelValues(attrs []attribute.KeyValue, labelValues []LabelValue) ([]attribute.KeyValue, attribute.Set) {
mergedAttrs := make([]attribute.KeyValue, 0, len(attrs)+len(labelValues))
mergedAttrs = append(mergedAttrs, attrs...)
for _, v := range labelValues {
mergedAttrs = append(mergedAttrs, v.keyValue)
func mergeLabelValues(attrs []attribute.KeyValue, labelValues []LabelValue) []attribute.KeyValue {
mergedAttrs := make([]attribute.KeyValue, len(attrs)+len(labelValues))
copy(mergedAttrs, attrs)
for i, v := range labelValues {
mergedAttrs[len(attrs)+i] = v.keyValue
}

return mergedAttrs, attribute.NewSet(mergedAttrs...)
return mergedAttrs
}
6 changes: 3 additions & 3 deletions internal/metrics/otel_metric_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (f *Counter) Decrement() {
}

func (f *Counter) With(labelValues ...LabelValue) *Counter {
attrs, set := mergeLabelValues(f.attrs, labelValues)
mergedAttrs := mergeLabelValues(f.attrs, labelValues)
m := &Counter{
c: f.c,
preRecordOptions: []api.AddOption{api.WithAttributeSet(set)},
preRecordOptions: []api.AddOption{api.WithAttributes(mergedAttrs...)},
name: f.name,
attrs: attrs,
attrs: mergedAttrs,
}

return m
Expand Down
8 changes: 5 additions & 3 deletions internal/metrics/otel_metric_gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ func (f *Gauge) With(labelValues ...LabelValue) *Gauge {
f.mutex.Lock()
defer f.mutex.Unlock()

attrs, set := mergeLabelValues(f.attrs, labelValues)
mergedAttrs := mergeLabelValues(f.attrs, labelValues)
set := attribute.NewSet(mergedAttrs...)

m := &Gauge{
g: f.g,
mutex: f.mutex,
stores: f.stores,
name: f.name,
attrs: attrs,
attrs: mergedAttrs,
}
if _, f := m.stores[set]; !f {
m.stores[set] = &GaugeValues{
opt: []api.ObserveOption{api.WithAttributeSet(set)},
opt: []api.ObserveOption{api.WithAttributes(mergedAttrs...)},
}
}
m.current = m.stores[set]
Expand Down
6 changes: 3 additions & 3 deletions internal/metrics/otel_metric_histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (f *Histogram) Record(value float64) {
}

func (f *Histogram) With(labelValues ...LabelValue) *Histogram {
attrs, set := mergeLabelValues(f.attrs, labelValues)
mergedAttrs := mergeLabelValues(f.attrs, labelValues)
m := &Histogram{
name: f.name,
attrs: attrs,
attrs: mergedAttrs,
d: f.d,
preRecordOptions: []api.RecordOption{api.WithAttributeSet(set)},
preRecordOptions: []api.RecordOption{api.WithAttributes(mergedAttrs...)},
}

return m
Expand Down