diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5abacf4..da48a3b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,10 +1,6 @@ name: CI -on: - pull_request: - push: - branches: - - master +on: [push, pull_request] jobs: test: diff --git a/Dockerfile b/Dockerfile index b31d776..8d148f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN mix compile # build release COPY rel rel -RUN mix release +RUN mix do sentry.package_source_code, release # prepare release image FROM alpine:3.15.3 AS app diff --git a/config/config.exs b/config/config.exs index 7a01c8c..4b844da 100644 --- a/config/config.exs +++ b/config/config.exs @@ -31,8 +31,6 @@ config :logger, :console, # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason -config :rollbax, enabled: false - # 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/config/prod.exs b/config/prod.exs index 43906c9..a1165b4 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -21,10 +21,9 @@ config :diff, config :sasl, sasl_error_logger: false -config :rollbax, - environment: "prod", - enabled: true, - enable_crash_reports: true +config :sentry, + enable_source_code_context: true, + root_source_code_paths: [File.cwd!()] config :logger, level: :info, diff --git a/config/releases.exs b/config/releases.exs index e14cdb2..f1aa3af 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -8,7 +8,9 @@ config :diff, config :goth, json: System.fetch_env!("DIFF_GCP_CREDENTIALS") -config :rollbax, access_token: System.fetch_env!("DIFF_ROLLBAR_ACCESS_TOKEN") +config :sentry, + dsn: System.fetch_env!("DIFF_SENTRY_DSN"), + environment_name: System.fetch_env!("DIFF_ENV") config :kernel, inet_dist_listen_min: String.to_integer(System.fetch_env!("BEAM_PORT")), diff --git a/lib/diff/application.ex b/lib/diff/application.ex index 43d4d96..d17875c 100644 --- a/lib/diff/application.ex +++ b/lib/diff/application.ex @@ -6,6 +6,8 @@ defmodule Diff.Application do use Application def start(_type, _args) do + :logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{}) + # List all child processes to be supervised children = [ {Task.Supervisor, name: Diff.Tasks}, diff --git a/lib/diff_web/endpoint.ex b/lib/diff_web/endpoint.ex index c6b447a..934234e 100644 --- a/lib/diff_web/endpoint.ex +++ b/lib/diff_web/endpoint.ex @@ -1,4 +1,5 @@ defmodule DiffWeb.Endpoint do + use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :diff socket "/live", Phoenix.LiveView.Socket @@ -32,6 +33,7 @@ defmodule DiffWeb.Endpoint do pass: ["*/*"], json_decoder: Phoenix.json_library() + plug Sentry.PlugContext plug Plug.MethodOverride plug Plug.Head diff --git a/lib/diff_web/plugs/rollbax.ex b/lib/diff_web/plugs/rollbax.ex deleted file mode 100644 index eac83af..0000000 --- a/lib/diff_web/plugs/rollbax.ex +++ /dev/null @@ -1,42 +0,0 @@ -defmodule DiffWeb.Plugs.Rollbax do - defmacro __using__(_opts) do - quote do - defp handle_errors(conn, %{kind: kind, reason: reason, stack: stacktrace}) do - if report?(kind, reason) do - conn = maybe_fetch_params(conn) - url = "#{conn.scheme}://#{conn.host}:#{conn.port}#{conn.request_path}" - user_ip = conn.remote_ip |> :inet.ntoa() |> List.to_string() - headers = Map.new(conn.req_headers) - - conn_data = %{ - "request" => %{ - "url" => url, - "user_ip" => user_ip, - "headers" => headers, - "params" => conn.params, - "method" => conn.method - }, - "server" => %{ - "host" => conn.host, - "root" => "/" - } - } - - Rollbax.report(kind, reason, stacktrace, %{}, conn_data) - end - end - - defp report?(:error, exception), do: Plug.Exception.status(exception) == 500 - defp report?(_kind, _reason), do: true - - defp maybe_fetch_params(conn) do - try do - Plug.Conn.fetch_query_params(conn) - rescue - _ -> - %{conn | params: "[UNFETCHED]"} - end - end - end - end -end diff --git a/lib/diff_web/router.ex b/lib/diff_web/router.ex index 8bc656f..c87144b 100644 --- a/lib/diff_web/router.ex +++ b/lib/diff_web/router.ex @@ -1,7 +1,6 @@ defmodule DiffWeb.Router do use DiffWeb, :router use Plug.ErrorHandler - use DiffWeb.Plugs.Rollbax import Phoenix.LiveView.Router diff --git a/mix.exs b/mix.exs index 2efbdc7..086f637 100644 --- a/mix.exs +++ b/mix.exs @@ -34,22 +34,22 @@ defmodule Diff.MixProject do # Type `mix help deps` for examples and options. defp deps do [ - {:phoenix, "~> 1.6"}, - {:phoenix_pubsub, "~> 2.0"}, - {:phoenix_html, "~> 3.2"}, + {:floki, "~> 0.32.0"}, {:gettext, "~> 0.11"}, + {:git_diff, github: "ericmj/git_diff", branch: "ericmj/fix-modes"}, {:goth, "~> 1.0"}, - {:jason, "~> 1.0"}, - {:plug_cowboy, "~> 2.1"}, - {:phoenix_live_view, "~> 0.6"}, + {:hackney, "~> 1.15"}, {:hex_core, "~> 0.8.0"}, - {:rollbax, "~> 0.11.0"}, + {:jason, "~> 1.0"}, {:logster, "~> 1.0"}, - {:git_diff, github: "ericmj/git_diff", branch: "ericmj/fix-modes"}, - {:hackney, "~> 1.15"}, - {:floki, "~> 0.32.0"}, + {:mox, "~> 1.0.0", only: :test}, + {:phoenix_html, "~> 3.2"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, - {:mox, "~> 1.0.0", only: :test} + {:phoenix_live_view, "~> 0.6"}, + {:phoenix_pubsub, "~> 2.0"}, + {:phoenix, "~> 1.6"}, + {:plug_cowboy, "~> 2.1"}, + {:sentry, "~> 10.2"} ] end diff --git a/mix.lock b/mix.lock index 5e4ec61..b44212b 100644 --- a/mix.lock +++ b/mix.lock @@ -21,6 +21,8 @@ "mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, "mox": {:hex, :mox, "1.0.1", "b651bf0113265cda0ba3a827fcb691f848b683c373b77e7d7439910a8d754d6e", [:mix], [], "hexpm", "35bc0dea5499d18db4ef7fe4360067a59b06c74376eb6ab3bd67e6295b133469"}, + "nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"}, + "nimble_ownership": {:hex, :nimble_ownership, "0.3.2", "d4fa4056ade0ae33b5a9eb64554a1b3779689282e37513260125d2d6b32e4874", [:mix], [], "hexpm", "28b9a9f4094fda1aa8ca72f732ff3223eb54aa3eda4fed9022254de2c152b138"}, "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, "phoenix": {:hex, :phoenix, "1.6.7", "f1de32418bbbcd471f4fe74d3860ee9c8e8c6c36a0ec173be8ff468a5d72ac90", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b354a4f11d9a2f3a380fb731042dae064f22d7aed8c7e7c024a2459f12994aad"}, "phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"}, @@ -32,7 +34,7 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"}, "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, - "rollbax": {:hex, :rollbax, "0.11.0", "9557935d09d154c8775fa4efc709bfacbb73f20c58a3ced31dea2a74dd6e25de", [:mix], [{:hackney, "~> 1.1", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "a74318b175aae4bdddcc1ecfdf38755df3d8143c9902b1bfd19507ac9901062d"}, + "sentry": {:hex, :sentry, "10.4.0", "d8ffe8ce15b4b53f5e879299c3c222324c289a47a507c0b251c4f91ce7bae9ff", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_ownership, "~> 0.3.0", [hex: :nimble_ownership, repo: "hexpm", optional: false]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "e5f98892152879dc87363b1b7f774eeddb8cf7dddfa7355e40eba188b2cae58a"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},