Skip to content

Commit

Permalink
ref(admin): Set the user email in Sentry (#4431)
Browse files Browse the repository at this point in the history
Add the logged in user's email to any Sentry errors/tracing etc.
  • Loading branch information
evanh committed Jun 28, 2023
1 parent 71ffe9d commit 2c75855
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions snuba/admin/static/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ client.getSettings().then((settings) => {
replaysSessionSampleRate: settings.replaysSessionSampleRate,
replaysOnErrorSampleRate: settings.replaysOnErrorSampleRate,
});
Sentry.setUser({ email: settings.userEmail });
}
});

Expand Down
1 change: 1 addition & 0 deletions snuba/admin/static/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Settings = {
tracesSampleRate: number;
replaysSessionSampleRate: number;
replaysOnErrorSampleRate: number;
userEmail: string;
};

export { AllowedTools, Settings };
6 changes: 5 additions & 1 deletion snuba/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import asdict
from typing import Any, List, Mapping, Optional, Sequence, Tuple, cast

import sentry_sdk
import simplejson as json
import structlog
from flask import Flask, Response, g, jsonify, make_response, request
Expand Down Expand Up @@ -96,7 +97,9 @@ def authorize() -> None:
if request.endpoint != "health":
user = authorize_request()
logger.info("authorize.finished", user=user)
g.user = user
with sentry_sdk.push_scope() as scope:
scope.user = {"email": user.email}
g.user = user


@application.route("/")
Expand All @@ -123,6 +126,7 @@ def settings_endpoint() -> Response:
"tracesSampleRate": settings.ADMIN_TRACE_SAMPLE_RATE,
"replaysSessionSampleRate": settings.ADMIN_REPLAYS_SAMPLE_RATE,
"replaysOnErrorSampleRate": settings.ADMIN_REPLAYS_SAMPLE_RATE_ON_ERROR,
"userEmail": g.user.email,
}
),
200,
Expand Down

0 comments on commit 2c75855

Please sign in to comment.