From 2059b770041fe80bae00cf93e5493f58222bb5ee Mon Sep 17 00:00:00 2001 From: Nikolas Nyby Date: Fri, 11 Oct 2024 16:31:04 -0400 Subject: [PATCH] sentry-js: Wait for onLoad before using Sentry.setUser() It looks like we need to wait for Sentry.onLoad to happen before calling this method, based on these docs: https://docs.sentry.io/platforms/javascript/install/loader/#guarding-sdk-function-calls --- CHANGES.txt | 4 ++++ .../templates/ctlsettings/sentry_js.html | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index fb97446..4acf480 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,7 @@ +0.4.2 +==================== +* Updated sentry-js config to use Sentry.onLoad. + 0.4.1 (2024-10-11) ==================== * Updated sentry JS config to use username instead of id. diff --git a/ctlsettings/templates/ctlsettings/sentry_js.html b/ctlsettings/templates/ctlsettings/sentry_js.html index c92e469..5699037 100644 --- a/ctlsettings/templates/ctlsettings/sentry_js.html +++ b/ctlsettings/templates/ctlsettings/sentry_js.html @@ -6,17 +6,21 @@ environment: '{{ ENVIRONMENT }}' }); - {% if request.user.is_anonymous %} - Sentry.setUser({ - email: 'none', - username: 'anonymous' - }); - {% else %} - Sentry.setUser({ - email: '{{ request.user.email }}', - username: '{{ request.user.username }}' + Sentry.onLoad(function() { + const client = Sentry.getClient(); + + {% if request.user.is_anonymous %} + client.setUser({ + email: 'none', + username: 'anonymous' + }); + {% else %} + client.setUser({ + email: '{{ request.user.email }}', + username: '{{ request.user.username }}' + }); + {% endif %} }); - {% endif %} };