Skip to content

Commit

Permalink
bugfix: fix prometheus attributes other than string (#3190)
Browse files Browse the repository at this point in the history
  • Loading branch information
tony612 authored Sep 19, 2022
1 parent 798b423 commit fae4b90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The `"go.opentelemetry.io/otel/sdk/metric".NewAccumulator` function was removed, see `NewMeterProvider`in the new metric SDK. (#3175)
- The deprecated `"go.opentelemetry.io/otel/sdk/metric".AtomicFieldOffsets` function was removed. (#3175)

### Fixed

- Fix attributes other than string in the Prometheus exporter. (#3190)

## [1.10.0] - 2022-09-09

### Added
Expand Down Expand Up @@ -225,7 +229,7 @@ Code instrumented with the `go.opentelemetry.io/otel/metric` will need to be mod
- `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT`
- `OTEL_SPAN_LINK_COUNT_LIMIT`
- `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT`

If the provided environment variables are invalid (negative), the default values would be used.
- Rename the `gc` runtime name to `go` (#2560)
- Add resource container ID detection. (#2418)
Expand Down
4 changes: 2 additions & 2 deletions exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ func getAttrs(attrs attribute.Set) ([]string, []string) {
kv := itr.Attribute()
key := strings.Map(sanitizeRune, string(kv.Key))
if _, ok := keysMap[key]; !ok {
keysMap[key] = []string{kv.Value.AsString()}
keysMap[key] = []string{kv.Value.Emit()}
} else {
// if the sanitized key is a duplicate, append to the list of keys
keysMap[key] = append(keysMap[key], kv.Value.AsString())
keysMap[key] = append(keysMap[key], kv.Value.Emit())
}
}

Expand Down
2 changes: 2 additions & 0 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func TestPrometheusExporter(t *testing.T) {
attrs := []attribute.KeyValue{
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
attribute.Key("E").Bool(true),
attribute.Key("F").Int(42),
}
counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter"))
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/testdata/counter.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# HELP foo a simple counter
# TYPE foo counter
foo{A="B",C="D"} 24.3
foo{A="B",C="D",E="true",F="42"} 24.3

0 comments on commit fae4b90

Please sign in to comment.