Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `RPCConnectRPCResponseMetadata`
- `RPCGRPCRequestMetadata`
- `RPCGRPCResponseMetadata`
- Export exemplars on native histograms in `go.opentelemetry.io/otel/exporters/prometheus`. (#22731)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
2 changes: 1 addition & 1 deletion exporters/prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func addExponentialHistogramMetric[N int64 | float64](
continue
}

// TODO(GiedriusS): add exemplars here after https://github.com/prometheus/client_golang/pull/1654#pullrequestreview-2434669425 is done.
m = addExemplars(m, dp.Exemplars)
ch <- m
}
}
Expand Down
43 changes: 34 additions & 9 deletions exporters/prometheus/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,21 @@ func TestExemplars(t *testing.T) {
escapingScheme: model.NoEscaping,
validationScheme: model.UTF8Validation,
},
{
name: "exponential histogram",
recordMetrics: func(ctx context.Context, meter otelmetric.Meter) {
hist, err := meter.Float64Histogram("exponential_histogram_foo",
otelmetric.WithDescription("a very nice histogram"),
otelmetric.WithUnit("By"),
)
require.NoError(t, err)
hist.Record(ctx, 9, attrsOpt)
},
expectedExemplarValue: 9,
expectedLabels: expectedNonEscapedLabels,
escapingScheme: model.NoEscaping,
validationScheme: model.UTF8Validation,
},
} {
t.Run(tc.name, func(t *testing.T) {
originalEscapingScheme := model.NameEscapingScheme
Expand Down Expand Up @@ -1112,17 +1127,27 @@ func TestExemplars(t *testing.T) {
provider := metric.NewMeterProvider(
metric.WithReader(exporter),
metric.WithResource(res),
metric.WithView(metric.NewView(
metric.Instrument{Name: "*"},
metric.Stream{
// filter out all attributes so they are added as filtered
// attributes to the exemplar
AttributeFilter: attribute.NewAllowKeysFilter(),
},
)),
metric.WithView(
metric.NewView(
metric.Instrument{Name: "exponential_histogram_*"},
metric.Stream{
Aggregation: metric.AggregationBase2ExponentialHistogram{
MaxSize: 10,
},
AttributeFilter: attribute.NewAllowKeysFilter(),
},
),
metric.NewView(
metric.Instrument{Name: "*"},
metric.Stream{
// filter out all attributes so they are added as filtered
// attributes to the exemplar
AttributeFilter: attribute.NewAllowKeysFilter(),
},
),
),
)
meter := provider.Meter("meter", otelmetric.WithInstrumentationVersion("v0.1.0"))

// Add a sampled span context so that measurements get exemplars added
sc := trace.NewSpanContext(trace.SpanContextConfig{
SpanID: trace.SpanID{0o1},
Expand Down
Loading