Skip to content

Commit

Permalink
Add user id to requests, more perf metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikhorluck committed Mar 17, 2024
1 parent 6b36f05 commit 79e2b4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion onlineweb4/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
"django.contrib.messages.middleware.MessageMiddleware",
"reversion.middleware.RevisionMiddleware",
"mozilla_django_oidc.middleware.SessionRefresh",
# add user id
"onlineweb4.settings.sentry.sentry_middleware",
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
Expand Down Expand Up @@ -201,7 +203,6 @@
"apps.approval",
"apps.article",
"apps.authentication",
"apps.autoconfig",
"apps.careeropportunity",
"apps.companyprofile",
"apps.contact",
Expand Down
22 changes: 21 additions & 1 deletion onlineweb4/settings/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@
sentry_sdk.init(
dsn=OW4_SENTRY_DSN,
environment=config("OW4_ENVIRONMENT", default="DEVELOP"),
traces_sample_rate=0.2,
enable_tracing=True,
profiles_sample_rate=0.2,
integrations=[DjangoIntegration(), AwsLambdaIntegration(timeout_warning=True)],
ignore_errors=[ValidationError],
)


def sentry_middleware(get_response):
# One-time configuration and initialization.

def middleware(request):
# Code to be executed for each request before
# the view (and later middleware) are called.
sentry_sdk.set_user(
None if request.user.is_anonymous else {"id": request.user.pk}
)
response = get_response(request)

# Code to be executed for each request/response after
# the view is called.

return response

return middleware

0 comments on commit 79e2b4d

Please sign in to comment.