A library which integrates Sentry logging into Pyramid with the ability to filter out unwanted messages.
Project description
Hypothesis Pyramid Sentry Extension
A library which integrates Sentry logging into Pyramid with the ability to filter out unwanted messages.
This is a Pyramid extension that wraps sentry-sdk's Pyramid integration and adds some additional customization and features.
Features
-
Initializes sentry-sdk with its Pyramid integration for you. Your app just has to set any
"h_pyramid_sentry.*"
settings that you want and then doconfig.include("h_pyramid_sentry")
(see instructions below for details). -
Prevents retryable exceptions from being reported to Sentry if your app is using pyramid_retry and the request is going to be retried (requires the
"h_pyramid_sentry.retry_support": True
setting, see below).Retryable exceptions will still be reported to Sentry if the request is not going to be retried again because it has run out of retry attempts or because one of the retries fails with a non-retryable exception. When this happens only the exception from the request's final attempt is reported to Sentry, so you get a single Sentry event per request not multiple, but information about the previous failed attempts' exceptions is added to the single Sentry event.
-
Ignores errors logged by
exc_logger
if your app is using pyramid_exclog.pyramid_exclog logs all exceptions with log-level ERROR, and these all get picked up by sentry_sdk's enabled-by-default logging integration. This would mean that all exceptions in Sentry appear to come from exc_logger, and that some handled exceptions that wouldn't normally be reported to Sentry now would get reported. This extension prevents the interference by telling sentry_sdk to ignore exc_logger.
-
Provides a convenient method for apps to register their own filters for exceptions and logged errors that they don't want to be reported to Sentry. See the
"h_pyramid_sentry.filters"
setting below.
Usage
config.add_settings({...}) # See below for available settings.
config.include("h_pyramid_sentry")
Filters
In your Pyramid configuration you can provide a list of filter functions in the
setting h_pyramid_sentry.filters
.
These functions are passed Event objects which
they can inspect. If the function returns True
, then the event is not sent to
Sentry.
For example to prevent reporting of ValueError
s:
config.add_settings({
"h_pyramid_sentry.filters": [
lambda event: instanceof(event.exception, ValueError)
],
})
Settings
The extension will listen to the following Pyramid deployment settings:
Pyramid setting | Effect |
---|---|
h_pyramid_sentry.init |
A dict of any options understood by sentry_sdk.init() |
h_pyramid_sentry.filters |
A list of functions to apply as filters |
h_pyramid_sentry.retry_support * |
Enable retry detection and filtering |
h_pyramid_sentry.celery_support * |
Enable Celery support for Sentry |
h_pyramid_sentry.sqlalchemy_support * |
Enable SQLAlchemy support for Sentry |
* Enabling retry or celery support requires your application to list the relevant dependency (pyramid_retry
or celery
) as a dependency.
As per the Sentry docs, the
environment variable SENTRY_DSN
will be automatically read if set, although this can
also be passed along with any other Sentry SDK options via h_pyramid_sentry.init
.
Setting up Your Hypothesis Pyramid Sentry Extension Development Environment
First you'll need to install:
- Git.
On Ubuntu:
sudo apt install git
, on macOS:brew install git
. - GNU Make.
This is probably already installed, run
make --version
to check. - pyenv. Follow the instructions in pyenv's README to install it. The Homebrew method works best on macOS. The Basic GitHub Checkout method works best on Ubuntu. You don't need to set up pyenv's shell integration ("shims"), you can use pyenv without shims.
Then to set up your development environment:
git clone https://github.com/hypothesis/h-pyramid-sentry.git
cd h_pyramid_sentry
make help
Releasing a New Version of the Project
-
First, to get PyPI publishing working you need to go to: https://github.com/organizations/hypothesis/settings/secrets/actions/PYPI_TOKEN and add h-pyramid-sentry to the
PYPI_TOKEN
secret's selected repositories. -
Now that the h-pyramid-sentry project has access to the
PYPI_TOKEN
secret you can release a new version by just creating a new GitHub release. Publishing a new GitHub release will automatically trigger a GitHub Actions workflow that will build the new version of your Python package and upload it to https://pypi.org/project/h-pyramid-sentry.
Changing the Project's Python Versions
To change what versions of Python the project uses:
-
Change the Python versions in the cookiecutter.json file. For example:
"python_versions": "3.10.4, 3.9.12",
-
Re-run the cookiecutter template:
make template
-
Commit everything to git and send a pull request
Changing the Project's Python Dependencies
To change the production dependencies in the setup.cfg
file:
-
Change the dependencies in the
.cookiecutter/includes/setuptools/install_requires
file. If this file doesn't exist yet create it and add some dependencies to it. For example:pyramid sqlalchemy celery
-
Re-run the cookiecutter template:
make template
-
Commit everything to git and send a pull request
To change the project's formatting, linting and test dependencies:
-
Change the dependencies in the
.cookiecutter/includes/tox/deps
file. If this file doesn't exist yet create it and add some dependencies to it. Use tox's factor-conditional settings to limit which environment(s) each dependency is used in. For example:lint: flake8, format: autopep8, lint,tests: pytest-faker,
-
Re-run the cookiecutter template:
make template
-
Commit everything to git and send a pull request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file h-pyramid-sentry-1.2.4.tar.gz
.
File metadata
- Download URL: h-pyramid-sentry-1.2.4.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6353d851a233f786162ae1ea445d051b8baa153157ffec6307771fbd8573872 |
|
MD5 | e9554b38ae4feb87529089187216e988 |
|
BLAKE2b-256 | a6689f9d415d50dece680d019940ab37004f74a3c04f76610dceaf6fcd4440fc |
File details
Details for the file h_pyramid_sentry-1.2.4-py3-none-any.whl
.
File metadata
- Download URL: h_pyramid_sentry-1.2.4-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 305a3e43fb117870921798bca210c636593e3dd72c5b1b00f804020b07049eb6 |
|
MD5 | 9ebe6f969ba6807a566713eff2574af2 |
|
BLAKE2b-256 | 81fed232fed37b67ec0e1ac64cdaeb26882be81e01592ae4402b2fda34f836f9 |