Skip to content

Commit

Permalink
move to sentry for error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Oct 6, 2024
1 parent 2dd03a4 commit 39aabf4
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 49 deletions.
3 changes: 3 additions & 0 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ RUN mix compile
COPY config/runtime.exs config/

COPY rel rel

# https://hexdocs.pm/sentry/Mix.Tasks.Sentry.PackageSourceCode.html#module-using-in-production
RUN mix sentry.package_source_code
RUN mix release

# start a new build stage so that the final image will only contain
Expand Down
13 changes: 7 additions & 6 deletions core/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ config :canary, :github_app_url, "https://github.com/apps/getcanary-dev/installa

config :ash, :missed_notifications, :ignore

config :honeybadger,
environment_name: Mix.env(),
api_key: {:system, "HONEYBADGER_API_KEY"},
revision: {:system, "APP_REVISION"},
ecto_repos: [Canary.Repo]

config :floki, :html_parser, Floki.HTMLParser.Html5ever

config :sentry,
integrations: [
oban: [
cron: [enabled: true]
]
]

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
7 changes: 7 additions & 0 deletions core/config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ config :canary, :github_app_url, "https://github.com/apps/getcanary/installation

config :canary, :typesense, collection: "canary_prod"

config :sentry,
dsn:
"https://f6f1f6ab1218132660f6bd80e8634712@o4506190168522752.ingest.us.sentry.io/4508073135833088",
environment_name: Mix.env(),
enable_source_code_context: true,
root_source_code_paths: [File.cwd!()]

# Runtime production configuration, including reading
# of environment variables, is done on config/runtime.exs.
7 changes: 7 additions & 0 deletions core/lib/canary/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Canary.Application do
@impl true
def start(_type, _args) do
attach_oban_telemetry()
add_sentry_logger()

:ok = Canary.Index.Collection.ensure(:webpage)
:ok = Canary.Index.Collection.ensure(:github_issue)
Expand Down Expand Up @@ -74,4 +75,10 @@ defmodule Canary.Application do
nil
)
end

defp add_sentry_logger() do
:logger.add_handler(:sentry_handler, Sentry.LoggerHandler, %{
config: %{metadata: [:file, :line]}
})
end
end
9 changes: 0 additions & 9 deletions core/lib/canary/query/understander.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ defmodule Canary.Query.Understander.LLM do
case Canary.AI.chat(args, timeout: 3_000) do
{:ok, completion} ->
parsed = parse(completion, max: 5)

Honeybadger.event("llm", %{
task: "understander",
query: query,
messages: messages,
completion: completion,
parsed: parsed
})

{:ok, parsed}

error ->
Expand Down
24 changes: 0 additions & 24 deletions core/lib/canary/workers/job_reporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,5 @@ defmodule Canary.Workers.JobReporter do
end
end

def handle_job(
[:oban, :job, event],
_measure,
%{job: %Oban.Job{worker: worker}, attempt: attempt} = meta,
_opts
)
when event in [:exception] do
if worker in @processors do
if attempt > 1 do
notify(meta)
end
else
notify(meta)
end

:ok
end

def handle_job(_event, _measure, _meta, _opts), do: :ok

# https://hexdocs.pm/oban/Oban.Telemetry.html#module-examples
defp notify(meta) do
context = Map.take(meta, [:id, :args, :queue, :worker])
Honeybadger.notify(meta.reason, metadata: context, stacktrace: meta.stacktrace)
end
end
3 changes: 2 additions & 1 deletion core/lib/canary_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ defmodule CanaryWeb do
def live_view do
quote do
use Phoenix.LiveView,
layout: {CanaryWeb.Layouts, :app}
layout: {CanaryWeb.Layouts, :app},
on_mount: Sentry.LiveViewHook

unquote(html_helpers())
end
Expand Down
3 changes: 3 additions & 0 deletions core/lib/canary_web/endpoint.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule CanaryWeb.Endpoint do
use Sentry.PlugCapture
use Phoenix.Endpoint, otp_app: :canary

# The session will be stored in the cookie and signed,
Expand Down Expand Up @@ -55,6 +56,8 @@ defmodule CanaryWeb.Endpoint do
pass: ["*/*"],
json_decoder: Phoenix.json_library()

plug Sentry.PlugContext

plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
Expand Down
4 changes: 0 additions & 4 deletions core/lib/canary_web/operations_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ defmodule CanaryWeb.OperationsController do
end

def search(conn, %{"query" => %{"text" => query, "tags" => tags, "sources" => sources}}) do
Honeybadger.event("search", %{account_id: conn.assigns.current_account.id})

sources = find_sources(conn, sources)

case Canary.Searcher.run(sources, query, tags: tags, cache: cache?()) do
Expand All @@ -64,8 +62,6 @@ defmodule CanaryWeb.OperationsController do
end

def ask(conn, %{"query" => %{"text" => query, "tags" => tags, "sources" => sources}}) do
Honeybadger.event("ask", %{account_id: conn.assigns.current_account.id})

sources = find_sources(conn, sources)

conn =
Expand Down
1 change: 0 additions & 1 deletion core/lib/canary_web/router.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
defmodule CanaryWeb.Router do
use CanaryWeb, :router
use AshAuthentication.Phoenix.Router
use Honeybadger.Plug

pipeline :browser do
plug :accepts, ["html"]
Expand Down
1 change: 0 additions & 1 deletion core/lib/canary_web/subdomain_router.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule CanaryWeb.SubdomainRouter do
use CanaryWeb, :router
use Honeybadger.Plug

pipeline :browser do
plug :accepts, ["html"]
Expand Down
5 changes: 3 additions & 2 deletions core/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ defmodule Canary.MixProject do
{:cloak, "~> 1.1"},
{:ash_cloak, "~> 0.1.2"},
{:primer_live, "~> 0.8"},
{:honeybadger, "~> 0.16"},
{:hop, "~> 0.1"},
{:ex_json_schema, "~> 0.10"},
{:yaml_elixir, "~> 2.11"}
{:yaml_elixir, "~> 2.11"},
{:sentry, "~> 10.2.0"},
{:hackney, "~> 1.8"}
] ++ deps_eval()
end

Expand Down
3 changes: 2 additions & 1 deletion core/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"hammer": {:hex, :hammer, "6.2.1", "5ae9c33e3dceaeb42de0db46bf505bd9c35f259c8defb03390cd7556fea67ee2", [:mix], [{:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "b9476d0c13883d2dc0cc72e786bac6ac28911fba7cc2e04b70ce6a6d9c4b2bdc"},
"heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]},
"honeybadger": {:hex, :honeybadger, "0.22.0", "c1476432a5fc0ae6de833f4549065ec7eaf1b9e5fb082d7a58cd312f9d1f9cb1", [:mix], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:hackney, "~> 1.1", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix, ">= 1.0.0 and < 2.0.0", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, ">= 1.0.0 and < 2.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "230ffbd1dc1ad4d38b5dd517e50983e2e5e9b50dc21fc4d3bdbbb6acf90cef50"},
"hop": {:hex, :hop, "0.1.1", "b1fdbca3fbcdbdac00190aca658aff8d1b7a5ee86fbb817ad62e31a5fea74465", [:mix], [{:floki, ">= 0.30.0", [hex: :floki, repo: "hexpm", optional: false]}, {:req, "~> 0.5", [hex: :req, repo: "hexpm", optional: false]}], "hexpm", "c7c60a7900f819caff75482c23db8f72687d7871705272fd252b03c79106e0da"},
"hpax": {:hex, :hpax, "1.0.0", "28dcf54509fe2152a3d040e4e3df5b265dcb6cb532029ecbacf4ce52caea3fd2", [:mix], [], "hexpm", "7f1314731d711e2ca5fdc7fd361296593fc2542570b3105595bb0bc6d0fad601"},
"html5ever": {:hex, :html5ever, "0.16.1", "3dccc3349e0c3e5f5542bcc09253e6246d174391aca692bdecccd446a1c62132", [:mix], [{:rustler, ">= 0.0.0", [hex: :rustler, repo: "hexpm", optional: true]}, {:rustler_precompiled, "~> 0.6.0 or ~> 0.7.0", [hex: :rustler_precompiled, repo: "hexpm", optional: false]}], "hexpm", "6eb06b7796eb100bc815dffd3f500de376a426a088a8405402305cdd8e7cc08a"},
Expand All @@ -70,6 +69,7 @@
"mint_web_socket": {:hex, :mint_web_socket, "1.0.4", "0b539116dbb3d3f861cdf5e15e269a933cb501c113a14db7001a3157d96ffafd", [:mix], [{:mint, ">= 1.4.1 and < 2.0.0-0", [hex: :mint, repo: "hexpm", optional: false]}], "hexpm", "027d4c5529c45a4ba0ce27a01c0f35f284a5468519c045ca15f43decb360a991"},
"mox": {:hex, :mox, "1.1.0", "0f5e399649ce9ab7602f72e718305c0f9cdc351190f72844599545e4996af73c", [:mix], [], "hexpm", "d44474c50be02d5b72131070281a5d3895c0e7a95c780e90bc0cfe712f633a13"},
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
"nimble_ownership": {:hex, :nimble_ownership, "0.3.2", "d4fa4056ade0ae33b5a9eb64554a1b3779689282e37513260125d2d6b32e4874", [:mix], [], "hexpm", "28b9a9f4094fda1aa8ca72f732ff3223eb54aa3eda4fed9022254de2c152b138"},
"nimble_pool": {:hex, :nimble_pool, "1.1.0", "bf9c29fbdcba3564a8b800d1eeb5a3c58f36e1e11d7b7fb2e084a643f645f06b", [:mix], [], "hexpm", "af2e4e6b34197db81f7aad230c1118eac993acc0dae6bc83bac0126d4ae0813a"},
"nodejs": {:hex, :nodejs, "2.0.0", "9a00d00eabf84ba7a04269de46863e0f87bdf6bc488d5a20972b38ade9012764", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "3a03df7dbfba435223b4534fbf276db8be5287fbf83c828f2749bf1ffe73e930"},
"nostrum": {:hex, :nostrum, "0.8.0", "36f5a08e99c3df3020523be9e1c650ad926a63becc5318562abfe782d586e078", [:mix], [{:certifi, "~> 2.8", [hex: :certifi, repo: "hexpm", optional: false]}, {:gun, "~> 2.0", [hex: :gun, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:kcl, "~> 1.4", [hex: :kcl, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm", "ce6861391ff346089d32a243fa71c0cb8bff79ab86ad53e8bf72808267899aee"},
Expand Down Expand Up @@ -110,6 +110,7 @@
"safetensors": {:hex, :safetensors, "0.1.3", "7ff3c22391e213289c713898481d492c9c28a49ab1d0705b72630fb8360426b2", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}, {:nx, "~> 0.5", [hex: :nx, repo: "hexpm", optional: false]}], "hexpm", "fe50b53ea59fde4e723dd1a2e31cfdc6013e69343afac84c6be86d6d7c562c14"},
"salsa20": {:hex, :salsa20, "1.0.4", "404cbea1fa8e68a41bcc834c0a2571ac175580fec01cc38cc70c0fb9ffc87e9b", [:mix], [], "hexpm", "745ddcd8cfa563ddb0fd61e7ce48d5146279a2cf7834e1da8441b369fdc58ac6"},
"saxy": {:hex, :saxy, "1.5.0", "0141127f2d042856f135fb2d94e0beecda7a2306f47546dbc6411fc5b07e28bf", [:mix], [], "hexpm", "ea7bb6328fbd1f2aceffa3ec6090bfb18c85aadf0f8e5030905e84235861cf89"},
"sentry": {:hex, :sentry, "10.2.1", "0450e16d779dc510bef1ff56cdfefb292a56c24c8490c1c205750257a72d255d", [: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", "49f91c7b80f117884ffa12a755eb3ab9037d9a7a16014c776604ae6fe469cbf5"},
"sleeplocks": {:hex, :sleeplocks, "1.1.3", "96a86460cc33b435c7310dbd27ec82ca2c1f24ae38e34f8edde97f756503441a", [:rebar3], [], "hexpm", "d3b3958552e6eb16f463921e70ae7c767519ef8f5be46d7696cc1ed649421321"},
"slipstream": {:hex, :slipstream, "1.1.1", "7e56f62f1a9ee81351e3c36f57b9b187e00dc2f470e70ba46ea7ad16e80b061f", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mint_web_socket, "~> 0.2 or ~> 1.0", [hex: :mint_web_socket, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.1 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c20e420cde1654329d38ec3aa1c0e4debbd4c91ca421491e7984ad4644e638a6"},
"slugify": {:hex, :slugify, "1.3.1", "0d3b8b7e5c1eeaa960e44dce94382bee34a39b3ea239293e457a9c5b47cc6fd3", [:mix], [], "hexpm", "cb090bbeb056b312da3125e681d98933a360a70d327820e4b7f91645c4d8be76"},
Expand Down

0 comments on commit 39aabf4

Please sign in to comment.