Skip to content

notify: add receiver and integration as structured log fields on failures - #5401

Open
locker95 wants to merge 1 commit into
prometheus:mainfrom
locker95:notify-structured-log-fields-5396
Open

notify: add receiver and integration as structured log fields on failures#5401
locker95 wants to merge 1 commit into
prometheus:mainfrom
locker95:notify-structured-log-fields-5396

Conversation

@locker95

Copy link
Copy Markdown

Pull Request Checklist

Please check all the applicable boxes.

Which user-facing changes does this PR introduce?

[ENHANCEMENT] notify: Add receiver and integration as structured log fields on notification failures

Summary

When a notification send fails, the dispatcher logs Notify for alerts failed with only aggrGroup, num_alerts, and err as structured fields. The receiver name and integration (e.g. slack[0]) are present only inside the free-text err string, which makes log aggregation (Loki/ELK) brittle.

Changes

  • Introduce notify.ErrorWithIntegration to annotate RetryStage failures with receiver and integration
  • Attach receiver (from the aggregation group) and integration (when available via errors.As) as structured fields on the dispatch failure log
  • Extend RetryStage tests to assert the annotated error fields

Channel is intentionally out of scope here: it is integration-specific and already appears in some integration error messages (e.g. Slack). Receiver/integration alone cover the main operator need from #5396.

…ures

When notification delivery fails, the dispatcher error log only exposed
receiver/integration inside the free-text err string. Annotate RetryStage
failures with ErrorWithIntegration and attach receiver/integration as
structured fields on the dispatch failure log so operators can group by
them in log aggregators without regex-parsing err.

Fixes prometheus#5396

Signed-off-by: Dean Chen <862469039@qq.com>
@locker95
locker95 requested a review from a team as a code owner July 22, 2026 10:45
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8090f1c8-a849-461d-8102-548f56c840fd

📥 Commits

Reviewing files that changed from the base of the PR and between 949777a and 49cc58b.

📒 Files selected for processing (4)
  • dispatch/dispatch.go
  • notify/notify_test.go
  • notify/retry_stage.go
  • notify/util.go

📝 Walkthrough

Walkthrough

Notification retry failures now include receiver and integration metadata through a new wrapped error type. Retry termination paths produce this error, and aggregation-group dispatch logging extracts the integration field for structured logs. Tests validate metadata for unrecoverable and canceled retries.

Changes

Notification failure context

Layer / File(s) Summary
Error context contract
notify/util.go
Adds ErrorWithIntegration, its constructor, and Error/Unwrap methods for preserving notification metadata and the underlying error.
Retry failure propagation
notify/retry_stage.go, notify/notify_test.go
Wraps canceled and unrecoverable retry errors with receiver and integration identifiers, with tests asserting both metadata values.
Dispatcher structured logging
dispatch/dispatch.go
Extracts ErrorWithIntegration from notification failures and adds the integration field to aggregation-group error logs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant NotificationAttempt
  participant RetryStage
  participant DispatcherLogger
  NotificationAttempt->>RetryStage: return notification error
  RetryStage->>RetryStage: wrap receiver and integration metadata
  RetryStage->>DispatcherLogger: return ErrorWithIntegration
  DispatcherLogger->>DispatcherLogger: add receiver and integration fields
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: structured receiver and integration fields on notification failures.
Description check ✅ Passed The description follows the template well, includes the issue reference, checklist items, and release notes, and clearly explains the change.
Linked Issues check ✅ Passed The PR satisfies #5396 by adding structured receiver and integration logging on notification failures; channel was optional and is intentionally omitted.
Out of Scope Changes check ✅ Passed The changes stay within the issue scope, covering logging, error annotation, and tests without introducing unrelated behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add receiver/integration (and where available, channel) as structured log fields on notification failures

1 participant