GithubHelp home page GithubHelp logo

robinsingh1 / flask-tracking Goto Github PK

View Code? Open in Web Editor NEW

This project forked from closeio/flask-tracking

0.0 2.0 0.0 240 KB

Tracking app for Flask that logs HTTP request and response information in a capped MongoDB collection

Python 100.00%

flask-tracking's Introduction

flask-tracking

flask-tracking is a tracking app for Flask that logs HTTP request and response information in a capped MongoDB collection. For each request, the execution time is stored, making it easy to identify slow requests. flask-tracking supports Flask-Login to store the currently logged in user and requires MongoEngine to store the tracking information.

Installation

In your main application file, install the tracking app as follows:

from flask.ext.tracking import Tracking
Tracking(app)

Make sure to set up the tracking app as early as possible to ensure accurate logging of the response and execution time. If you're using Flask-gzip, install the tracking middleware afterwards to avoid logging compressed responses.

From now on, all requests are stored in the tracking collection.

Configuration

  • TRACKING_EXCLUDE: A list of regular expressions of paths that you want to exclude from being tracked.

    Example:

TRACKING_EXCLUDE = [
    '^/favicon.ico$',
    '^/static/',
    '^/_debug_toolbar/',
]
  • TRACKING_EXCLUDE_BODY: A list of regular expressions of paths where you don't want to track the request and response body. This is useful if specific paths receive or return sensitive data.

    Example:

TRACKING_EXCLUDE_BODY = [
    '^/auth/login/$'
]
  • TRACKING_MAX_BODY_LENGTH: The maximum size in bytes of the request and response body that should be stored.

Examples

The following query shows all requests that took longer than one second to execute.

from flask.ext.tracking.documents import Tracking
Tracking.objects.filter(execution_time__gte=1000)

The following query shows all requests that were served between 23:40 and 23:45 UTC on October 22th, 2012:

from flask.ext.tracking.documents import Tracking
Tracking.objects.filter(date_created__gte='2012-10-22 23:40:00', date_created__lte='2012-10-22 23:45:00') 

Storing custom data

Sometimes it is useful to store custom data in the tracking table for a given request. To do that, simply assign your data to request._tracking_data. Example:

from flask import request
def my_view():
    request._tracking_data = {'action: 'view', 'my_stuff': [1, 2, 3]}
    return render()

Custom data is stored in a DynamicField called custom_data and can therefore contain any information.

flask-tracking's People

Contributors

wojcikstefan avatar thomasst avatar philfreo avatar anemitz avatar

Watchers

Robin avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.