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
6 changes: 6 additions & 0 deletions lib/error_tracker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ defmodule ErrorTracker do
%Occurrence{} = occurrence
occurrence = %{occurrence | error: error}

# `Repo.insert!(_, on_conflict: [set: [...]])` only round-trips the columns
# it sets, so the in-memory struct keeps `muted: false` (the schema default)
# even when the DB row is muted. Stamp it with the value we already fetched
# so subscribers of `[:error_tracker, :error, :*]` see the real flag.
error = %{error | muted: muted}

# If the error existed and was marked as resolved before this exception,
# sent a Telemetry event
# If it is a new error, sent a Telemetry event
Expand Down
20 changes: 20 additions & 0 deletions test/error_tracker/telemetry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,24 @@ defmodule ErrorTracker.TelemetryTest do

assert_receive {:telemetry_event, [:error_tracker, :error, :unresolved], _, %{error: %Error{}}}
end

test "the :unresolved event carries the muted flag for muted errors" do
{exception, stacktrace} =
try do
raise "This is a test"
rescue
e -> {e, __STACKTRACE__}
end

%Occurrence{error: error = %Error{}} = ErrorTracker.report(exception, stacktrace)
{:ok, error} = ErrorTracker.mute(error)
{:ok, _resolved} = ErrorTracker.resolve(error)

# Trigger the same error again. It exists and is resolved, so the
# :unresolved telemetry event fires — and its `error` struct must
# reflect the muted flag stored in the DB.
ErrorTracker.report(exception, stacktrace)

assert_receive {:telemetry_event, [:error_tracker, :error, :unresolved], _, %{error: %Error{muted: true}}}
end
end
Loading