Skip to content

Commit

Permalink
sentry-js: Wait for onLoad before using Sentry.setUser()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikolas committed Oct 11, 2024
1 parent e7b3a6d commit 2059b77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 14 additions & 10 deletions ctlsettings/templates/ctlsettings/sentry_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
};
</script>

Expand Down

0 comments on commit 2059b77

Please sign in to comment.