Skip to main content

Log and graph slow Pyramid and WSGI apps

Project description

Overview

The slowlog library helps you find out why some requests to your web application take a long time. It periodically dumps stack traces of long running requests to a log file. It works as a Pyramid tween or as a WSGI component. It is inspired by Products.LongRequestLogger, which provides similar functionality for Zope 2.

This library can also log frame statistics to Graphite using the perfmetrics library, making it possible to create real-time graphs that reveal expensive code paths.

This library uses sys._current_frames() to gather stack traces, so it supports CPython versions 2.6+ and 3.2+, but other Python implementations might not work.

TravisBadge

Installation

Install using setuptools, e.g. (within a virtualenv):

$ bin/easy_install slowlog

Pyramid Configuration

Once the slowlog library is installed, use the config.include mechanism to add slowlog to your project. In your Pyramid project’s __init__.py:

config = Configurator(...)
config.include('slowlog')

Alternately, you can add the following line to your application’s .ini file:

pyramid.includes = slowlog

Next, Pyramid needs some settings before the slowlog library has any effect. Two tweens are available, slowlog and framestats.

The slowlog tween

The slowlog tween periodically logs stack traces of long running requests. To activate it, set slowlog = true in your Pyramid settings. The slowlog tween supports the following settings.

slowlog

Set to true to activate the slowlog tween. Default: false.

slowlog_timeout

Only log stack traces of requests that last at least this number of seconds (floating point). Default: 2.0.

slowlog_interval

Once a request lasts longer than slowlog_timeout, the slowlog tween continues to log stack traces periodically with the given interval in seconds (floating point). Default: 1.0.

slowlog_file

Log all stack traces to the given file. The file will be rotated automatically when it grows to 10 megabytes. If this setting is empty or missing, stack traces will be logged using Python’s standard logging module with the logger name slowlog. Default: none.

slowlog_frames

Limit the number of frames in stack traces. If set to 0, no stack traces will be logged. Default: 100.

slowlog_hide_post_vars

A whitespace-delimited list of POST variables that should be redacted (hidden) in logs. Useful for avoiding accidental storage of cleartext passwords. Default: password.

The framestats tween

The framestats tween periodically increments Statsd counters for all frames on the stack of long-running requests. To activate it, set framestats = true in your Pyramid settings. The framestats tween supports the following settings.

framestats

Set to true to activate the framestats tween. Default: false.

statsd_uri

Required. A common URI is statsd://localhost:8125. See the perfmetrics library for supported parameters.

framestats_timeout

Only update Statsd for requests that last at least this number of seconds (floating point). Default: 2.0.

framestats_interval

Once a request lasts longer than framestats_timeout, the framestats tween continues to update Statsd periodically with the given interval in seconds (floating point). Default: 1.0.

framestats_frames

Limit the number of frames to follow in stack traces. If set to 1, Statsd will receive information about only the current frame. Default: 100.

CHANGES

0.9 (2012-09-22)

  • Initial release.

Project details


Release history Release notifications | RSS feed

This version

0.9

Download files

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

Source Distribution

slowlog-0.9.tar.gz (14.6 kB view details)

Uploaded Source

File details

Details for the file slowlog-0.9.tar.gz.

File metadata

  • Download URL: slowlog-0.9.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for slowlog-0.9.tar.gz
Algorithm Hash digest
SHA256 4faae46b28ab5a133c0b9ad49e1dae5435d8e977e7fbab7195bc99556f71325a
MD5 36f85f5279fc8fb9f436139ee581c928
BLAKE2b-256 66dafd7339236cf78322f97d4e94750bd9100655211f5bb86523e09cf639fdbc

See more details on using hashes here.

Supported by

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