Skip to main content

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 do config.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 ValueErrors:

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

  1. 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.

  2. 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:

  1. Change the Python versions in the cookiecutter.json file. For example:

    "python_versions": "3.10.4, 3.9.12",
    
  2. Re-run the cookiecutter template:

    make template
    
  3. 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:

  1. 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
    
  2. Re-run the cookiecutter template:

    make template
    
  3. Commit everything to git and send a pull request

To change the project's formatting, linting and test dependencies:

  1. 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,
    
  2. Re-run the cookiecutter template:

    make template
    
  3. Commit everything to git and send a pull request

Release files for h-pyramid-sentry 1.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for h-pyramid-sentry 1.2.4
File Size Uploaded
h-pyramid-sentry-1.2.4.tar.gz 22.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for h-pyramid-sentry 1.2.4
File Interpreter ABI Platform
h_pyramid_sentry-1.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 33.4 kB

Release files / h-pyramid-sentry-1.2.4.tar.gz

Download URL h-pyramid-sentry-1.2.4.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d6353d851a233f786162ae1ea445d051b8baa153157ffec6307771fbd8573872
BLAKE2b-256 checksum
How to use checksums
a6689f9d415d50dece680d019940ab37004f74a3c04f76610dceaf6fcd4440fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / h_pyramid_sentry-1.2.4-py3-none-any.whl

Download URL h_pyramid_sentry-1.2.4-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
305a3e43fb117870921798bca210c636593e3dd72c5b1b00f804020b07049eb6
BLAKE2b-256 checksum
How to use checksums
81fed232fed37b67ec0e1ac64cdaeb26882be81e01592ae4402b2fda34f836f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page