From 8915a5caadf5a120abdaac7a891a927e22c5f557 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 27 Sep 2022 18:01:53 +0200 Subject: [PATCH] Fix Sentry registration Signed-off-by: Thomas Citharel --- config/config.exs | 4 ---- lib/service/actor_suspension.ex | 1 + lib/service/error_reporting/sentry.ex | 18 +++++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/config/config.exs b/config/config.exs index 1ebf3e65..620a9665 100644 --- a/config/config.exs +++ b/config/config.exs @@ -141,10 +141,6 @@ config :logger, :console, format: "$time $metadata[$level] $message\n", metadata: [:request_id] -config :logger, Sentry.LoggerBackend, - level: :warn, - capture_log_messages: true - config :mobilizon, Mobilizon.Web.Auth.Guardian, issuer: "mobilizon", token_ttl: %{ diff --git a/lib/service/actor_suspension.ex b/lib/service/actor_suspension.ex index 04efe9c3..26ccd9b7 100644 --- a/lib/service/actor_suspension.ex +++ b/lib/service/actor_suspension.ex @@ -11,6 +11,7 @@ defmodule Mobilizon.Service.ActorSuspension do alias Mobilizon.Medias.File alias Mobilizon.Posts.Post alias Mobilizon.Resources.Resource + alias Mobilizon.Service.ErrorReporting.Sentry alias Mobilizon.Service.Export.Cachable alias Mobilizon.Storage.Repo alias Mobilizon.Users.User diff --git a/lib/service/error_reporting/sentry.ex b/lib/service/error_reporting/sentry.ex index 333b8e57..0855cb2d 100644 --- a/lib/service/error_reporting/sentry.ex +++ b/lib/service/error_reporting/sentry.ex @@ -13,7 +13,9 @@ defmodule Mobilizon.Service.ErrorReporting.Sentry do @impl ErrorReporting def configure do - Logger.add_backend(Sentry.LoggerBackend) + if enabled?() do + Logger.add_backend(Sentry.LoggerBackend) + end end def capture_message(message, opts \\ []) when is_binary(message) do @@ -31,12 +33,14 @@ defmodule Mobilizon.Service.ErrorReporting.Sentry do @impl ErrorReporting @spec attach :: :ok | {:error, :already_exists} def attach do - :telemetry.attach( - "oban-errors", - [:oban, :job, :exception], - &handle_event/4, - [] - ) + if enabled?() do + :telemetry.attach( + "oban-errors", + [:oban, :job, :exception], + &handle_event/4, + [] + ) + end end @impl ErrorReporting