From the documentation: “Much of the usefulness of Sentry comes from additional context data with the events.”
As a new and non experienced user I wish to get more information on how and where to add the three methods for providing request context.
I am finishing to write a Ruby on Rails application and would like to add Sentry.
Considering that in the getsentry GitHub documentation it is advised to avoid to configure the client in the code, I decided to set the SENTRY_DSN environment variable directly in the production environment, and include the dotenv gem in case I want to try Sentry in development.
Said that, I want to include some request context and I would appreciate some advice.
In the Sentry documentation for Rails, there is an example that implicitly suggests the ideal place to put the code is in a private method inside the application controller, to be called with a before_action filter.
I take for granted that this is the best solution, even though I would like to know if there are other.
Considering that I want to set the SENTRY_DSN environment variable in production from terminal, I would like to enclose the content of the ‘set_raven_context’ method in a if Rails.env.production? conditional. However I would like to consult (if possible) examples of what kind of request context can be provided, in addition to the examples already inserted in the documentation.
Below is what for now I would include in the application controller.
You can notice that I did not add anything to what I found in the documentation, simply because I have at present no idea of what else I can add:
def set_raven_context if Rails.env.production? Raven.user_context(id: current_user.id, name: current_user.name, email: current_user.email, ip_address: request.ip) Raven.tags_context(language: I18n.locale, timezone: current_user.time_zone) end end