python-oops-amqp is a Python module that provides a publisher to send OOPS error reports over AMQP and a receiver that will consume them off an AMQP queue and republish to a local OOPS config.
This package permits immediate reporting of errors in an application - environments with message queues will probably want to use this rather than depending on a polling based method for transporting OOPS reports from the reporting machine to the analysis server.
For discussion please join the Launchpad developers list: https://launchpad.net/~launchpad-dev
Usage
Publishing to AMQP
Where you are creating OOPS reports, configure oops_amqp.Publisher. This takes a connection factory - a simple callable that creates an amqp connection - and the exchange name and routing key to submit to.
>>> factory = partial(amqp.Connection, host="localhost:5672",
... userid="guest", password="guest", virtual_host="/", insist=False)
>>> publisher = oops_amqp.Publisher(factory, "oopses", "")
Provide the publisher to your OOPS config:
>>> config = oops.Config()
>>> config.publishers.append(publisher)
Any oops published via that config will now be sent via amqp.
OOPS ids are generating by hashing the oops message (without the id field) - this ensures unique ids.
The reason a factory is used is because amqplib is not threadsafe - the publisher maintains a thread locals object to hold the factories and creates connections when new threads are created(when they first generate an OOPS).
Dealing with downtime
From time to time your AMQP server may be unavailable. If that happens then the Publisher will not assign an oops id - it will return None to signal that the publication failed. To prevent losing the OOPS its a good idea to have a fallback publisher - either another AMQP publisher (to a different server) or one that spools locally (where you can pick up the OOPSes via rsync or some other mechanism. Using the oops standard helper publish_new_only will let you wrap the fallback publisher so that it only gets invoked if the primary method failed:
>>> fallback_factory = partial(amqp.Connection, host="otherserver:5672",
... userid="guest", password="guest", virtual_host="/", insist=False)
>>> fallback_publisher = oops_amqp.Publisher(fallback_factory, "oopses", "")
>>> config.publishers.append(publish_new_only(fallback_publisher))
Receiving from AMQP
There is a simple method that will run an infinite loop processing reports from AMQP. To use it you need to configure a local config to publish the received reports. A full config is used because that includes support for filtering (which can be useful if you need to throttle volume, for instance). Additionally you need an amqp channel object and a queue name to receive from.
This example uses the OOPSDateDirRepo publisher, telling it to accept whatever id was assigned by the process publishing to AMQP:
>>> publisher = oops_datedir_repo.OOPSDateDirRepo('.', inherit_id=True)
>>> config = oops.Config()
>>> config.publishers.append(publisher.publish)
>>> connection = amqp.Connection(host="localhost:5672",
... userid="guest", password="guest", virtual_host="/", insist=False)
>>> receiver = oops_amqp.Receiver(config, connection, "my queue")
>>> receiver.run_forever()
For more information see pydoc oops_amqp.
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-amqp. 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_amqp.tests.test_suite.
For instance:
bin/py -m testtools.run oops_amqp.tests.test_suite
Product's homepage
Requirements:
· Python
· bson
· python-oops
· amqplib