Skip to content

Logging improvements#4113

Merged
SuperQ merged 3 commits intoprometheus:mainfrom
tjhop:chore/logging-fixes
Nov 14, 2025
Merged

Logging improvements#4113
SuperQ merged 3 commits intoprometheus:mainfrom
tjhop:chore/logging-fixes

Conversation

@tjhop
Copy link
Contributor

@tjhop tjhop commented Nov 8, 2024

Some logging fixes to address PR feedback from #4089; correct error levels in a few spots and improve consistency.

@tjhop
Copy link
Contributor Author

tjhop commented Nov 8, 2024

@grobinson-grafana for your comment here, do you have a preference what key name we align on?

@grobinson-grafana
Copy link
Collaborator

@grobinson-grafana for your comment here, do you have a preference what key name we align on?

Group key is the correct name.

@SuperQ
Copy link
Member

SuperQ commented Nov 19, 2024

Ping, any additional work needed here?

@tjhop tjhop force-pushed the chore/logging-fixes branch from 1a116a1 to 1c3ab9a Compare November 13, 2025 16:26
Addresses feedback from another PR
prometheus#4089 (comment)

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
This changes the majority of our `Notify()` implementations to set up a
new logger with the group key attached under the key name `group_key`,
and then to use that logger in all subsequent calls to the logger,
including passing it through to further functions that accept loggers
via params.

A few of the notify implementations are more complicated; they either
extract the key later in their `Notify()` implementation or within sub
methods, or even conditionally like with sns. I left those mostly as is
for now, as they seem to be more snow-flake-y.

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
@tjhop tjhop force-pushed the chore/logging-fixes branch from 1c3ab9a to a64bfe2 Compare November 13, 2025 17:03
@SuperQ SuperQ requested a review from siavashs November 13, 2025 17:06
@tjhop
Copy link
Contributor Author

tjhop commented Nov 13, 2025

Sorry for the noise here -- I needed to resolve a conflict and accidentally rebased on my copy of main instead of upstream. This is all cleaned up and ready for review now 👍


n.logger.Debug("extracted group key", "key", key)
logger := n.logger.With("group_key", key)
logger.Debug("extracted group key")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we move this inside notify.ExtractGroupKey() instead of repeating the same line of code in all integrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, but I'm trying to think through the most sane way to do that. Currently, notify.ExtractGroupKey() has the following signature:

alertmanager/notify/util.go

Lines 159 to 166 in 29d491e

// ExtractGroupKey gets the group key from the context.
func ExtractGroupKey(ctx context.Context) (Key, error) {
key, ok := GroupKey(ctx)
if !ok {
return "", fmt.Errorf("group key missing")
}
return Key(key), nil
}

Do we want to update the function signature to accept a logger as well?
Alternatively, I could use the top level slog.Debug() function inside of notify.ExtractGroupKey() if we want to shim a call in to main somewhere after we initialize the logger to slog.SetDefault(logger).

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say skip it, not worth the effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Still a good point, maybe a better option will present in the future

Copy link
Contributor

@siavashs siavashs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks

@SuperQ SuperQ merged commit 1e01172 into prometheus:main Nov 14, 2025
7 checks passed
@SoloJacobs SoloJacobs mentioned this pull request Nov 24, 2025
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.

4 participants