Skip to content

Commit

Permalink
HH-217412 upgrade sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
712u3 committed May 30, 2024
1 parent 1db6bc4 commit 5117838
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
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
2 changes: 1 addition & 1 deletion frontik/integrations/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def initialize_app(self, app: FrontikApplication) -> Optional[Future]:

resource = Resource(
attributes={
ResourceAttributes.SERVICE_NAME: options.app, # type: ignore
ResourceAttributes.SERVICE_NAME: app.app_name, # type: ignore
ResourceAttributes.SERVICE_VERSION: app.application_version(), # type: ignore
ResourceAttributes.HOST_NAME: options.node_name,
ResourceAttributes.CLOUD_REGION: http_client_options.datacenter,
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
2 changes: 1 addition & 1 deletion tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def frontik_app(self) -> FrontikApplication:
return app

async def test_parent_span(self, frontik_app: FrontikApplication) -> None:
await self.fetch_json('/page_a')
await self.fetch('/page_a')
BATCH_SPAN_PROCESSOR[0].force_flush()
assert len(SPAN_STORAGE) == 4
client_a_span = find_span('http.request.cloud.region', 'externalRequest')
Expand Down

0 comments on commit 5117838

Please sign in to comment.