Skip to main content

Sentry integration for HawkAPI — plugin + middleware

Project description

hawkapi-sentry

PyPI Python License CI Downloads

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hawkapi_sentry-0.2.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

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

hawkapi_sentry-0.2.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file hawkapi_sentry-0.2.0.tar.gz.

File metadata

  • Download URL: hawkapi_sentry-0.2.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_sentry-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6f9bc9b8b88774e7436e16d7a4cf5fca2d596b7d835dc6fa4b00f3e7c279cac4
MD5 d32693c2c51a47566765bc36e933a720
BLAKE2b-256 9a0f0fc2a862331c527833c2c1a7f895c16e38c27f03e507c1e5767a7d4deed6

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_sentry-0.2.0.tar.gz:

Publisher: release.yml on ashimov/hawkapi-sentry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hawkapi_sentry-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: hawkapi_sentry-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hawkapi_sentry-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f188bd696ad613806702fcbbdba746b299056f6d5ab0fd1eb2fab154b0b943c0
MD5 57e7e72f7a4af0598ce7d3b3bf35a752
BLAKE2b-256 6d7a6542a8931ec675e117f0f455e1fea9c985d6f945e3d3c11931cb9274a99b

See more details on using hashes here.

Provenance

The following attestation bundles were made for hawkapi_sentry-0.2.0-py3-none-any.whl:

Publisher: release.yml on ashimov/hawkapi-sentry

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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