From 53d11e27eb31ff92ad8406a9f7fe273d77d8a4a7 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Wed, 22 Oct 2025 04:43:20 +0900 Subject: [PATCH] appview/notify: pass logger with mergedLogger Change-Id: zzqwmuukxlnkwwztuusllwvtuzusxyur Signed-off-by: Seongmin Lee --- appview/indexer/notifier.go | 6 +++--- appview/notify/merged_notifier.go | 15 ++++++++++----- appview/state/state.go | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/appview/indexer/notifier.go b/appview/indexer/notifier.go index c7bd3aab..89d37944 100644 --- a/appview/indexer/notifier.go +++ b/appview/indexer/notifier.go @@ -11,7 +11,7 @@ import ( var _ notify.Notifier = &Indexer{} func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) { - l := log.FromContext(ctx).With("notifier", "indexer.NewIssue", "issue", issue) + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) l.Debug("indexing new issue") err := ix.Issues.Index(ctx, *issue) if err != nil { @@ -20,7 +20,7 @@ func (ix *Indexer) NewIssue(ctx context.Context, issue *models.Issue) { } func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) { - l := log.FromContext(ctx).With("notifier", "indexer.NewIssueClosed", "issue", issue) + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) l.Debug("updating an issue") err := ix.Issues.Index(ctx, *issue) if err != nil { @@ -29,7 +29,7 @@ func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) { } func (ix *Indexer) DeleteIssue(ctx context.Context, issue *models.Issue) { - l := log.FromContext(ctx).With("notifier", "indexer.DeleteIssue", "issue", issue) + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) l.Debug("deleting an issue") err := ix.Issues.Delete(ctx, issue.Id) if err != nil { diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index 2e15e4d3..6b252453 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -2,33 +2,38 @@ package notify import ( "context" + "log/slog" "reflect" "sync" "tangled.org/core/appview/models" + "tangled.org/core/log" ) type mergedNotifier struct { notifiers []Notifier + logger *slog.Logger } -func NewMergedNotifier(notifiers ...Notifier) Notifier { - return &mergedNotifier{notifiers} +func NewMergedNotifier(notifiers []Notifier, logger *slog.Logger) Notifier { + return &mergedNotifier{notifiers, logger} } var _ Notifier = &mergedNotifier{} // fanout calls the same method on all notifiers concurrently -func (m *mergedNotifier) fanout(method string, args ...any) { +func (m *mergedNotifier) fanout(method string, ctx context.Context, args ...any) { + ctx = log.IntoContext(ctx, m.logger.With("method", method)) var wg sync.WaitGroup for _, n := range m.notifiers { wg.Add(1) go func(notifier Notifier) { defer wg.Done() v := reflect.ValueOf(notifier).MethodByName(method) - in := make([]reflect.Value, len(args)) + in := make([]reflect.Value, len(args)+1) + in[0] = reflect.ValueOf(ctx) for i, arg := range args { - in[i] = reflect.ValueOf(arg) + in[i+1] = reflect.ValueOf(arg) } v.Call(in) }(n) diff --git a/appview/state/state.go b/appview/state/state.go index f640eef7..8a8a35c8 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -168,7 +168,7 @@ func Make(ctx context.Context, config *config.Config) (*State, error) { notifiers = append(notifiers, phnotify.NewPosthogNotifier(posthog)) } notifiers = append(notifiers, indexer) - notifier := notify.NewMergedNotifier(notifiers...) + notifier := notify.NewMergedNotifier(notifiers, tlog.SubLogger(logger, "notify")) state := &State{ d, -- 2.43.0