Sentry should send environment information
This commit is contained in:
parent
697eefc7a0
commit
b9be186d2c
6 changed files with 16 additions and 19 deletions
|
@ -118,16 +118,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_raven_context
|
def set_raven_context
|
||||||
user = logged_user
|
Raven.user_context(sentry_user)
|
||||||
|
|
||||||
context = {
|
|
||||||
ip_address: request.ip,
|
|
||||||
id: user&.id,
|
|
||||||
email: user&.email,
|
|
||||||
roles: logged_user_roles
|
|
||||||
}.compact
|
|
||||||
|
|
||||||
Raven.user_context(context)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_info_to_payload(payload)
|
def append_info_to_payload(payload)
|
||||||
|
@ -202,16 +193,19 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sentry_user
|
||||||
|
user = logged_user
|
||||||
|
{ id: user&.id, role: user&.class&.name || 'Guest' }.compact
|
||||||
|
end
|
||||||
|
|
||||||
def sentry_config
|
def sentry_config
|
||||||
sentry = Rails.application.secrets.sentry
|
sentry = Rails.application.secrets.sentry
|
||||||
|
|
||||||
{
|
{
|
||||||
key: sentry[:client_key],
|
key: sentry[:client_key],
|
||||||
enabled: sentry[:enabled],
|
enabled: sentry[:enabled],
|
||||||
user: {
|
environment: sentry[:environment],
|
||||||
id: current_user&.id,
|
user: sentry_user
|
||||||
email: current_email
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import * as Sentry from '@sentry/browser';
|
import * as Sentry from '@sentry/browser';
|
||||||
|
|
||||||
const { key, enabled, user } = gon.sentry || {};
|
const { key, enabled, user, environment } = gon.sentry || {};
|
||||||
|
|
||||||
// We need to check for key presence here as we do not have a dsn for browser yet
|
// We need to check for key presence here as we do not have a dsn for browser yet
|
||||||
if (enabled && key) {
|
if (enabled && key) {
|
||||||
Sentry.init({ dsn: key });
|
Sentry.init({ dsn: key, environment });
|
||||||
|
|
||||||
if (user.email) {
|
if (user.email) {
|
||||||
Sentry.configureScope(scope => {
|
Sentry.configureScope(scope => {
|
||||||
|
|
|
@ -38,6 +38,7 @@ HELPSCOUT_CLIENT_SECRET=""
|
||||||
HELPSCOUT_WEBHOOK_SECRET=""
|
HELPSCOUT_WEBHOOK_SECRET=""
|
||||||
|
|
||||||
SENTRY_ENABLED="disabled"
|
SENTRY_ENABLED="disabled"
|
||||||
|
SENTRY_CURRENT_ENV="development"
|
||||||
SENTRY_DSN_RAILS=""
|
SENTRY_DSN_RAILS=""
|
||||||
SENTRY_DSN_JS=""
|
SENTRY_DSN_JS=""
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,6 @@ if ENV['SENTRY_ENABLED'] == 'enabled'
|
||||||
|
|
||||||
Raven.configure do |config|
|
Raven.configure do |config|
|
||||||
config.dsn = ENV['SENTRY_DSN_RAILS']
|
config.dsn = ENV['SENTRY_DSN_RAILS']
|
||||||
|
config.environments = ['production', 'staging']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,7 @@ defaults: &defaults
|
||||||
sentry:
|
sentry:
|
||||||
enabled: <%= ENV['SENTRY_ENABLED'] == 'enabled' %>
|
enabled: <%= ENV['SENTRY_ENABLED'] == 'enabled' %>
|
||||||
client_key: <%= ENV['SENTRY_DSN_JS'] %>
|
client_key: <%= ENV['SENTRY_DSN_JS'] %>
|
||||||
|
environment: <%= ENV['SENTRY_CURRENT_ENV'] %>
|
||||||
|
|
||||||
development:
|
development:
|
||||||
<<: *defaults
|
<<: *defaults
|
||||||
|
|
|
@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do
|
||||||
context 'when no one is logged in' do
|
context 'when no one is logged in' do
|
||||||
it do
|
it do
|
||||||
expect(Raven).to have_received(:user_context)
|
expect(Raven).to have_received(:user_context)
|
||||||
.with({ ip_address: '0.0.0.0', roles: 'Guest' })
|
.with({ role: 'Guest' })
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
|
@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do
|
||||||
|
|
||||||
it do
|
it do
|
||||||
expect(Raven).to have_received(:user_context)
|
expect(Raven).to have_received(:user_context)
|
||||||
.with({ ip_address: '0.0.0.0', email: current_user.email, id: current_user.id, roles: 'User' })
|
.with({ id: current_user.id, role: 'User' })
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
|
@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do
|
||||||
|
|
||||||
it do
|
it do
|
||||||
expect(Raven).to have_received(:user_context)
|
expect(Raven).to have_received(:user_context)
|
||||||
.with({ ip_address: '0.0.0.0', email: current_user.email, id: current_user.id, roles: 'User, Gestionnaire, Administrateur, Administration' })
|
.with({ id: current_user.id, role: 'User' })
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
|
|
Loading…
Reference in a new issue