-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inspect request in sentry context #3180
Conversation
@@ -12,7 +12,7 @@ defmodule PlausibleWeb.Api.ExternalController do | |||
|
|||
def event(conn, _params) do | |||
with {:ok, request} <- Ingestion.Request.build(conn), | |||
_ <- Sentry.Context.set_extra_context(%{request: request}) do | |||
_ <- Sentry.Context.set_extra_context(%{request: inspect(request)}) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: we can use _ = Sentry.Context.set_extra_context(%{request: inspect(request)})
here since the result doesn't matter (to avoid with
expanding to an extra case
). And then since with
has only one case in pipeline and else
is handled, we can switch to case
to make it less magical:
def event(conn, _params) do
case Ingestion.Request.build(conn) do
{:ok, request} ->
Sentry.Context.set_extra_context(%{request: inspect(request)})
case Ingestion.Event.build_and_buffer(request) do
{:ok, %{dropped: [], buffered: _buffered}} ->
conn
|> put_status(202)
|> text("ok")
{:ok, %{dropped: dropped, buffered: _}} ->
first_invalid_changeset = find_first_invalid_changeset(dropped)
if first_invalid_changeset do
conn
|> put_resp_header("x-plausible-dropped", "#{Enum.count(dropped)}")
|> put_status(400)
|> json(%{
errors: Plausible.ChangesetHelpers.traverse_errors(first_invalid_changeset)
})
else
conn
|> put_resp_header("x-plausible-dropped", "#{Enum.count(dropped)}")
|> put_status(202)
|> text("ok")
end
end
{:error, %Ecto.Changeset{} = changeset} ->
conn
|> put_status(400)
|> json(%{errors: Plausible.ChangesetHelpers.traverse_errors(changeset)})
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, case
fits here much better. Would you like to include that change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to do it in a separate PR to make the fix clear to anyone who checks the changelog :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I forgot to update changelog!
BundleMonUnchanged files (7)
No change in files bundle size Final result: ✅ View report in BundleMon website ➡️ |
I think we should JSON encode it for best results. @ruslandoga do you have capacity to look into it? I can pick it up as well. |
Sure do! :) I'll do it right after plausible/ecto_ch#92 |
Awesome, while at it could you make sure this: https://github.com/plausible/analytics/blob/master/lib/plausible/ingestion/event.ex#L376 is fingerprinted in Sentry.EventFilter please? There's quite a lot of it suddenly :) |
Changes
Fixes #3166
Tests
Changelog
Documentation
Dark mode