Skip to content

Commit

Permalink
add rich user info to sentry events
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 29, 2024
1 parent d675248 commit e168d7d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,37 @@ def get_tab_url(self, tab: str) -> str:
)

def setup_sentry(self, event_processor: typing.Callable = None):
def add_user_to_event(event, hint):
user = self.request and self.request.user
if not user:
return event
event["user"] = {
"id": user.id,
"name": user.display_name,
"email": user.email,
"data": {
field: getattr(user, field)
for field in [
"uid",
"phone_number",
"photo_url",
"balance",
"is_paying",
"is_anonymous",
"is_disabled",
"disable_safety_checker",
"created_at",
]
},
}
return event

with sentry_sdk.configure_scope() as scope:
scope.set_extra("base_url", self.app_url())
scope.set_transaction_name(
"/" + self.slug_versions[0], source=TRANSACTION_SOURCE_ROUTE
)
scope.add_event_processor(add_user_to_event)
if event_processor:
scope.add_event_processor(event_processor)

Expand Down

0 comments on commit e168d7d

Please sign in to comment.