stephenhillier / starlette_exporter

Prometheus exporter for Starlette and FastAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom labels

PhE opened this issue · comments

How to define custom labels that will be used on every starlette_exporter metrics ?
For example to add the user_id (email) extracted from a JWT token or any part of the request/session.

It could be acheive with a callback or by monkey-patching *.

Does it make sense ?

The closest thing I can think of is to add a custom metric with any labels you like https://github.com/stephenhillier/starlette_exporter#custom-metrics. However, that will just add a new metric; the original default starlette_exporter metrics will still have the old labels.

I looked at https://github.com/rycus86/prometheus_flask_exporter#configuration and it looks like the Flask exporter provides a way to configure custom labels for all metrics so that might be a good feature here. I'm not currently able to devote a lot of time to new features myself though.

If the data is in headers we can extract specific Key value from header as label.
Example if in header you have:
Authorization: Bearer

Then we can have an auth label.
To decode the payload it will be to expensive from token.
However we can add labels base by specific header or all of them .

Custom labels now available in 0.14 (#52 )