[Exporter.Prometheus] Export _created series for OpenMetrics#7223
[Exporter.Prometheus] Export _created series for OpenMetrics#7223martincostello wants to merge 17 commits into
Conversation
Export `{name}_created` series for counters and histograms when start time is available when using OpenMetrics.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7223 +/- ##
==========================================
+ Coverage 89.86% 89.94% +0.07%
==========================================
Files 276 276
Lines 14007 14043 +36
==========================================
+ Hits 12588 12631 +43
+ Misses 1419 1412 -7
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Pull request overview
Adds support for exporting OpenMetrics {name}_created series for counters and histograms when a metric start time is available, and updates tests/changelogs accordingly.
Changes:
- Emit
{name}_createdsamples for counters and histograms in OpenMetrics format (whenMetricPoint.StartTimeis present). - Extend serializer and integration tests to validate presence/absence of
_createddepending on OpenMetrics negotiation. - Update Prometheus exporter changelogs to document the new behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs | Adds assertions that _created is exported only for OpenMetrics (counter + histogram). |
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusHttpListenerTests.cs | Updates HTTP listener integration expectations to include _created in OpenMetrics responses. |
| test/OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests/PrometheusExporterMiddlewareTests.cs | Updates ASP.NET Core middleware integration expectations to include _created in OpenMetrics responses. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs | Implements writing of {name}_created lines based on MetricPoint.StartTime. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Documents the new _created OpenMetrics series behavior. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Documents the new _created OpenMetrics series behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add missing `TYPE` metadata.
Fix test for updated behaviour.
|
@martincostello could you please check the copilot cli feedback. PR #7223 Review: [Exporter.Prometheus] Export _created series for OpenMetrics 🔴 CRITICAL: Incorrect # TYPE _created gauge metadata line The PR emits a separate # TYPE {name}_created gauge metadata declaration. However, per the OpenMetrics spec, Spec example (Counter) — NO separate TYPE for _created:TYPE foo counterfoo_total 17.0 The PR incorrectly emits: TYPE foo_created gauge ← NOT in any spec exampleTYPE foo counterfoo_total 17.0 This could cause Prometheus parsers to reject the output since they know _created is a special suffix, not a 🟡 MEDIUM: Timestamp precision WriteUnixTimeSeconds uses ToUnixTimeMilliseconds() / 1000.0 → only millisecond precision. The WriteDouble with G17 🟢 LOW: Double iteration of MetricPoints HasCreatedMetric() iterates all metric points to check for non-default StartTime, then the main loop iterates again. ✅ Verified OK
The # TYPE {name}_created gauge metadata line appears to violate the OpenMetrics spec. The rest of the implementation looks solid. |
|
Will do - the fun of Copilot. Changes originally authored by it won't always fulfill its own review analysis 😄 |
- Remove non-spec `TYPE` for `_counter`. - Fix-up timestamp precision.
Fix-up duplicated definitions.
Fix-up merge.
Add missing suffix.
|
Codex feedback: |
Fix `_created` metrics not being emitted for negative histogram bucket bounds.
|
Done. |
Changes
Export
{name}_createdseries for counters and histograms when start time is available when using OpenMetrics.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)