Skip to main content

Iron Leap Django SDK

Project description

Django Middleware

Send Iron Leap API call data.

How to install

pip install ironleapdjango

How to use

In your settings.py file in your Django project directory, please add ironleap.middleware.ironleap_middleware to the MIDDLEWARE array. For example:

MIDDLEWARE = [
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'ironleapdjango.middleware.ironleap_middleware'
    ...
]

Configuration options

APP_KEY

(required), string, provided by Iron Leap.

IRONLEAP_URL

(required), string, target url collecting events

Options specific to incoming API calls

SKIP

(optional) (request, response) => boolean, a function that takes a request and a response, and returns true if you want to skip this particular event.

IDENTIFY_COMPANY

(optional) (request, response) => string, a function that takes a request and a response, and returns a string that is the company id for this event.

GET_METADATA

(optional) (request, response) => dictionary, getMetadata is a function that returns an object that allows you to add custom metadata that will be associated with the event. The metadata must be a dictionary that can be converted to JSON. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

LOG_BODY

(optional) boolean, default True, Set to False to remove the HTTP body before sending. If you want more control over which fields are included or not included look at the individual mask method below.

MASK_EVENT_MODEL

(optional) (APIEvent) => APIEvent, a function that takes an APIEvent and returns another APIEvent. Use this if you prefer to write your own mask function than use the string based filter options: REQUEST_BODY_MASKS, REQUEST_HEADER_MASKS, RESPONSE_BODY_MASKS, & RESPONSE_HEADER_MASKS.

BATCH_SIZE

(optional) int, default 25, Batch size with which events get sent to Iron Leap.

EVENT_QUEUE_SIZE

(optional) int, default 1000, Maximum number of events to hold in queue before sending.

BATCH_SEND_INTERVAL

(optional) int, default 2, Number of seconds between sends of batch.

Example

def identify_company(req, res):
    # Your custom code that returns a company id string
    return "67890"

def should_skip(req, res):
    # Your custom code that returns true to skip logging
    return "health/probe" in req.path

def mask_event(eventmodel):
    # Your custom code to change or remove any sensitive fields
    if 'password' in eventmodel.response.body:
        eventmodel.response.body['password'] = None
    return eventmodel

def get_metadata(req, res):
    return {
        'datacenter': 'westus',
        'deployment_version': 'v1.2.3',
    }


IRONLEAP_MIDDLEWARE = {
    'APP_KEY': 'app key',
    'IRONLEAP_URL': 'https://analytics.ironleap.io/api/collect'
    'DEBUG': False,
    'LOG_BODY': True,
    'IDENTIFY_COMPANY': identify_company,
    'SKIP': should_skip,
    'MASK_EVENT_MODEL': mask_event,
    'GET_METADATA': get_metadata,
}

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

ironleapdjango-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

File details

Details for the file ironleapdjango-1.0.0.tar.gz.

File metadata

  • Download URL: ironleapdjango-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.20.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9

File hashes

Hashes for ironleapdjango-1.0.0.tar.gz
Algorithm Hash digest
SHA256 33d1cd8747ba80ceff163e196b1078f03e07ecdf2f31eb74abcced5d22889d61
MD5 c5d3c4037ae507ecdf11ca021bed5303
BLAKE2b-256 78dfc0d6f53a90083bd632f72489f2ae26670c4c01b09f9b5b57206f4a3feef9

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