Connect Pyramid to Bugsink
When a Pyramid request fails, Bugsink shows you the exception, the application frame that raised it, and the HTTP request that reached the view.
This guide covers the initial setup and Pyramid’s automatic capture of unhandled view exceptions. You’ll connect an existing application, then make one request fail to confirm that it reaches Bugsink.
To follow along, create a Bugsink project and copy its DSN. The quickstart guide shows where to find it.
Install the SDK
Install the open-source Sentry SDK in the environment your application uses. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project.
python -m pip install --upgrade sentry-sdkpython -m pip install --upgrade sentry-sdk
Configure Pyramid
Import the SDK and Pyramid integration where you configure the application:
import sentry_sdk from pyramid.config import Configurator from pyramid.view import view_config from sentry_sdk.integrations.pyramid import PyramidIntegrationimport sentry_sdk from pyramid.config import Configurator from pyramid.view import view_config from sentry_sdk.integrations.pyramid import PyramidIntegration
Initialize the SDK before creating the Configurator. Reading the DSN from
the environment keeps it out of source control:
sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[PyramidIntegration()], )sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[PyramidIntegration()], )
Set SENTRY_DSN in the environment where the application runs:
export SENTRY_DSN=https://key@bugsink.example/1export SENTRY_DSN=https://key@bugsink.example/1
Trigger an unhandled exception
If a Pyramid view raises an exception and does not catch it, the integration reports it automatically. There is no SDK call inside the view. To verify the setup, this checkout view raises an exception when a product is missing:
@view_config(route_name="checkout", renderer="json") def checkout(request): sku = request.matchdict["sku"] try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None return {"reserved": product["name"]}@view_config(route_name="checkout", renderer="json") def checkout(request): sku = request.matchdict["sku"] try: product = inventory[sku] except KeyError: raise ProductNotFound(f"Product {sku} is not in inventory") from None return {"reserved": product["name"]}
The application maps the checkout route to /checkout/{sku} and scans for
the decorated view:
def make_app(): with Configurator() as config: config.add_route("inventory", "/") config.add_route("checkout", "/checkout/{sku}") config.scan(__name__) return config.make_wsgi_app()def make_app(): with Configurator() as config: config.add_route("inventory", "/") config.add_route("checkout", "/checkout/{sku}") config.scan(__name__) return config.make_wsgi_app()
Start the application as usual, then request a product that does not exist through that URL:
python app.py :::bash curl http://127.0.0.1:8080/checkout/pyramid-missingpython app.py :::bash curl http://127.0.0.1:8080/checkout/pyramid-missing
Pyramid returns an HTTP 500 response and the integration reports the exception.
See the error in Bugsink
Open your Bugsink project and select the new ProductNotFound issue. Its event
points to the failing line in the view and includes the GET request.
ProductNotFound
That’s it: unhandled Pyramid view exceptions will now be reported to Bugsink.
The integration runs around Pyramid’s request handling, so your views stay ordinary application code. An unhandled exception includes its Python stack, the application source frame, and the HTTP request that reached the view.
If your application catches an exception itself, report it explicitly with
capture_exception().
