mirror of
https://github.com/plausible/analytics.git
synced 2025-01-01 14:04:46 +03:00
Parse Google Analytics failed response before reporting to Sentry (#2354)
This commit parses failed GA responses to JSON before reporting to Sentry. This makes Sentry's PII filtering smarter, redacting only specific keys from the response, instead of the whole string.
This commit is contained in:
parent
ad10721d46
commit
95aafb477d
@ -42,8 +42,8 @@ defmodule Plausible.Google.HTTP do
|
||||
{:ok, report} <- convert_to_maps(report) do
|
||||
{:ok, {report, token}}
|
||||
else
|
||||
{:ok, %{status: _non_http_200, body: body}} ->
|
||||
Sentry.Context.set_extra_context(%{google_analytics_response: body})
|
||||
{:ok, %{status: _non_http_200, body: _body} = response} ->
|
||||
report_failed_request_to_sentry(response)
|
||||
{:error, :request_failed}
|
||||
|
||||
{:error, cause} ->
|
||||
@ -51,6 +51,16 @@ defmodule Plausible.Google.HTTP do
|
||||
end
|
||||
end
|
||||
|
||||
defp report_failed_request_to_sentry(%{status: status, body: body}) do
|
||||
case Jason.decode(body) do
|
||||
{:ok, %{} = body} ->
|
||||
Sentry.Context.set_extra_context(%{ga_response: %{body: body, status: status}})
|
||||
|
||||
_error ->
|
||||
Sentry.Context.set_extra_context(%{ga_response: %{body: body, status: status}})
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_report_from_response(raw_body) do
|
||||
with {:ok, map} <- Jason.decode(raw_body),
|
||||
%{"reports" => [report | _]} <- map do
|
||||
|
Loading…
Reference in New Issue
Block a user