ashcrow / flask-track-usage

Basic metrics tracking for the Flask framework.
Other
53 stars 33 forks source link

[Idea] Possibility to exclude url path, not only views #64

Open Patataman opened 2 years ago

Patataman commented 2 years ago

I wanted to use TRACK_USAGE_INCLUDE_OR_EXCLUDE_VIEWS = 'exclude' to track every view except the admin view, however it tracked too the requests for static files (which I don't want to track), creating a lot of entries in the database.

I tried to exclude it with

tracker.exclude("/static")

But when requesting static files, TrackUsage.before_request -> self.app.view_functions.get(ctx.request.endpoint) https://github.com/ashcrow/flask-track-usage/blob/629ad1c285dc48e73ef17319b62379643a143221/src/flask_track_usage/__init__.py#L109 returns a lambda, which makes impossible (or at least I could find how to replicate) exclude those routes.

This could be very handy for semi-large/large applications where is faster just exclude 1 view than include all the other views.

I have seen that ctx.request.path returns the path (/, /static, /admin, etc), maybe checking both possibilities, views and routes could be a solution for this?