fix: tweak sentry config

- disable session tracking - This causes sentry to phone home on every load, we don't need this (yet)
- disable automatic integrtaions (like redis)
- disable all default integration and cherry-pick what's required
This commit is contained in:
Ankush Menat 2023-11-30 17:44:51 +05:30
parent 52686f79cb
commit 0e8b4de96f
3 changed files with 25 additions and 1 deletions

View file

@ -62,10 +62,28 @@ if _dev_server:
# Always initialize sentry SDK if the DSN is sent
if sentry_dsn := os.getenv("FRAPPE_SENTRY_DSN"):
import sentry_sdk
from sentry_sdk.integrations.argv import ArgvIntegration
from sentry_sdk.integrations.atexit import AtexitIntegration
from sentry_sdk.integrations.dedupe import DedupeIntegration
from sentry_sdk.integrations.excepthook import ExcepthookIntegration
from sentry_sdk.integrations.modules import ModulesIntegration
from frappe.utils.sentry import before_send
sentry_sdk.init(dsn=sentry_dsn, before_send=before_send, release=__version__)
sentry_sdk.init(
dsn=sentry_dsn,
before_send=before_send,
release=__version__,
auto_enabling_integrations=False,
default_integrations=False,
integrations=[
AtexitIntegration(),
ExcepthookIntegration(),
DedupeIntegration(),
ModulesIntegration(),
ArgvIntegration(),
],
)
class _dict(dict):

View file

@ -3,4 +3,9 @@ import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: frappe.boot.sentry_dsn,
release: frappe?.boot?.versions?.frappe,
autoSessionTracking: false,
initialScope: {
// don't use frappe.session.user, it's set much later and will fail because of async loading
user: { id: frappe.boot.user.name ?? "Unidentified" },
},
});

View file

@ -41,6 +41,7 @@ def capture_exception(
evt_processor = _make_wsgi_event_processor(frappe.request.environ, False)
scope.add_event_processor(evt_processor)
scope.set_tag("site", frappe.local.site)
scope.set_tag("user", getattr(frappe.session, "user", "Unidentified"))
# Extract `X-Frappe-Request-ID` to store as a separate field if its present
if trace_id := frappe.monitor.get_trace_id():