Skip to content

Commit

Permalink
DataChecker : adapte erreur vers Sentry (#4183)
Browse files Browse the repository at this point in the history
* DataChecker : adapte erreur vers Sentry

* Refactor Sentry configuration
  • Loading branch information
AntoineAugusti authored Sep 12, 2024
1 parent 4ea45c5 commit 4446da2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
20 changes: 10 additions & 10 deletions apps/transport/lib/transport/data_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
13 changes: 12 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 1 addition & 11 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4446da2

Please sign in to comment.