mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-08-09 06:24:52 +03:00
change sentry integration to use new sentry sdk unified
This commit is contained in:
parent
3af5333bbb
commit
35f63d0e0a
|
@ -45,7 +45,6 @@ DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a
|
|||
DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error
|
||||
DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error
|
||||
SENTRY_DSN SENTRY_DSN n/a raises error
|
||||
DJANGO_SENTRY_CLIENT SENTRY_CLIENT n/a raven.contrib.django.raven_compat.DjangoClient
|
||||
DJANGO_SENTRY_LOG_LEVEL SENTRY_LOG_LEVEL n/a logging.INFO
|
||||
MAILGUN_API_KEY MAILGUN_ACCESS_KEY n/a raises error
|
||||
MAILGUN_DOMAIN MAILGUN_SENDER_DOMAIN n/a raises error
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
{% if cookiecutter.use_sentry == 'y' -%}
|
||||
import logging
|
||||
|
||||
import sentry_sdk
|
||||
|
||||
from sentry_sdk.integrations.django import DjangoIntegration
|
||||
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||
|
||||
{% endif -%}
|
||||
from .base import * # noqa
|
||||
from .base import env
|
||||
|
@ -196,60 +201,17 @@ MIDDLEWARE = ['raven.contrib.django.raven_compat.middleware.SentryResponseErrorI
|
|||
# Sentry
|
||||
# ------------------------------------------------------------------------------
|
||||
SENTRY_DSN = env('SENTRY_DSN')
|
||||
SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient')
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
'root': {
|
||||
'level': 'WARNING',
|
||||
'handlers': ['sentry'],
|
||||
},
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '%(levelname)s %(asctime)s %(module)s '
|
||||
'%(process)d %(thread)d %(message)s'
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'sentry': {
|
||||
'level': 'ERROR',
|
||||
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
|
||||
},
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.db.backends': {
|
||||
'level': 'ERROR',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'raven': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'sentry.errors': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'django.security.DisallowedHost': {
|
||||
'level': 'ERROR',
|
||||
'handlers': ['console', 'sentry'],
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
|
||||
RAVEN_CONFIG = {
|
||||
'dsn': SENTRY_DSN
|
||||
}
|
||||
|
||||
sentry_logging = LoggingIntegration(
|
||||
level=SENTRY_CELERY_LOGLEVEL, # Capture info and above as breadcrumbs
|
||||
event_level=None # Send no events from log messages
|
||||
)
|
||||
|
||||
sentry_sdk.init(
|
||||
dsn="SENTRY_DSN",
|
||||
integrations=[sentry_logging, DjangoIntegration()]
|
||||
)
|
||||
{%- else %}
|
||||
# LOGGING
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
{% if cookiecutter.use_celery == 'y' %}
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||
|
||||
from django.apps import apps, AppConfig
|
||||
from django.conf import settings
|
||||
|
||||
|
@ -26,9 +30,6 @@ class CeleryAppConfig(AppConfig):
|
|||
installed_apps = [app_config.name for app_config in apps.get_app_configs()]
|
||||
app.autodiscover_tasks(lambda: installed_apps, force=True)
|
||||
|
||||
{% if cookiecutter.use_sentry == 'y' -%}
|
||||
if hasattr(settings, 'RAVEN_CONFIG'):
|
||||
# Celery signal registration
|
||||
{% if cookiecutter.use_pycharm == 'y' -%}
|
||||
# Since raven is required in production only,
|
||||
# imports might (most surely will) be wiped out
|
||||
|
@ -36,16 +37,16 @@ class CeleryAppConfig(AppConfig):
|
|||
# in other environments.
|
||||
# @formatter:off
|
||||
{%- endif %}
|
||||
from raven import Client as RavenClient
|
||||
from raven.contrib.celery import register_signal as raven_register_signal
|
||||
from raven.contrib.celery import register_logger_signal as raven_register_logger_signal
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.celery import CeleryIntegration
|
||||
{% if cookiecutter.use_pycharm == 'y' -%}
|
||||
# @formatter:on
|
||||
{%- endif %}
|
||||
|
||||
raven_client = RavenClient(dsn=settings.RAVEN_CONFIG['dsn'])
|
||||
raven_register_logger_signal(raven_client)
|
||||
raven_register_signal(raven_client)
|
||||
sentry_logging = LoggingIntegration(
|
||||
level=settings.SENTRY_CELERY_LOGLEVEL, # Capture info and above as breadcrumbs
|
||||
event_level=None # Send no events from log messages
|
||||
)
|
||||
sentry_sdk.init(dsn=settings.SENTRY_DSN, integrations=[sentry_logging, CeleryIntegration()])
|
||||
{%- endif %}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user