stephenhillier / starlette_exporter

Prometheus exporter for Starlette and FastAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: skip_paths take patterns

bunny-therapist opened this issue · comments

The flask-prometheus-exporter uses excluded_paths which can take regular expressions like "/management/.*" which then excludes all paths under that path. I would like to do the same (I am trying to replace flask-prometheus-exporter with starlette-exporter without affecting metrics), but "skip_paths" just takes a list of strings. To get the same functionality I would have to list every endpoint under "/management/" - and if ever another endpoint is added to management (in another module), I would have to remember to add that as well.

Therefore, I request that skip_paths accepts regular expressions, or some kind of pattern, or at least a leading base path. I believe this won't break any backwards compatibility since an exact string can be seen as a regular expression that just matches that string (especially given the limited charset of urls). If backwards compatibility is a concern, one could simply pass in re.Pattern objects or similar to skip_paths and treat instances of str as before.

Great idea. Regex seems like a good choice.

I agree that existing usage (e.g. skip_paths=["/metrics"] should work fine as regex. If you are willing to submit a PR I can review it, if not I will try to work on it as time allows.