Skip to content

Commit

Permalink
Merge pull request #44 from ccnmtl/sentry-fix
Browse files Browse the repository at this point in the history
sentry-js: Wait for onLoad before using Sentry.setUser()
  • Loading branch information
ndittren authored Oct 12, 2024
2 parents e7b3a6d + 2059b77 commit 5706e7b
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 5706e7b

Please sign in to comment.