Skip to content

Commit 1b36fbc

Browse files
author
Javier Segura
committed
fix: Propagate muted flag to :error telemetry events
`Repo.insert!(_, on_conflict: [set: [...]])` only round-trips the columns it sets, so the in-memory `Error` struct dispatched to subscribers of `[:error_tracker, :error, :new]` and `[:error_tracker, :error, :unresolved]` always carried the schema default (`muted: false`), regardless of the row's real state in the database. This made the dashboard mute action effectively a no-op for those two events. The DB row is already queried for `existing_status` and `muted` at the top of `upsert_error!/5`, so stamp the in-memory struct with that value before dispatching the telemetry events. Two-line change, no public API surface modified — subscribers that already read `metadata.error.muted` start working without any change on their side.
1 parent 3fd3e10 commit 1b36fbc

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/error_tracker.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ defmodule ErrorTracker do
371371
%Occurrence{} = occurrence
372372
occurrence = %{occurrence | error: error}
373373

374+
# `Repo.insert!(_, on_conflict: [set: [...]])` only round-trips the columns
375+
# it sets, so the in-memory struct keeps `muted: false` (the schema default)
376+
# even when the DB row is muted. Stamp it with the value we already fetched
377+
# so subscribers of `[:error_tracker, :error, :*]` see the real flag.
378+
error = %{error | muted: muted}
379+
374380
# If the error existed and was marked as resolved before this exception,
375381
# sent a Telemetry event
376382
# If it is a new error, sent a Telemetry event

test/error_tracker/telemetry_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,24 @@ defmodule ErrorTracker.TelemetryTest do
5151

5252
assert_receive {:telemetry_event, [:error_tracker, :error, :unresolved], _, %{error: %Error{}}}
5353
end
54+
55+
test "the :unresolved event carries the muted flag for muted errors" do
56+
{exception, stacktrace} =
57+
try do
58+
raise "This is a test"
59+
rescue
60+
e -> {e, __STACKTRACE__}
61+
end
62+
63+
%Occurrence{error: error = %Error{}} = ErrorTracker.report(exception, stacktrace)
64+
{:ok, error} = ErrorTracker.mute(error)
65+
{:ok, _resolved} = ErrorTracker.resolve(error)
66+
67+
# Trigger the same error again. It exists and is resolved, so the
68+
# :unresolved telemetry event fires — and its `error` struct must
69+
# reflect the muted flag stored in the DB.
70+
ErrorTracker.report(exception, stacktrace)
71+
72+
assert_receive {:telemetry_event, [:error_tracker, :error, :unresolved], _, %{error: %Error{muted: true}}}
73+
end
5474
end

0 commit comments

Comments
 (0)