@@ -207,7 +207,13 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
207207 if encodingHeader != string (Identity ) {
208208 rsp .Header ().Set (contentEncodingHeader , encodingHeader )
209209 }
210- enc := expfmt .NewEncoder (w , contentType )
210+
211+ var enc expfmt.Encoder
212+ if opts .EnableOpenMetricsTextCreatedSamples {
213+ enc = expfmt .NewEncoder (w , contentType , expfmt .WithCreatedLines ())
214+ } else {
215+ enc = expfmt .NewEncoder (w , contentType )
216+ }
211217
212218 // handleError handles the error according to opts.ErrorHandling
213219 // and returns true if we have to abort after the handling.
@@ -408,6 +414,21 @@ type HandlerOpts struct {
408414 // (which changes the identity of the resulting series on the Prometheus
409415 // server).
410416 EnableOpenMetrics bool
417+ // EnableOpenMetricsTextCreatedSamples specifies if this handler should add, extra, synthetic
418+ // Created Timestamps for counters, histograms and summaries, which for the current
419+ // version of OpenMetrics are defined as extra series with the same name and "_created"
420+ // suffix. See also the OpenMetrics specification for more details
421+ // https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#counter-1
422+ //
423+ // Created timestamps are used to improve the accuracy of reset detection,
424+ // but the way it's designed in OpenMetrics 1.0 it also dramatically increases cardinality
425+ // if the scraper does not handle those metrics correctly (converting to created timestamp
426+ // instead of leaving those series as-is). New OpenMetrics versions might improve
427+ // this situation.
428+ //
429+ // Prometheus introduced the feature flag 'created-timestamp-zero-ingestion'
430+ // in version 2.50.0 to handle this situation.
431+ EnableOpenMetricsTextCreatedSamples bool
411432 // ProcessStartTime allows setting process start timevalue that will be exposed
412433 // with "Process-Start-Time-Unix" response header along with the metrics
413434 // payload. This allow callers to have efficient transformations to cumulative
0 commit comments