@@ -180,7 +180,12 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
180180 w = gz
181181 }
182182
183- enc := expfmt .NewEncoder (w , contentType )
183+ var enc expfmt.Encoder
184+ if opts .EnableOpenMetricsCreatedMetrics {
185+ enc = expfmt .NewEncoder (w , contentType , expfmt .WithCreatedLines ())
186+ } else {
187+ enc = expfmt .NewEncoder (w , contentType )
188+ }
184189
185190 // handleError handles the error according to opts.ErrorHandling
186191 // and returns true if we have to abort after the handling.
@@ -371,6 +376,21 @@ type HandlerOpts struct {
371376 // (which changes the identity of the resulting series on the Prometheus
372377 // server).
373378 EnableOpenMetrics bool
379+ // If 'EnableOpenMetrics' is true, 'EnableOpenMetricsCreatedMetrics' allows
380+ // to add extra '_created' lines for counters, histograms and summaries,
381+ // as defined in the OpenMetrics specification (see
382+ // https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#counter-1).
383+ // Created timestamps are used to improve the accuracy of reset detection,
384+ // but be aware that it also increases the size of the payload.
385+ //
386+ // Prometheus introduced the feature flag 'created-timestamp-zero-ingestion'
387+ // in version 2.50.0, but with support limited to the Prometheus protobuf
388+ // format. Starting in Prometheus XXXX, the feature flag will be extended
389+ // to the OpenMetrics text format. If using Prometheus XXXX or later, it
390+ // is recommended to enable the feature flag in Prometheus, otherwise enabling
391+ // _created lines will result in increased cardinality and no improvements
392+ // in reset detection.
393+ EnableOpenMetricsCreatedMetrics bool
374394 // ProcessStartTime allows setting process start timevalue that will be exposed
375395 // with "Process-Start-Time-Unix" response header along with the metrics
376396 // payload. This allow callers to have efficient transformations to cumulative
0 commit comments