When running in Chrome, it shows only text/plain, while with CURL it shows application/openmetrics-text
I'm running a Quarkus application with a Prometheus endpoint which will shows the "old" Prometheus format without exemplars when accessing the metrics endpoint in the Chrome browser, and it will show the OpenMetrics output when running it via CURL.
I assume that the content negotiation where Chrome sends among other accepted format "text/html" somehow let's the application go down the path of the old format, while when CURL doesn't send any headers, it chooses the new format.
So I wonder: Can I (or this extension) have Chrome send "application/openmetrics-text" as a supported mime type, so that I will see exemplars in the Chrome window?
The extension gets the current document request from Chrome and checks if its content type is either "application/openmetrics-text" (or "text/plain" and matching the path names defined). So basically you'd have to take every request matching the "text/plain" content type and try to request the same document as "application/openmetrics-text" again and work from there, which would be quite an overhead.
Also, the content type information you get in the extension itself isn't really great. Prometheus sends content-type: text/plain; version=0.0.4; charset=utf-8; escaping=values which would make it easier to detect Prometheus endpoints in the first place, but all the extension sees is content-type: text/plain.
So at the moment, I'm not really sure how to implement this check in a sensible way, but I'm open to suggestions.
As a short term solution, there seem to be Chrome extensions which can override headers. I just did a quick Google search on "chrome force content type", but haven't looked at any extension in particular.
Also, I haven't worked with exemplars yet, could you please provide some sort of example output so I can check if the highlighting still works correctly?
Here's an example of a metrics with the exemplar. You'll see it after the hash:
http_server_requests_seconds_count{method="GET",outcome="SUCCESS",status="204",uri="/realms/{realm}/protocol/{protocol}/login-status-iframe.html/init"} 2.0 # {span_id="cc258ebf850c7ec8",trace_id="39750627ed1138e074b6256816bfa845"} 1.0 1728839669.614
About the content type: When writing this, I didn't have the response content type in mind, but the accepted types. My browser currently sends something like the following. I wonder if this extension could add application/openmetrics-text to it.
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Thanks for the example!
I'm lookin into modifying the request headers, might take a little while.
I've been playing around with the declarativeNetRequest API to modify the Accept header, so far I couldn't get it to work. I'd happily accept a PR.
Ref:
- https://stackoverflow.com/questions/3274144/can-i-modify-outgoing-request-headers-with-a-chrome-extension
- https://developer.chrome.com/docs/extensions/reference/api/declarativeNetRequest#header_modification