{ "html": "
Edit your mix.exs file to add it as a dependency and add the :sentry
package to your applications:
defp application do\n [applications: [:sentry, :logger]]\nend\n\ndefp deps do\n [{:sentry, "~> 6.0.0"}]\nend\n
Setup the application production environment in your config/prod.exs
config :sentry,\n dsn: "https://public:secret@app.getsentry.com/1",\n environment_name: :prod,\n enable_source_code_context: true,\n root_source_code_path: File.cwd!,\n tags: %{\n env: "production"\n },\n included_environments: [:prod]\n
The environment_name
and included_environments
work together to determine\nif and when Sentry should record exceptions. The environment_name
is the\nname of the current environment. In the example above, we have explicitly set\nthe environment to :prod
which works well if you are inside an environment\nspecific configuration like config/prod.exs
.
An alternative is to use Mix.env
in your general configuration file:
config :sentry, dsn: "https://public:secret@app.getsentry.com/1"\n included_environments: [:prod],\n environment_name: Mix.env\n
This will set the environment name to whatever the current Mix environment\natom is, but it will only send events if the current environment is :prod
,\nsince that is the only entry in the included_environments
key.
You can even rely on more custom determinations of the environment name. It’s\nnot uncommmon for most applications to have a “staging” environment. In order\nto handle this without adding an additional Mix environment, you can set an\nenvironment variable that determines the release level.
\nconfig :sentry, dsn: "https://public:secret@app.getsentry.com/1"\n included_environments: ~w(production staging),\n environment_name: System.get_env("RELEASE_LEVEL") || "development"\n
In this example, we are getting the environment name from the RELEASE_LEVEL
\nenvironment variable. If that variable does not exist, we default to "development"
.\nNow, on our servers, we can set the environment variable appropriately. On\nour local development machines, exceptions will never be sent, because the\ndefault value is not in the list of included_environments
.
If using an environment with Plug or Phoenix add the following to your router:
\nuse Plug.ErrorHandler\nuse Sentry.Plug\n
If you use the error logger and setup Plug/Phoenix then you are already done, all errors will bubble up to\nsentry.
\nOtherwise we provide a simple way to capture exceptions:
\ndo\n ThisWillError.reall()\nrescue\n my_exception ->\n Sentry.capture_exception(my_exception, [stacktrace: System.stacktrace(), extra: %{extra: information}])\nend\n