Skip to content

promhttp: add AcceptedFormats option to customize format negotiation - #2146

Merged
bwplotka merged 1 commit into
mainfrom
om2-2
Oct 1, 2026
Merged

bwplotka merged 1 commit into
mainfrom
om2-2

Conversation

@bwplotka

@bwplotka bwplotka commented Oct 1, 2026

Copy link
Copy Markdown
Member

Allows customizing the formats negotiated by promhttp.Handler via HandlerOpts.AcceptedFormats.

When AcceptedFormats is empty:

  • If EnableOpenMetrics is false, expfmt.DefaultAcceptedFormats() is used.
  • If EnableOpenMetrics is true, expfmt.DefaultOpenMetricsAcceptedFormats() is used.

Callers can now specify custom formats in AcceptedFormats, allowing opt-in to experimental formats like OpenMetrics 2.0 (expfmt.FmtOpenMetrics_2_0_0) without altering the default negotiation behavior when EnableOpenMetrics is set.

Supersedes #2132.

@kakkoyun kakkoyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Add HandlerOpts.AcceptedFormats to allow callers to customize the
formats negotiated based on the incoming Accept header. This enables
opting into experimental formats such as OpenMetrics 2.0 without
altering the default negotiation behavior when EnableOpenMetrics is set.

Add table-driven tests for OpenMetrics 2.0 negotiation and exposition.

Signed-off-by: bwplotka <bwplotka@gmail.com>
@bwplotka
bwplotka enabled auto-merge October 1, 2026 12:47
@bwplotka
bwplotka merged commit ba782fc into main Oct 1, 2026
15 checks passed
@bwplotka
bwplotka deleted the om2-2 branch October 1, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants