@@ -160,7 +160,7 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
160
160
}
161
161
162
162
var contentType expfmt.Format
163
- if opts .EnableOpenMetrics {
163
+ if opts .EnableOpenMetrics || opts . OpenMetricsOptions . EnableOpenMetrics {
164
164
contentType = expfmt .NegotiateIncludingOpenMetrics (req .Header )
165
165
} else {
166
166
contentType = expfmt .Negotiate (req .Header )
@@ -181,7 +181,7 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
181
181
}
182
182
183
183
var enc expfmt.Encoder
184
- if opts .EnableOpenMetricsCreatedMetrics {
184
+ if opts .OpenMetricsOptions . EnableOpenMetricsCreatedMetrics {
185
185
enc = expfmt .NewEncoder (w , contentType , expfmt .WithCreatedLines ())
186
186
} else {
187
187
enc = expfmt .NewEncoder (w , contentType )
@@ -366,6 +366,32 @@ type HandlerOpts struct {
366
366
// away). Until the implementation is improved, it is recommended to
367
367
// implement a separate timeout in potentially slow Collectors.
368
368
Timeout time.Duration
369
+ // If true, the experimental OpenMetrics encoding is added to the
370
+ // possible options during content negotiation. Note that Prometheus
371
+ // 2.5.0+ will negotiate OpenMetrics as first priority. OpenMetrics is
372
+ // the only way to transmit exemplars. However, the move to OpenMetrics
373
+ // is not completely transparent. Most notably, the values of "quantile"
374
+ // labels of Summaries and "le" labels of Histograms are formatted with
375
+ // a trailing ".0" if they would otherwise look like integer numbers
376
+ // (which changes the identity of the resulting series on the Prometheus
377
+ // server).
378
+ //
379
+ // Deprecated: Use OpenMetricsOptions.EnableOpenMetrics instead.
380
+ EnableOpenMetrics bool
381
+ // OpenMetricsOptions holds settings for the experimental OpenMetrics encoding.
382
+ // It can be used to enable OpenMetrics encoding and for setting extra options.
383
+ OpenMetricsOptions OpenMetricsOptions
384
+ // ProcessStartTime allows setting process start timevalue that will be exposed
385
+ // with "Process-Start-Time-Unix" response header along with the metrics
386
+ // payload. This allow callers to have efficient transformations to cumulative
387
+ // counters (e.g. OpenTelemetry) or generally _created timestamp estimation per
388
+ // scrape target.
389
+ // NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus
390
+ // exposition format.
391
+ ProcessStartTime time.Time
392
+ }
393
+
394
+ type OpenMetricsOptions struct {
369
395
// If true, the experimental OpenMetrics encoding is added to the
370
396
// possible options during content negotiation. Note that Prometheus
371
397
// 2.5.0+ will negotiate OpenMetrics as first priority. OpenMetrics is
@@ -391,14 +417,6 @@ type HandlerOpts struct {
391
417
// _created lines will result in increased cardinality and no improvements
392
418
// in reset detection.
393
419
EnableOpenMetricsCreatedMetrics bool
394
- // ProcessStartTime allows setting process start timevalue that will be exposed
395
- // with "Process-Start-Time-Unix" response header along with the metrics
396
- // payload. This allow callers to have efficient transformations to cumulative
397
- // counters (e.g. OpenTelemetry) or generally _created timestamp estimation per
398
- // scrape target.
399
- // NOTE: This feature is experimental and not covered by OpenMetrics or Prometheus
400
- // exposition format.
401
- ProcessStartTime time.Time
402
420
}
403
421
404
422
// gzipAccepted returns whether the client will accept gzip-encoded content.
0 commit comments