Skip to main content

OOPS wsgi middleware.

Project description

Copyright (c) 2011, Canonical Ltd

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3 only.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. GNU Lesser General Public License version 3 (see the file LICENSE).

The oops_wsgi package provides integration glue between wsgi web servers and the oops error reporting system (http://pypi.python.org/pypi/oops).

Dependencies

Testing Dependencies

Usage

oops_wsgi provides integration with an oops.Config, permitting errors in your web application to be gathered centrally, with tracebacks and other diagnostic information.

Typically, something like this:

  • Setup your configuration:

    >>> from oops import Config
    >>> config = Config()

Note that you will probably want at least one publisher, or your reports will be discarded.

  • Add in wsgi specific hooks to the config:

    >>> oops_wsgi.install_hooks(config)

This is a convenience function - you are welcome to pick and choose the creation or filter hooks you want from oops_wsgi.hooks.

  • Create your wsgi app as normal, and then wrap it:

    >>> app = oops_wsgi.make_app(app, config)

If any exception bubbles up through this middleware, an oops will be logged. If the body of the request had not started, then a custom page is shown that shows the OOPS id, and the exception is swallowed. Exceptions that indicate normal situations like end-of-file on a socket do not trigger OOPSes. If the OOPS is filtered, or no publishers are configured, then the exception will propogate up the stack - the oops middleware cannot do anything useful in these cases. (For instance, if you have a custom 404 middleware above the oops middleware in the wsgi stack, and filter 404 exceptions so they do not create reports, then if the oops middleware did anything other than propogate the exception, your custom 404 middleware would not work.

If the body had started, then there is no way to communicate the OOPS id to the client and the exception will propogate up the wsgi app stack.

You can customise the error page if you supply a helper that accepts (environ, report) and returns HTML to be sent to the client.

>>> def myerror_html(environ, report):
...    return '<html><body><h1>OOPS! %s</h1></body></html>' % report['id']
>>> app = oops_wsgi.make_app(app, config, error_render=myerror_html)

Or you can supply a string template to be formatted with the report.

>>> json_template='{"oopsid" : "%(id)s"}'
>>> app = oops_wsgi.make_app(app, config, error_template=json_template)

For more information see pydoc oops_wsgi.

Installation

Either run setup.py in an environment with all the dependencies available, or add the working directory to your PYTHONPATH.

Development

Upstream development takes place at https://launchpad.net/python-oops-wsgi. To setup a working area for development, if the dependencies are not immediately available, you can use ./bootstrap.py to create bin/buildout, then bin/py to get a python interpreter with the dependencies available.

To run the tests use the runner of your choice, the test suite is oops_wsgi.tests.test_suite.

For instance:

$ bin/py -m testtools.run oops_wsgi.tests.test_suite

If you have testrepository you can run the tests with that:

$ testr run

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

oops_wsgi-0.0.7.tar.gz (7.6 kB view hashes)

Uploaded Source

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