Sentry integration for HawkAPI — plugin + middleware
Project description
hawkapi-sentry
Sentry integration for HawkAPI — a plugin that initialises the Sentry SDK on startup and captures unhandled exceptions, plus a middleware that creates a performance transaction per request.
Quickstart
pip install hawkapi-sentry
from hawkapi import HawkAPI
from hawkapi_sentry import SentryPlugin, SentryMiddleware
app = HawkAPI()
app.add_plugin(
SentryPlugin(
dsn="https://key@sentry.io/123",
environment="production",
traces_sample_rate=0.1,
)
)
app.add_middleware(SentryMiddleware)
That's it. Every unhandled exception is captured with full request context; every request gets a Sentry performance transaction.
SentryPlugin parameter reference
| Parameter | Type | Default | Description |
|---|---|---|---|
dsn |
str | None |
None |
Sentry DSN. Empty/None = no-op mode (safe for local dev). |
environment |
str |
"production" |
Sentry environment tag. |
release |
str | None |
None |
Release string. None = not set. |
traces_sample_rate |
float |
0.0 |
Fraction of transactions to sample for performance monitoring. |
profiles_sample_rate |
float |
0.0 |
Fraction of sampled transactions to profile. |
include_user_data |
bool |
False |
When True, attach request.state.user dict to Sentry events. |
user_getter |
Callable[[Request], dict] | None |
None |
Custom callable to extract user data from the request. Takes priority over include_user_data. |
before_send |
Callable | None |
None |
Passed directly to sentry_sdk.init. Return None to drop an event. |
tags |
dict[str, str] | None |
None |
Global tags applied to every captured event. |
ignore_status_codes |
tuple[int, ...] |
(404, 401, 403) |
HTTP status codes for which exceptions are not sent to Sentry. |
Migration from sentry-sdk[fastapi]
| FastAPI / starlette-sentry | hawkapi-sentry |
|---|---|
sentry_sdk.init(integrations=[StarletteIntegration(), FastApiIntegration()]) |
app.add_plugin(SentryPlugin(dsn=...)) |
SentryAsgiMiddleware(app) |
app.add_middleware(SentryMiddleware) |
before_send kwarg to sentry_sdk.init |
SentryPlugin(before_send=...) |
Manual with sentry_sdk.push_scope() as scope: scope.set_user(...) |
SentryPlugin(user_getter=lambda req: {...}) |
The main difference: HawkAPI plugins own the SDK lifecycle, so you never call sentry_sdk.init() yourself — SentryPlugin.on_startup() does it.
Development
# Clone and install in editable mode with dev extras
git clone https://github.com/ashimov/hawkapi-sentry.git
cd hawkapi-sentry
uv sync --extra dev
# Run tests
uv run pytest tests/ -q
# Lint
uv run ruff check .
uv run ruff format .
# Type-check
uv run pyright src/
License
MIT — Copyright (c) 2026 HawkAPI Contributors.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hawkapi_sentry-0.1.1.tar.gz.
File metadata
- Download URL: hawkapi_sentry-0.1.1.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f878bd8c88ccfc44b32f0b225bd08a97c8f86e9391ed36a89fb4d1c344a9b0cf
|
|
| MD5 |
88491c247fd11ab9b3f5e26aa5d7cfbe
|
|
| BLAKE2b-256 |
7a291669aa3ef6d971f334481ae990fb560c536186a841e635c9bc2c60730ac4
|
Provenance
The following attestation bundles were made for hawkapi_sentry-0.1.1.tar.gz:
Publisher:
release.yml on ashimov/hawkapi-sentry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hawkapi_sentry-0.1.1.tar.gz -
Subject digest:
f878bd8c88ccfc44b32f0b225bd08a97c8f86e9391ed36a89fb4d1c344a9b0cf - Sigstore transparency entry: 1340561804
- Sigstore integration time:
-
Permalink:
ashimov/hawkapi-sentry@e2a3c8c236021d8e91f8be9de1938f28c9eccb97 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ashimov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e2a3c8c236021d8e91f8be9de1938f28c9eccb97 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hawkapi_sentry-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hawkapi_sentry-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f5734feb3f34d184e19aefcc0f3bdf2dc6744f2dbc8709971a2ed1c3bd3541
|
|
| MD5 |
79da0b3b0013687dfb9f13a018f5744e
|
|
| BLAKE2b-256 |
d136bb6140340934eecd8b5216503206103335a2047ab2fd9b052797cd9594be
|
Provenance
The following attestation bundles were made for hawkapi_sentry-0.1.1-py3-none-any.whl:
Publisher:
release.yml on ashimov/hawkapi-sentry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hawkapi_sentry-0.1.1-py3-none-any.whl -
Subject digest:
a9f5734feb3f34d184e19aefcc0f3bdf2dc6744f2dbc8709971a2ed1c3bd3541 - Sigstore transparency entry: 1340561806
- Sigstore integration time:
-
Permalink:
ashimov/hawkapi-sentry@e2a3c8c236021d8e91f8be9de1938f28c9eccb97 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ashimov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e2a3c8c236021d8e91f8be9de1938f28c9eccb97 -
Trigger Event:
release
-
Statement type: