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

Sentry setup configuration changes #494

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions chatbot_ner/setup_sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
SENTRY_DSN = os.environ.get('SENTRY_DSN')
_sentry_enabled = (os.environ.get('SENTRY_ENABLED') or '').strip().lower()
SENTRY_ENABLED = (_sentry_enabled == 'true' and 'test' not in sys.argv)
SENTRY_SAMPLE_RATE = os.environ.get('SENTRY_SAMPLE_RATE', 0.1)


def setup_sentry():
Expand All @@ -19,19 +20,28 @@ def setup_sentry():
"""
if SENTRY_ENABLED:
import sentry_sdk
import logging
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.integrations.excepthook import ExcepthookIntegration

def before_sentry_send(event, hint):
if event.get('logger', None) == 'elasticapm.transport':
return None
event.setdefault("tags", {})["cas_name"] = CLIENT_APPLICATIONS_SETUP_NAME
return event

sentry_logging = LoggingIntegration(
level=logging.INFO,
event_level=logging.ERROR
)
sentry_exception = ExcepthookIntegration(
always_run=True
)
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration(), LoggingIntegration()],
integrations=[DjangoIntegration(), sentry_logging, sentry_exception],
environment=ENVIRONMENT,
sample_rate=0.1,
sample_rate=float(SENTRY_SAMPLE_RATE),
before_send=before_sentry_send
)