Skip to content

Commit

Permalink
Merge pull request #157 from uktrade/feature/sentry-setup
Browse files Browse the repository at this point in the history
chore: Improve Sentry SDK initialization and logging
  • Loading branch information
hareshkainthdbt authored Jan 13, 2025
2 parents 09dafcc + d1edcde commit 490231c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions fbr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
configured deployments.
"""

import logging
import os

from pathlib import Path
from typing import Any

import dj_database_url
import environ
import sentry_sdk

from dbt_copilot_python.database import database_url_from_env
from django_log_formatter_asim import ASIMFormatter
from sentry_sdk.integrations.django import DjangoIntegration

# Define the root directory (i.e. <repo-root>)
root = environ.Path(__file__) - 4 # i.e. Repository root
Expand All @@ -44,15 +47,12 @@
)

# Only init sentry if the SENTRY_DSN is provided
if os.environ.get("SENTRY_DSN"):
import sentry_sdk

from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
os.environ.get("SENTRY_DSN"),
integrations=[DjangoIntegration()],
)
# Sentry set up:
SENTRY_DSN = os.environ.get("SENTRY_DSN", None)
if SENTRY_DSN:
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()])
else:
logging.getLogger(__name__).info("SENTRY_DSN not set. Sentry is disabled.")

DEBUG = env("DEBUG", default=False)

Expand Down Expand Up @@ -285,7 +285,8 @@
},
}

if os.environ.get("SENTRY_DSN"):
if SENTRY_DSN:
logging.getLogger(__name__).info("added sentry to logging config")
LOGGING["loggers"]["sentry_sdk"] = {
"level": "ERROR",
"handlers": ["asim"],
Expand Down

0 comments on commit 490231c

Please sign in to comment.