Skip to content

Commit

Permalink
fix: don't scrub uploads (#18)
Browse files Browse the repository at this point in the history
* fix: don't scrub uploads
* add a test for Plug.Upload
  • Loading branch information
msutkowski authored Feb 7, 2024
1 parent 21166ca commit 1ebfaa4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/logger_json/plug/metadata_formatters/datadog_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ if Code.ensure_loaded?(Plug) do
end

defp recursive_scrub(%{__struct__: Plug.Conn.Unfetched}, _scrub_map), do: "%Plug.Conn.Unfetched{}"
defp recursive_scrub(%Plug.Upload{}, _scrub_map), do: "%Plug.Upload{}"

defp recursive_scrub([head | _tail] = data, scrub_map) when is_tuple(head),
do: data |> Enum.map(&recursive_scrub(&1, scrub_map)) |> Map.new()
Expand Down
24 changes: 24 additions & 0 deletions test/unit/logger_json/plug/datadog_logger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@ defmodule LoggerJSON.Plug.MetadataFormatters.DatadogLoggerTest do
}
} = Jason.decode!(log)
end

test "doesn't blow up during uploads" do
conn =
:post
|> conn("/upload", %Plug.Upload{
content_type: "text/csv",
filename: "example.csv",
path: "/tmp/plug-1707-lAW6/multipart-1707338489-738149684841-4"
})
|> put_req_header("content-type", "multipart/form-data")

log =
capture_io(:standard_error, fn ->
MyPlug.call(conn, [])
Logger.flush()
Process.sleep(10)
end)

assert %{
"http" => %{
"request_params" => "%Plug.Upload{}"
}
} = Jason.decode!(log)
end
end

describe "configuration: :scrubbed_value" do
Expand Down

0 comments on commit 1ebfaa4

Please sign in to comment.