Skip to content

Commit

Permalink
add test, changelog
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten committed Nov 29, 2023
1 parent 8409717 commit ae179d1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- Add `WithResourceAsConstantLabels` option to apply resource attributes for every metric emitted by the Prometheus exporter. (#4733)

## [1.21.0/0.44.0] 2023-11-16

### Removed
Expand Down
21 changes: 21 additions & 0 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

func TestPrometheusExporter(t *testing.T) {
filter := attribute.NewDenyKeysFilter()
testCases := []struct {
name string
emptyResource bool
Expand Down Expand Up @@ -368,6 +369,26 @@ func TestPrometheusExporter(t *testing.T) {
counter.Add(ctx, 9, opt)
},
},
{
name: "with resource attributes filter",
expectedFile: "testdata/with_resource_attributes_filter.txt",
options: []Option{
WithResourceAsConstantLabels(&filter),
},
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
opt := otelmetric.WithAttributes(
attribute.Key("A").String("B"),
attribute.Key("C").String("D"),
attribute.Key("E").Bool(true),
attribute.Key("F").Int(42),
)
counter, err := meter.Float64Counter("foo", otelmetric.WithDescription("a simple counter"))
require.NoError(t, err)
counter.Add(ctx, 5, opt)
counter.Add(ctx, 10.1, opt)
counter.Add(ctx, 9.8, opt)
},
},
}

for _, tc := range testCases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# HELP foo_total a simple counter
# TYPE foo_total counter
foo_total{A="B",C="D",E="true",F="42",otel_scope_name="testmeter",otel_scope_version="v0.1.0",service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 24.9
# HELP otel_scope_info Instrumentation Scope metadata
# TYPE otel_scope_info gauge
otel_scope_info{otel_scope_name="testmeter",otel_scope_version="v0.1.0"} 1
# HELP target_info Target metadata
# TYPE target_info gauge
target_info{service_name="prometheus_test",telemetry_sdk_language="go",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1

0 comments on commit ae179d1

Please sign in to comment.