diff --git a/config/config.exs b/config/config.exs index b723cd0f..e46cb256 100644 --- a/config/config.exs +++ b/config/config.exs @@ -28,7 +28,8 @@ config :postoffice, PostofficeWeb.Endpoint, ] # Configures Elixir's Logger -config :logger, :console, +config :logger, + backends: [:console, Sentry.LoggerBackend], format: "$time $metadata[$level] $message\n", metadata: [:request_id] @@ -50,6 +51,16 @@ config :postoffice, Oban, ], queues: [default: 10, http: 100, pubsub: 15] +config :sentry, + dsn: System.get_env("POSTOFFICE_SENTRY_DSN", ""), + environment_name: Mix.env(), + enable_source_code_context: true, + root_source_code_path: File.cwd!(), + tags: %{ + env: Mix.env() + }, + included_environments: [:prod] + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/lib/postoffice_web/endpoint.ex b/lib/postoffice_web/endpoint.ex index d7999c43..fa3d82ab 100644 --- a/lib/postoffice_web/endpoint.ex +++ b/lib/postoffice_web/endpoint.ex @@ -1,4 +1,5 @@ defmodule PostofficeWeb.Endpoint do + use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :postoffice @session_options [ @@ -38,6 +39,7 @@ defmodule PostofficeWeb.Endpoint do pass: ["*/*"], json_decoder: Phoenix.json_library() + plug Sentry.PlugContext plug Plug.MethodOverride plug Plug.Head diff --git a/mix.exs b/mix.exs index 7c79adc1..1c5b096f 100644 --- a/mix.exs +++ b/mix.exs @@ -62,6 +62,7 @@ defmodule Postoffice.MixProject do {:phoenix_live_dashboard, "0.7.2"}, {:phoenix_live_reload, "1.4.0", only: :dev}, {:gettext, "0.20.0"}, + {:sentry, "8.1.0"}, {:jason, "1.4.0"}, {:plug_cowboy, "2.5.2"}, {:bcrypt_elixir, "3.0.1"},