From af6cf76f8af57661e0ddd654076219870625c665 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Fri, 20 Dec 2024 16:54:15 +1300 Subject: [PATCH] Add a `JSON` wrapper for Sentry --- config/runtime.exs | 2 +- lib/nerves_hub/sentry_json_wrapper.ex | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 lib/nerves_hub/sentry_json_wrapper.ex diff --git a/config/runtime.exs b/config/runtime.exs index c519eea25..e99c6b34f 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -395,7 +395,7 @@ config :sentry, cron: [enabled: true] ] ], - json_library: JSON + json_library: NervesHub.SentryJsonWrapper config :opentelemetry, :resource, service: %{name: nerves_hub_app} diff --git a/lib/nerves_hub/sentry_json_wrapper.ex b/lib/nerves_hub/sentry_json_wrapper.ex new file mode 100644 index 000000000..0a6d6a980 --- /dev/null +++ b/lib/nerves_hub/sentry_json_wrapper.ex @@ -0,0 +1,15 @@ +defmodule NervesHub.SentryJsonWrapper do + # Sentry tries to validate the JSON library configured, but the builtin + # JSON library doesn't define `encode`, only `encode!`. + # This little wrapper fixes that, until Sentry is updated to support `encode!`, or + # `JSON` supports `encode`. + # https://github.com/getsentry/sentry-elixir/blob/master/lib/sentry/config.ex#L696-L714 + + def encode(data) do + {:ok, JSON.encode!(data)} + end + + def decode(data) do + JSON.decode(data) + end +end