Skip to main content

OOPS AMQP transport.

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_amqp package provides an AMQP OOPS (https://pypi.org/project/oops) publisher, and a small daemon that listens on amqp for OOPS reports and republishes them (into a supplied publisher). The OOPS framework permits falling back to additional publishers if AMQP is down.

Dependencies

Testing Dependencies

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="/")
>>> publisher = oops_amqp.Publisher(factory, "oopses", "")

Provide the publisher to your OOPS config:

>>> config = oops.Config()
>>> config.publisher = 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 amqp 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_with_fallback 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="/")
>>> fallback_publisher = oops_amqp.Publisher(fallback_factory, "oopses", "")
>>> config.publisher = publish_with_fallback(publisher, 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 connection factory (to handle the amqp server being restarted) and a queue name to receive from.

This example uses the DateDirRepo publisher, telling it to accept whatever id was assigned by the process publishing to AMQP:

>>> publisher = oops_datedir_repo.DateDirRepo('.', inherit_id=True)
>>> config = oops.Config()
>>> config.publisher = publisher.publish
>>> receiver = oops_amqp.Receiver(config, factory, "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 run the tests, use tox.

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_amqp-0.3.0.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

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

oops_amqp-0.3.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file oops_amqp-0.3.0.tar.gz.

File metadata

  • Download URL: oops_amqp-0.3.0.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for oops_amqp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0dde0d12d84102f8f54b7958628ea0e67f51fef71c8cbcedf7b37c7230fffa1a
MD5 56d2688721c5f59d7c0e266580ed1d69
BLAKE2b-256 e9ce9dee9af14b38bf809786b70e41a19df138c0e0ced19104565a590ce34221

See more details on using hashes here.

File details

Details for the file oops_amqp-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: oops_amqp-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for oops_amqp-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb0f8f746053ca2ce000686f64d7bdc6e3db3550086f6e5cd0f6e7215c7a8c35
MD5 c0d5c835d9a08169c8f59b9f3a446f57
BLAKE2b-256 46bde78dad80723d687945c9df860adf1aabf12b5e0a56e1edf53b5a8caf1b7a

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