Skip to content

Commit

Permalink
Configure user with initialScope
Browse files Browse the repository at this point in the history
Based on the docs here:
https://docs.sentry.io/platforms/javascript/configuration/options/#initial-scope

My Sentry.onLoad and client.setUser setup doesn't seem to be working,
and I don't think this is how things are intended to be used in Sentry.
  • Loading branch information
nikolas committed Oct 16, 2024
1 parent fb2d78b commit 4e2fb6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.4.3
====================
* Updated sentry-js config again to be more failsafe, and also
configure user data in initialScope on initialization.

0.4.2 (2024-10-14)
====================
* Updated sentry-js config to use Sentry.onLoad.
Expand Down
29 changes: 14 additions & 15 deletions ctlsettings/templates/ctlsettings/sentry_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
<script>
window.sentryOnLoad = function() {
Sentry.init({
environment: '{{ ENVIRONMENT }}'
});

Sentry.onLoad(function() {
const client = Sentry.getClient();
environment: '{{ ENVIRONMENT }}',

{% if request.user.is_anonymous %}
client.setUser({
email: 'none',
username: 'anonymous'
});
{% else %}
client.setUser({
email: '{{ request.user.email }}',
username: '{{ request.user.username }}'
});
{% if request and request.user %}
initialScope: {
user: {
{% if request.user.is_anonymous %}
email: 'none',
username: 'anonymous'
{% else %}
email: '{{ request.user.email }}',
username: '{{ request.user.username }}'
{% endif %}
}
}
{% endif %}

});
};
</script>
Expand Down

0 comments on commit 4e2fb6b

Please sign in to comment.