Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/sentry/logger_backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ defmodule Sentry.LoggerBackend do
] ++ Map.to_list(sentry)
end

defp excluded_domain?([head | _], state), do: head in state.excluded_domains
defp excluded_domain?([head | rest], state) do
head in state.excluded_domains or excluded_domain?(rest, state)
end

defp excluded_domain?(_, _), do: false

defp logger_metadata(meta, state) do
Expand Down
30 changes: 30 additions & 0 deletions test/logger_backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,36 @@ defmodule Sentry.LoggerBackendTest do
Logger.configure_backend(Sentry.LoggerBackend, excluded_domains: [:cowboy])
end

test "ignores log messages with excluded domains" do
Logger.configure_backend(Sentry.LoggerBackend,
capture_log_messages: true,
excluded_domains: [:test_domain]
)

bypass = Bypass.open()
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
pid = self()

Bypass.expect(bypass, fn conn ->
{:ok, body, conn} = Plug.Conn.read_body(conn)

event =
body
|> Envelope.from_binary!()
|> Envelope.event()

send(pid, event.message)
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
end)

capture_log(fn ->
Logger.error("no domain")
Logger.error("test_domain", domain: [:test_domain])
assert_receive("no domain")
refute_receive("test_domain")
end)
end

test "includes Logger.metadata for keys configured to be included" do
Logger.configure_backend(Sentry.LoggerBackend, metadata: [:string, :number, :map, :list])
bypass = Bypass.open()
Expand Down