Skip to content

Commit

Permalink
Log sentry event IDs in lograge
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Sep 17, 2023
1 parent 07050f9 commit 25a98c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
34 changes: 19 additions & 15 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,29 @@ def store_region_on_thread
extra[:fingerprint] = [error.original_exception.class.name, *trace]
end
ensure
e = Sentry.capture_exception(error, extra)
puts Oj.dump({ event_id: e.event_id })
@sentry_event = Sentry.capture_exception(error, **extra)
end
end

before_action :tag_sentry_context
before_action :tag_sentry_context

def tag_sentry_context
user = current_user&.resource_owner
Sentry.set_user(
id: user&.id,
name: user&.name,
ip_address: request.remote_ip
def tag_sentry_context
user = current_user&.resource_owner
Sentry.set_user(
id: user&.id,
name: user&.name,
ip_address: request.remote_ip
)
Sentry.configure_scope do |scope|
scope.set_context(
'feature flags',
Flipper.preload_all.to_h { |f| [f.name, f.enabled?(user)] }
)
Sentry.configure_scope do |scope|
scope.set_context(
'feature flags',
Flipper.preload_all.to_h { |f| [f.name, f.enabled?(user)] }
)
end
end
end

def append_info_to_payload(payload)
super
payload[:sentry_event] = @sentry_event
end
end
5 changes: 3 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class Application < Rails::Application
config.lograge.custom_options = ->(event) do
{
params: event.payload[:request].query_parameters,
request_id: event.payload[:headers]['action_dispatch.request_id']
}
request_id: event.payload[:headers]['action_dispatch.request_id'],
sentry_event_id: event.payload[:sentry_event]&.event_id
}.compact
end

# Normally we wanna be API-only, but we mount some admin panels in, so... :(
Expand Down

0 comments on commit 25a98c8

Please sign in to comment.