Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HH-217412 upgrade sentry #707

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion frontik/integrations/sentry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Optional
import logging

import sentry_sdk
from sentry_sdk.integrations.fastapi import FastApiIntegration, StarletteIntegration
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.atexit import AtexitIntegration
from sentry_sdk.integrations.dedupe import DedupeIntegration
from sentry_sdk.integrations.stdlib import StdlibIntegration
from sentry_sdk.integrations.excepthook import ExcepthookIntegration
from sentry_sdk.integrations.modules import ModulesIntegration
from sentry_sdk.integrations.logging import LoggingIntegration

from frontik.integrations import Integration, integrations_logger
from frontik.options import options
Expand All @@ -25,7 +33,21 @@ def initialize_app(self, app: FrontikApplication) -> Optional[Future]:
max_breadcrumbs=options.sentry_max_breadcrumbs,
default_integrations=False,
auto_enabling_integrations=False,
integrations=[FastApiIntegration(), StarletteIntegration()],
integrations=[
AioHttpIntegration(),
FastApiIntegration(),
StarletteIntegration(),
AtexitIntegration(),
DedupeIntegration(),
ExcepthookIntegration(),
ModulesIntegration(),
StdlibIntegration(),
LoggingIntegration(level=None, event_level=logging.WARNING),
],
sample_rate=options.sentry_sample_rate,
enable_tracing=options.sentry_enable_tracing,
traces_sample_rate=options.sentry_traces_sample_rate,
in_app_include=list(filter(None, options.sentry_in_app_include.split(','))),
)

return None
Expand Down
4 changes: 4 additions & 0 deletions frontik/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class Options:

sentry_dsn: Optional[str] = None
sentry_max_breadcrumbs: int = 0
sentry_sample_rate: float = 1.0
sentry_enable_tracing: Optional[bool] = None
sentry_traces_sample_rate: Optional[float] = None
sentry_in_app_include: str = ''

send_timeout_stats_interval_ms: int = 60000

Expand Down
4 changes: 2 additions & 2 deletions tests/test_sentry_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize_sentry_logger(self):


@router.get('/sentry_error', cls=Page)
async def get_page(handler=get_current_handler()):
async def get_page(handler: Page = get_current_handler()):
ip = handler.get_query_argument('ip', None)
extra = handler.get_query_argument('extra_key', None)
a = 155
Expand Down Expand Up @@ -59,7 +59,7 @@ async def test_sentry_exception(self):
assert len(sentry_events) == 1
event = sentry_events[0]
assert len(event['breadcrumbs']['values']) == 0
assert event.get('modules') is None
assert event.get('modules') is not None
assert event['request']['query_string'] == 'ip=127.0.0.77&extra_key=extra_val'
assert event['user']['real_ip'] == '127.0.0.77'
assert event['extra']['extra_key'] == 'extra_val'
Expand Down
Loading