Skip to content

Commit

Permalink
Add a test for :crash_reason metadata handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pojiro committed Jan 31, 2023
1 parent bcc8510 commit c1624a4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/logger_backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,37 @@ defmodule Sentry.LoggerBackendTest do
end)
end

test "includes Logger.metadata except for :crash_reason" do
Logger.configure_backend(Sentry.LoggerBackend, metadata: [:string, :crash_reason])
bypass = Bypass.open()
Process.flag(:trap_exit, true)
pid = self()

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

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

assert event.extra["logger_metadata"]["string"] == "string"
assert event.extra["logger_metadata"]["crash_reason"] == nil
send(pid, "API called")
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
end)

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

capture_log(fn ->
{:ok, pid} = Sentry.TestGenServer.start_link(pid)
Sentry.TestGenServer.add_logger_metadata(pid, :string, "string")
Sentry.TestGenServer.invalid_function(pid)
assert_receive "terminating"
assert_receive "API called"
end)
end

test "does not include Logger.metadata when disabled" do
Logger.configure_backend(Sentry.LoggerBackend, metadata: [])
bypass = Bypass.open()
Expand Down

0 comments on commit c1624a4

Please sign in to comment.