Skip to content

Commit fae4b90

Browse files
authored
bugfix: fix prometheus attributes other than string (#3190)
1 parent 798b423 commit fae4b90

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
4242
- The `"go.opentelemetry.io/otel/sdk/metric".NewAccumulator` function was removed, see `NewMeterProvider`in the new metric SDK. (#3175)
4343
- The deprecated `"go.opentelemetry.io/otel/sdk/metric".AtomicFieldOffsets` function was removed. (#3175)
4444

45+
### Fixed
46+
47+
- Fix attributes other than string in the Prometheus exporter. (#3190)
48+
4549
## [1.10.0] - 2022-09-09
4650

4751
### Added
@@ -225,7 +229,7 @@ Code instrumented with the `go.opentelemetry.io/otel/metric` will need to be mod
225229
- `OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT`
226230
- `OTEL_SPAN_LINK_COUNT_LIMIT`
227231
- `OTEL_LINK_ATTRIBUTE_COUNT_LIMIT`
228-
232+
229233
If the provided environment variables are invalid (negative), the default values would be used.
230234
- Rename the `gc` runtime name to `go` (#2560)
231235
- Add resource container ID detection. (#2418)

exporters/prometheus/exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ func getAttrs(attrs attribute.Set) ([]string, []string) {
208208
kv := itr.Attribute()
209209
key := strings.Map(sanitizeRune, string(kv.Key))
210210
if _, ok := keysMap[key]; !ok {
211-
keysMap[key] = []string{kv.Value.AsString()}
211+
keysMap[key] = []string{kv.Value.Emit()}
212212
} else {
213213
// if the sanitized key is a duplicate, append to the list of keys
214-
keysMap[key] = append(keysMap[key], kv.Value.AsString())
214+
keysMap[key] = append(keysMap[key], kv.Value.Emit())
215215
}
216216
}
217217

exporters/prometheus/exporter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func TestPrometheusExporter(t *testing.T) {
4545
attrs := []attribute.KeyValue{
4646
attribute.Key("A").String("B"),
4747
attribute.Key("C").String("D"),
48+
attribute.Key("E").Bool(true),
49+
attribute.Key("F").Int(42),
4850
}
4951
counter, err := meter.SyncFloat64().Counter("foo", instrument.WithDescription("a simple counter"))
5052
require.NoError(t, err)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# HELP foo a simple counter
22
# TYPE foo counter
3-
foo{A="B",C="D"} 24.3
3+
foo{A="B",C="D",E="true",F="42"} 24.3

0 commit comments

Comments
 (0)