Add Sentry

This commit is contained in:
Shadowfacts 2021-09-22 13:59:44 -04:00
parent 6e0271bf4b
commit fce1bf6c2f
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
7 changed files with 33 additions and 2 deletions

View File

@ -30,6 +30,8 @@ config :phoenix, :json_library, Jason
config :logger, truncate: :infinity
config :frenzy, sentry_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"

View File

@ -6,4 +6,8 @@ defmodule Frenzy do
Contexts are also responsible for managing your data, regardless
if it comes from the database, an external API or others.
"""
def sentry_enabled? do
Application.get_env(:frenzy, :sentry_enabled)
end
end

View File

@ -100,6 +100,13 @@ defmodule Frenzy.Pipeline.ScrapeStage do
Logger.error(Exception.format(:error, e, __STACKTRACE__))
if Frenzy.sentry_enabled?() do
Sentry.capture_exception(e,
stacktrace: __STACKTRACE__,
extra: %{extractor: module_name, item_url: url}
)
end
{:ok, Readability.article(body)}
end
end

View File

@ -75,6 +75,13 @@ defmodule Frenzy.UpdateFeeds do
Logger.warn(
"Encountered error updating feed #{feed.id} #{feed.feed_url}: #{inspect(error)}"
)
if Frenzy.sentry_enabled?() do
Sentry.capture_exception(error,
stacktrace: __STACKTRACE__,
extra: %{feed_id: feed.id, feed_url: feed.feed_url}
)
end
end
end)
end

View File

@ -1,4 +1,8 @@
defmodule FrenzyWeb.Endpoint do
if Frenzy.sentry_enabled?() do
use Sentry.PlugCapture
end
use Phoenix.Endpoint, otp_app: :frenzy
@session_options [
@ -39,6 +43,10 @@ defmodule FrenzyWeb.Endpoint do
pass: ["*/*"],
json_decoder: Phoenix.json_library()
if Frenzy.sentry_enabled?() do
plug Sentry.PlugContext
end
plug Plug.MethodOverride
plug Plug.Head

View File

@ -56,7 +56,8 @@ defmodule Frenzy.MixProject do
{:floki, "~> 0.23"},
{:phoenix_live_view,
git: "https://github.com/phoenixframework/phoenix_live_view", branch: "master"},
{:gemini, git: "https://git.shadowfacts.net/shadowfacts/gemini-ex.git", branch: "main"}
{:gemini, git: "https://git.shadowfacts.net/shadowfacts/gemini-ex.git", branch: "main"},
{:sentry, "~> 8.0"}
]
end
@ -70,7 +71,8 @@ defmodule Frenzy.MixProject do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
test: ["ecto.create --quiet", "ecto.migrate", "test"],
sentry_recompile: ["deps.compile sentry --force", "compile"]
]
end
end

View File

@ -44,6 +44,7 @@
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
"readability": {:git, "https://git.shadowfacts.net/shadowfacts/readability.git", "1538ca2a8c3c3b6b041c9e86b560f368c4547896", [branch: "master"]},
"saxy": {:hex, :saxy, "0.6.0", "cdb2f2fcd8133d1f3f8b0cf6a131ee1ca348dca613de266e9a239db850c4a093", [:mix], [], "hexpm"},
"sentry": {:hex, :sentry, "8.0.5", "5ca922b9238a50c7258b52f47364b2d545beda5e436c7a43965b34577f1ef61f", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.6", [hex: :plug, repo: "hexpm", optional: true]}, {:plug_cowboy, "~> 2.3", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm", "4972839fdbf52e886d7b3e694c8adf421f764f2fa79036b88fb4742049bd4b7c"},
"socket": {:hex, :socket, "0.3.13", "98a2ab20ce17f95fb512c5cadddba32b57273e0d2dba2d2e5f976c5969d0c632", [:mix], [], "hexpm", "f82ea9833ef49dde272e6568ab8aac657a636acb4cf44a7de8a935acb8957c2e"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},