File tree Expand file tree Collapse file tree 5 files changed +43
-5
lines changed Expand file tree Collapse file tree 5 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -648,11 +648,20 @@ func (i *Incident) getRecipientsChannel(t time.Time) rule.ContactChannels {
648648 }
649649
650650 if i .IsNotifiable (state .Role ) {
651- for _ , contact := range r .GetContactsAt (t ) {
652- if contactChs [contact ] == nil {
653- contactChs [contact ] = make (map [int64 ]bool )
654- contactChs [contact ][contact.DefaultChannelID ] = true
651+ contacts := r .GetContactsAt (t )
652+ if len (contacts ) > 0 {
653+ i .logger .Debugw ("Expanded recipient to contacts" ,
654+ zap .Object ("recipient" , r ),
655+ zap .Objects ("contacts" , contacts ))
656+
657+ for _ , contact := range contacts {
658+ if contactChs [contact ] == nil {
659+ contactChs [contact ] = make (map [int64 ]bool )
660+ contactChs [contact ][contact.DefaultChannelID ] = true
661+ }
655662 }
663+ } else {
664+ i .logger .Warnw ("Recipient expanded to no contacts" , zap .Object ("recipient" , r ))
656665 }
657666 }
658667 }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package recipient
22
33import (
44 "database/sql"
5+ "go.uber.org/zap/zapcore"
56 "time"
67)
78
@@ -21,6 +22,14 @@ func (c *Contact) GetContactsAt(t time.Time) []*Contact {
2122 return []* Contact {c }
2223}
2324
25+ // MarshalLogObject implements the zapcore.ObjectMarshaler interface.
26+ func (c * Contact ) MarshalLogObject (encoder zapcore.ObjectEncoder ) error {
27+ // Use contact_id as key so that the type is explicit if logged as the Recipient interface.
28+ encoder .AddInt64 ("contact_id" , c .ID )
29+ encoder .AddString ("name" , c .FullName )
30+ return nil
31+ }
32+
2433var _ Recipient = (* Contact )(nil )
2534
2635type Address struct {
Original file line number Diff line number Diff line change 11package recipient
22
3- import "time"
3+ import (
4+ "go.uber.org/zap/zapcore"
5+ "time"
6+ )
47
58type Group struct {
69 ID int64 `db:"id"`
@@ -21,4 +24,12 @@ func (g *Group) String() string {
2124 return g .Name
2225}
2326
27+ // MarshalLogObject implements the zapcore.ObjectMarshaler interface.
28+ func (g * Group ) MarshalLogObject (encoder zapcore.ObjectEncoder ) error {
29+ // Use contact_id as key so that the type is explicit if logged as the Recipient interface.
30+ encoder .AddInt64 ("group_id" , g .ID )
31+ encoder .AddString ("name" , g .Name )
32+ return nil
33+ }
34+
2435var _ Recipient = (* Group )(nil )
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010
1111type Recipient interface {
1212 fmt.Stringer
13+ zapcore.ObjectMarshaler
1314
1415 GetContactsAt (t time.Time ) []* Contact
1516}
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ func (s *Schedule) RefreshRotations() {
2323 s .rotationResolver .update (s .Rotations )
2424}
2525
26+ // MarshalLogObject implements the zapcore.ObjectMarshaler interface.
27+ func (s * Schedule ) MarshalLogObject (encoder zapcore.ObjectEncoder ) error {
28+ // Use schedule_id as key so that the type is explicit if logged as the Recipient interface.
29+ encoder .AddInt64 ("schedule_id" , s .ID )
30+ encoder .AddString ("name" , s .Name )
31+ return nil
32+ }
33+
2634type Rotation struct {
2735 ID int64 `db:"id"`
2836 ScheduleID int64 `db:"schedule_id"`
You can’t perform that action at this time.
0 commit comments