carlos / platform Public

apperr: the group sample is the earliest occurrence

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 5e88ea105929bd1ef09a80956585634ff30a1b01 parent a8fb42f
2 files changed, +3 −2
  • internal/apperr/group.go +1 −0
  • internal/apperr/group_test.go +2 −2
diff --git a/internal/apperr/group.go b/internal/apperr/group.go
index 3fc8e911e..d74cf81e2 100644
--- a/internal/apperr/group.go
+++ b/internal/apperr/group.go
@@ -48,6 +48,7 @@ func GroupRecords(recs []Record) []Group {
g.Count += count
if first.Before(g.First) {
g.First = first
+ g.Sample = r
}
if last.After(g.Last) {
g.Last = last
diff --git a/internal/apperr/group_test.go b/internal/apperr/group_test.go
index d98f6f798..354f0418e 100644
--- a/internal/apperr/group_test.go
+++ b/internal/apperr/group_test.go
@@ -9,7 +9,7 @@ func TestGroupRecords(t *testing.T) {
now := time.Date(2026, 9, 7, 10, 0, 0, 0, time.UTC)
recs := []Record{
{FP: "a", Source: SourceEdge, Kind: KindHTTP, Name: "500 GET /x", Host: "h1", Release: "v1", Count: 3, First: now.Add(-10 * time.Minute), Last: now.Add(-5 * time.Minute), Stack: "s1"},
- {FP: "a", Source: SourceEdge, Kind: KindHTTP, Name: "500 GET /x", Host: "h2", Release: "v2", Count: 2, First: now.Add(-20 * time.Minute), Last: now.Add(-1 * time.Minute)},
+ {FP: "a", Source: SourceEdge, Kind: KindHTTP, Name: "500 GET /x", Host: "h2", Release: "v2", Count: 2, First: now.Add(-20 * time.Minute), Last: now.Add(-1 * time.Minute), Stack: "s2"},
{FP: "b", Source: SourceLog, Kind: KindLog, Name: "boom", Level: "error", Host: "h1", Count: 1, First: now.Add(-30 * time.Minute), Last: now.Add(-30 * time.Minute)},
{FP: OverflowFP, Source: SourceEdge, Name: "500 GET /z", Host: "h1", Count: 40, First: now, Last: now},
}
@@ -27,7 +27,7 @@ func TestGroupRecords(t *testing.T) {
if len(a.Hosts) != 2 || a.Hosts[0] != "h1" || a.Hosts[1] != "h2" || len(a.Releases) != 2 {
t.Fatalf("a hosts/releases = %v %v", a.Hosts, a.Releases)
}
- if a.Sample.Stack != "s1" {
+ if a.Sample.Stack != "s2" {
t.Fatal("sample must be the earliest record")
}
}