Skip to main content

Sending events to sentry

Simply setting up sentry and ensuring it can receive errors is not enough.

We want to ensure we enrich each event (be it capture_message or capture_exception)

These are the important data enrichment we want to have with Sentry.

Structured Context

We will provide the following to Sentry:

  • CurrentRequest
  • Endpoint Request (e.g. IndexRequest)

Structured Context: CurrentRequest

Provides the details of the current logged in user.

{
identities_user_id: CurrentRequest.identities_user&.id,
org_user_profile_id: CurrentRequest.org_user_profile&.id,
org_company_id: CurrentRequest.org_company&.id,
careers_user_profile_id: CurrentRequest.careers_user_profile&.id,
uuid: CurrentRequest.uuid,
remote_ip: CurrentRequest.remote_ip,
user_agent: CurrentRequest.user_agent
}

Endpoint Request

Each endpoint has request.

We will convert the request object into a json, and then parse it into a hash.

The manages will always pass the endpoint request to the Error class

# index_manager.rb

if validator.invalid?
raise Errors::UnprocessableContentError.new(
title: 'There was an error when getting your job applications',
messages: validator.errors.messages,
request: JSON.parse(request.to_json(), symbolize_names: true) # passing the request to the error object
)
end

Specifically this line JSON.parse(request.to_json(), symbolize_names: true)

Tags

We want to be able to search for errors in Sentry UI. In order to do this, we need to set tags to the Sentry context.

tagsexample valuedescription
domaincareers/jobs/career_usersprovide the path equivalent of the rails namespace

You can search for errors in your domain by searching in Sentry UI domain:careers/jobs/careers_users