Skip to main content

Server-side analytics

Project description

Tracker

Tracker is a python package, that can be integrated into

  • any django project as middleware;

  • any flask project as extension.

It asynchronously intercepts requests and sends metric data to our RigidAnalytics Backend (see https://github.com/reustleco/rigidanalytics).

Installation

From PyPI

pip install rigidanalytics-tracker

From git repository

git clone git@github.com:reustleco/rigidanalytics-tracker.git
cd rigidanalytics-tracker
pipenv install
pipenv shell

Configuration

Below the following environment variables are in use: RA_PROJECT_ID, RA_PROJECT_TOKEN and RA_BACKEND_ENDPOINT.

In order to get project ID and token you need to have access to the admin pages on RigidAnalytics Backend. RA_BACKEND_ENDPOINT is the base URL to the Backend. If it is not provided then the default URL (i.e. https://rigidanalytics.com) is used instead.

Django integration

  • Add rigidanalytics_tracker.middleware.Analytics middleware to the MIDDLEWARE (after all django middlewares).

  • Add the following dict that configures Tracker:

RIGID_ANALYTICS = {
    'PROJECT_ID': os.environ['RA_PROJECT_ID'],
    'PROJECT_TOKEN': os.environ['RA_PROJECT_TOKEN'],
    'DEBUG_DISABLE_ANALYTICS': False,
    'BACKEND_ENDPOINT': os.environ.get('RA_BACKEND_ENDPOINT', ''),
}

See an example django integration about how everything configured there.

Flask integration

from rigidanalytics_tracker.flask import Tracker

flask_app.config['RIGID_ANALYTICS'] = {
    'PROJECT_ID': os.environ['RA_PROJECT_ID'],
    'PROJECT_TOKEN': os.environ['RA_PROJECT_TOKEN'],
    'DEBUG_DISABLE_ANALYTICS': False,
    'BACKEND_ENDPOINT': os.environ.get('RA_BACKEND_ENDPOINT', ''),
}
tracker = Tracker()
tracker.init_app(flask_app)

See an example flask integration about how everything configured there.

Automated tests

The automated tests are implemented by means of tox. In order to run the tests execute the following command:

tox

Test the tracker

Create an virtual environment:

cd tests/integrations/
pipenv install --dev
pipenv shell

Run event handler:

dotenv -f .env.example run ./event_handler.py

In the applications the tracker is configured to send the events to the event handler. Once an event is captured it is printed to console.

Test django integration

dotenv -f .env.example run ./django_app/manage.py migrate
dotenv -f .env.example run ./django_app/manage.py runserver

Open home page and then check console (with the event handler) for an event.

Test flask integration

dotenv -f .env.example run python ./flask_app/app.py

Open home page and then check console (with the event handler) for an event.

Test with the existing backend

Create .env:

cp .env.example .env

Get a project ID and project token from the existing RigidAnalytics backend and put them into the RA_PROJECT_ID and RA_PROJECT_TOKEN respectively. Put backend URL into the RA_BACKEND_ENDPOINT.

Start flask application:

dotenv run python ./flask_app/app.py

Open home page and then check backend admin for a new event.

Load Testing

Depending on OS, the maximum number of open files needs to be adjusted.

While still inside the integrations folder, run locust server.

locust

The dashboard for locust is at http://localhost:8089.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rigidanalytics_tracker-2.0.5.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rigidanalytics_tracker-2.0.5-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file rigidanalytics_tracker-2.0.5.tar.gz.

File metadata

  • Download URL: rigidanalytics_tracker-2.0.5.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for rigidanalytics_tracker-2.0.5.tar.gz
Algorithm Hash digest
SHA256 71e8d33a0bbbe88a41fd724469758c6b8a47b59f1b1d124f99af0bc2f7e5f941
MD5 faebed956084efa601aeb6a760823747
BLAKE2b-256 86ac891f268016bb0e56e03be7496460c12bb757854e7a6e06320610e12641ac

See more details on using hashes here.

File details

Details for the file rigidanalytics_tracker-2.0.5-py3-none-any.whl.

File metadata

  • Download URL: rigidanalytics_tracker-2.0.5-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for rigidanalytics_tracker-2.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f72325f8eb2261ce8ec450a0cfa9bdc8032f1e480959c2ad1613750451c15936
MD5 327802499627d3f474c1843e149a51c8
BLAKE2b-256 3bc8e7bf1d82e893807a24d66e49ae5e9ad546547f3bef39ccead52d27e04550

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page