Skip to content

Commit

Permalink
🔊 Add initial Sentry integration
Browse files Browse the repository at this point in the history
Ref: #11
  • Loading branch information
webknjaz committed Sep 20, 2020
1 parent 45a0e3d commit e741fb9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions octomachinery/github/api/app_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aiohttp.client import ClientSession
from aiohttp.client_exceptions import ClientConnectorError
import attr
import sentry_sdk

# pylint: disable=relative-beyond-top-level
from ...routing import WEBHOOK_EVENTS_ROUTER
Expand Down Expand Up @@ -50,6 +51,14 @@ class GitHubApp:
converter=frozenset,
)

def __attrs_post_init__(self) -> None: # pylint: disable=no-self-use
"""Initialize the Sentry SDK library."""
# NOTE: Under the hood, it will set up the DSN from `SENTRY_DSN`
# NOTE: env var. We don't need to care about it not existing as
# NOTE: Sentry SDK helpers don't fail loudly and if not
# NOTE: configured, it'll be ignored.
sentry_sdk.init()

async def dispatch_event(self, github_event: GitHubEvent) -> Iterable[Any]:
"""Dispatch ``github_event`` into the embedded routers."""
return await github_event.dispatch_via(
Expand Down
7 changes: 7 additions & 0 deletions octomachinery/routing/webhooks_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging

from anyio import get_cancelled_exc_class, sleep as async_sleep
import sentry_sdk

# pylint: disable=relative-beyond-top-level,import-error
from ..runtime.context import RUNTIME_CONTEXT
Expand Down Expand Up @@ -88,6 +89,12 @@ async def route_github_event(
except get_cancelled_exc_class():
raise
except Exception as exc: # pylint: disable=broad-except
# NOTE: It's probably better to wrap each event handler with
# NOTE: try/except and call `capture_exception()` there instead.
# NOTE: We'll also need to figure out the magic of associating
# NOTE: breadcrumbs with event handlers.
sentry_sdk.capture_exception(exc)

# NOTE: Framework-wise, these exceptions are meaningless because they
# NOTE: can be anything random that the webhook author (octomachinery
# NOTE: end-user) forgot to handle. There's nothing we can do about
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ install_requires =
gidgethub
pyjwt[crypto]
pyyaml
sentry_sdk
setuptools_scm

[options.packages.find]
Expand Down

0 comments on commit e741fb9

Please sign in to comment.