Skip to content

Commit 6ff51c3

Browse files
committed
sentry context, traces
1 parent 55546fc commit 6ff51c3

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

app/controllers/application_controller.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class ApplicationController < ActionController::Base
22
before_action :set_locale
3+
before_action :populate_sentry_scope
34

45
private
56

@@ -59,4 +60,46 @@ def require_sponsorship_session
5960
redirect_to new_user_session_path(back_to: url_for(params.to_unsafe_h.merge(only_path: true)))
6061
end
6162
end
63+
64+
def populate_sentry_scope
65+
Sentry.configure_scope do |scope|
66+
if current_staff
67+
scope.set_context(
68+
'sponsor-app.staff',
69+
{
70+
id: current_staff.id,
71+
login: current_staff.login,
72+
}
73+
)
74+
end
75+
76+
if current_sponsorship
77+
scope.set_context(
78+
'sponsor-app.sponsor',
79+
{
80+
id: current_sponsorship.id,
81+
name: current_sponsorship.name,
82+
}
83+
)
84+
end
85+
86+
if current_conference
87+
scope.set_context(
88+
'sponsor-app.conference',
89+
{
90+
id: current_conference.id,
91+
slug: current_conference.slug,
92+
}
93+
)
94+
end
95+
96+
case
97+
when current_staff
98+
Sentry.set_user(id: "staff_#{current_staff.id}", username: current_staff.login)
99+
when current_sponsorship
100+
email = session[:email] ||= current_sponsorship.contact&.email
101+
Sentry.set_user(id: "#{current_sponsorship.id}", email: )
102+
end
103+
end
104+
end
62105
end

app/javascript/raven.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as Sentry from "@sentry/browser";
22

33
if (window.SENTRY_DSN) {
4-
Sentry.init({ dsn: window.SENTRY_DSN });
4+
Sentry.init({
5+
dsn: window.SENTRY_DSN,
6+
release: window.APP_VERSION,
7+
tracesSampleRate: 0.2,
8+
});
59
}

config/initializers/sentry.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
Sentry.init do |config|
22
config.dsn = ENV['SENTRY_DSN']
33
config.background_worker_threads = 0 if ENV['AWS_LAMBDA_FUNCTION_NAME']
4+
5+
config.traces_sample_rate = 0.25
6+
config.enable_logs = true
7+
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
48
end

0 commit comments

Comments
 (0)