{ "html": "
\n

Installation

\n

Edit your mix.exs file to add it as a dependency and add the :sentry package to your applications:

\n
defp application do\n [applications: [:sentry, :logger]]\nend\n\ndefp deps do\n  [{:sentry, "~> 6.0.0"}]\nend\n
\n
\n
\n\n\n
\n

Configuration

\n

Setup the application production environment in your config/prod.exs

\n
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
\n
\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.

\n

An alternative is to use Mix.env in your general configuration file:

\n
config :sentry, dsn: "https://public:secret@app.getsentry.com/1"\n   included_environments: [:prod],\n   environment_name: Mix.env\n
\n
\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.

\n

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.

\n
config :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
\n
\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.

\n

If using an environment with Plug or Phoenix add the following to your router:

\n
use Plug.ErrorHandler\nuse Sentry.Plug\n
\n
\n
\n\n\n
\n

Capturing Errors

\n

If you use the error logger and setup Plug/Phoenix then you are already done, all errors will bubble up to\nsentry.

\n

Otherwise we provide a simple way to capture exceptions:

\n
do\n  ThisWillError.reall()\nrescue\n  my_exception ->\n    Sentry.capture_exception(my_exception, [stacktrace: System.stacktrace(), extra: %{extra: information}])\nend\n
\n
\n
\n", "link": "https://docs.getsentry.com/clients/elixir/", "id": "elixir", "name": "Elixir" }