Skip to content

Commit

Permalink
Merge pull request #159 from uktrade/feature/add-sentry-sample-rate
Browse files Browse the repository at this point in the history
update:Sentry configuration and improve security
  • Loading branch information
hareshkainthdbt authored Jan 14, 2025
2 parents a2393f4 + ab9a600 commit 6cac8a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ webpack-stats.json

# Other
.DS_Store
/key.pem
19 changes: 6 additions & 13 deletions fbr/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@
)

# Only init sentry if the SENTRY_DSN is provided
# TODO: add SENTRY_TRACES_SAMPLE_RATE to secrets default value of 0.0
# Sentry set up:
SENTRY_DSN = os.environ.get("SENTRY_DSN", None)
if SENTRY_DSN:
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[DjangoIntegration()])
sentry_sdk.init(
dsn=SENTRY_DSN,
integrations=[DjangoIntegration()],
traces_sample_rate=env("SENTRY_TRACES_SAMPLE_RATE", default=1.0),
)
logging.getLogger(__name__).info("SENTRY_DSN set. Sentry is enabled.")
else:
logging.getLogger(__name__).info("SENTRY_DSN not set. Sentry is disabled.")
Expand Down Expand Up @@ -286,18 +291,6 @@
},
}

if SENTRY_DSN:
logging.getLogger(__name__).info("added sentry to logging config")
LOGGING["loggers"]["sentry_sdk"] = {
"level": "ERROR",
"handlers": ["asim"],
"propagate": False,
}
else:
logging.getLogger(__name__).info(
"sentry not enabled. skipping sentry logging config"
)

# Django Log Formatter ASIM settings
# See https://github.com/uktrade/django-log-formatter-asim#settings
DLFA_TRACE_HEADERS = ("X-B3-TraceId", "X-B3-SpanId")
Expand Down

0 comments on commit 6cac8a1

Please sign in to comment.