From 4446da20d7816c8c5a0c61759d1046bb5fe138da Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Thu, 12 Sep 2024 14:54:16 +0200 Subject: [PATCH] DataChecker : adapte erreur vers Sentry (#4183) * DataChecker : adapte erreur vers Sentry * Refactor Sentry configuration --- apps/transport/lib/transport/data_checker.ex | 20 ++++++++++---------- config/config.exs | 13 ++++++++++++- config/prod.exs | 12 +----------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apps/transport/lib/transport/data_checker.ex b/apps/transport/lib/transport/data_checker.ex index 36fd919647..60c6fe663b 100644 --- a/apps/transport/lib/transport/data_checker.ex +++ b/apps/transport/lib/transport/data_checker.ex @@ -86,26 +86,26 @@ defmodule Transport.DataChecker do {:archived, datetime} {:error, %HTTPoison.Error{} = error} -> - Sentry.capture_message( - "Unable to get Dataset status from data.gouv.fr", - extra: %{dataset_datagouv_id: datagouv_id, error_reason: inspect(error)} - ) - + log_sentry_event(datagouv_id, error) :ignore {:error, reason} when reason in [:not_found, :gone] -> :inactive {:error, error} -> - Sentry.capture_message( - "Unable to get Dataset status from data.gouv.fr", - extra: %{dataset_datagouv_id: datagouv_id, error_reason: inspect(error)} - ) - + log_sentry_event(datagouv_id, error) :ignore end end + defp log_sentry_event(datagouv_id, error) do + Sentry.capture_message( + "Unable to get dataset status for Dataset##{datagouv_id} from data.gouv.fr", + fingerprint: ["#{__MODULE__}:dataset_status:error"], + extra: %{dataset_datagouv_id: datagouv_id, error_reason: inspect(error)} + ) + end + def outdated_data do # Generated as an integer rather than a UUID because `payload.job_id` # for other notifications are %Oban.Job.id (bigint). diff --git a/config/config.exs b/config/config.exs index 5b0febe68f..3c2df9a575 100644 --- a/config/config.exs +++ b/config/config.exs @@ -183,8 +183,19 @@ config :transport, transport_tools_folder: Path.absname("transport-tools/") # Disable sending events to Sentry by default. +# Sentry events are only sent when `dsn` is not nil +# https://hexdocs.pm/sentry/upgrade-10-x.html#stop-using-included_environments # Events are sent in production and staging, configured in `prod.exs` -config :sentry, dsn: nil +config :sentry, + dsn: nil, + environment_name: "SENTRY_ENV" |> System.get_env(to_string(config_env())) |> String.to_atom(), + enable_source_code_context: true, + # https://hexdocs.pm/sentry/Sentry.html#module-configuration + # > a list of paths to the root of your application's source code. + # > For umbrella apps, you should set this to all the application paths in your umbrella + # Caveat: https://github.com/getsentry/sentry-elixir/issues/638 + root_source_code_paths: [File.cwd!() |> Path.join("apps")], + filter: Transport.Shared.SentryExceptionFilter # For now, never send session data (containing sensitive data in our case) nor params, # even if this means less useful information. diff --git a/config/prod.exs b/config/prod.exs index b765ec7f75..86270024ca 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -15,18 +15,8 @@ config :transport, # Configure Sentry for production and staging. # Check out https://sentry.io/settings/transport-data-gouv-fr/projects/transport-site/install/elixir/ config :sentry, - # Sentry events are only sent when `dsn` is not nil - # https://hexdocs.pm/sentry/upgrade-10-x.html#stop-using-included_environments dsn: System.get_env("SENTRY_DSN"), - csp_url: System.get_env("SENTRY_CSP_URL"), - environment_name: "SENTRY_ENV" |> System.get_env(to_string(config_env())) |> String.to_atom(), - enable_source_code_context: true, - # https://hexdocs.pm/sentry/Sentry.html#module-configuration - # > a list of paths to the root of your application's source code. - # > For umbrella apps, you should set this to all the application paths in your umbrella - # Caveat: https://github.com/getsentry/sentry-elixir/issues/638 - root_source_code_paths: [File.cwd!() |> Path.join("apps")], - filter: Transport.Shared.SentryExceptionFilter + csp_url: System.get_env("SENTRY_CSP_URL") # Do not print debug messages in production config :logger, level: :info