open-telemetry / opentelemetry-go

OpenTelemetry Go API and SDK
https://opentelemetry.io/
Apache License 2.0
5.16k stars 1.04k forks source link

Prometheus Exporter should have an option to export using OpenMetrics format #3468

Open paivagustavo opened 1 year ago

paivagustavo commented 1 year ago

Problem Statement

Prometheus exporter only expose metrics using the Prometheus format, which is a subset of the OpenMetrics format. Ideally, we should be able to specify an option to export metrics using the OpenMetrics format.

Given that we don't expose an OpenMetrics format, we lose information about metric's units, which make some required processing of Prometheus metric to OTLP as the specs define to be skipped, e..g, unit suffixes added by the otel-go are not able to be removed due to the lack of unit information as a limitation of the prometheus format.

Proposed Solution

A prometheus.WithOpenMetrics() option to enable the OpenMetrics format, which should contains unit metadata and implement the OTLP Metric points to Prometheus.

The Unit of an OTLP metric point MUST be added as OpenMetrics UNIT metadata. Additionally, the unit MUST be added as a suffix to the metric name, and SHOULD be converted to base units recommended by OpenMetrics when possible. The unit suffix comes before any type-specific suffixes.

Alternatives

Another alternative would always enable this behavior, but having an option to enable/disabled can be useful.

MadVikingGod commented 1 year ago

I explored trying to get prometheus to expose the Unit types, and it looks like the library doesn't do this yet https://github.com/prometheus/client_golang/issues/684.

MrAlias commented 1 year ago

This doesn't look to be required for GA, moving to the post-GA project.

MrAlias commented 1 year ago

Note from SIG meeting: this will likely depend on the underlying Prometheus library supporting OpenMetrics before we want to also support it.

dashpole commented 11 months ago

You can use OpenMetrics today with the prometheus exporter. In the example, you can change this line: https://github.com/open-telemetry/opentelemetry-go/blob/0e874c3468c2cbc5bbaf075537be6c0f2152b5ef/example/prometheus/main.go#L93

To:

http.Handle("/metrics", HandlerFor(prometheus.DefaultGatherer, HandlerOpts{EnableOpenMetrics: true})) 
dashpole commented 11 months ago

I don't think this blocks the prometheus exporter GA. Adding UNIT metadata to the exporter after the go client has support can be done as an addition later.

dashpole commented 7 months ago

Blocked by https://github.com/prometheus/client_golang/issues/684