asgi: ignore lifespan requests, remove healthcheck events from sentry

This commit is contained in:
Jens Langhammer 2020-09-06 16:51:50 +02:00
parent 219e16f8e5
commit bf4763d946
3 changed files with 8 additions and 3 deletions

View File

@ -5,7 +5,6 @@ import structlog
bind = "0.0.0.0:8000" bind = "0.0.0.0:8000"
workers = multiprocessing.cpu_count() * 2 + 1 workers = multiprocessing.cpu_count() * 2 + 1
workers = 1
user = "passbook" user = "passbook"
group = "passbook" group = "passbook"

View File

@ -4,6 +4,7 @@ from botocore.client import ClientError
from django.core.exceptions import DisallowedHost, ValidationError from django.core.exceptions import DisallowedHost, ValidationError
from django.db import InternalError, OperationalError, ProgrammingError from django.db import InternalError, OperationalError, ProgrammingError
from django_redis.exceptions import ConnectionInterrupted from django_redis.exceptions import ConnectionInterrupted
from redis.exceptions import ConnectionError as RedisConnectionError
from redis.exceptions import RedisError from redis.exceptions import RedisError
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from structlog import get_logger from structlog import get_logger
@ -24,6 +25,7 @@ def before_send(event, hint):
ConnectionInterrupted, ConnectionInterrupted,
APIException, APIException,
ConnectionResetError, ConnectionResetError,
RedisConnectionError,
WorkerLostError, WorkerLostError,
DisallowedHost, DisallowedHost,
ConnectionResetError, ConnectionResetError,

View File

@ -76,6 +76,10 @@ class ASGILogger:
return return
self.start = time() self.start = time()
if scope["type"] == "lifespan":
# https://code.djangoproject.com/ticket/31508
# https://github.com/encode/uvicorn/issues/266
return
await self.app(scope, receive, self.send_hooked) await self.app(scope, receive, self.send_hooked)
async def send_hooked(self, message: Message) -> None: async def send_hooked(self, message: Message) -> None:
@ -115,6 +119,6 @@ class ASGILogger:
) )
application = SentryAsgiMiddleware( application = ASGILogger(
ASGILogger(guarantee_single_callable(get_default_application())) guarantee_single_callable(SentryAsgiMiddleware(get_default_application()))
) )