Add expression to the Alert object

17 views
Skip to first unread message

Alexander Klump

unread,
Aug 30, 2025, 6:35:25 AM (8 days ago) Aug 30
to Prometheus Developers
Dear folks,
from a use case where I wanted to see the expression which triggered the alert in my slack template, I first used a workaround (https://stackoverflow.com/questions/64007696/adding-alertmanager-expression-queries-while-alerting), but had the idea to

include the expression in the alert struct to send it to the receivers.

Since I liked to see how far I would get I played around and added it myself on my forks:
- Prometheus: https://github.com/prometheus/prometheus/compare/main...AlexanderKlump:prometheus:add-expression-as-field-to-alert-struct
- Alertmanager: https://github.com/prometheus/alertmanager/compare/main...AlexanderKlump:alertmanager:add-expression-to-alert-structure?expand=1
- Common: https://github.com/prometheus/common/compare/main...AlexanderKlump:common:add-expression-field-to-alert-struct

I got it working in the sense that Prometheus sends the expression field in the json, Alertmanager ingests it and one can use the expression in a reiver template.

Before I fine tune it (and check the tests) and add a PR, I wanted to ask if you think this is a valuable change (seems somehow big to me, and maybe there was a good reason to not include it)

Thank you for Prometheus+everything else!

Bjoern Rabenstein

unread,
Sep 2, 2025, 4:53:18 AM (5 days ago) Sep 2
to Alexander Klump, Prometheus Developers
On 22.08.25 08:48, 'Alexander Klump' via Prometheus Developers wrote:
> from a use case where I wanted to see the expression which triggered the
> alert in my slack template, I first used a workaround
> (https://stackoverflow.com/questions/64007696/adding-alertmanager-expression-queries-while-alerting),
> but had the idea to
>
> *include the expression in the alert struct to send it to the receivers.*
>
> Since I liked to see how far I would get I played around and added it
> myself on my forks:
> - Prometheus:
> https://github.com/prometheus/prometheus/compare/main...AlexanderKlump:prometheus:add-expression-as-field-to-alert-struct
> - Alertmanager:
> https://github.com/prometheus/alertmanager/compare/main...AlexanderKlump:alertmanager:add-expression-to-alert-structure?expand=1
> - Common:
> https://github.com/prometheus/common/compare/main...AlexanderKlump:common:add-expression-field-to-alert-struct
>
> I got it working in the sense that Prometheus sends the expression field in
> the json, Alertmanager ingests it and one can use the expression in a
> reiver template.
>
> Before I fine tune it (and check the tests) and add a PR, I wanted to ask
> if you think this is a valuable change (seems somehow big to me, and maybe
> there was a good reason to not include it)

This recent discussion at the dev-summit might be relevant:

https://docs.google.com/document/d/1uurQCi5iVufhYHGlBZ8mJMK_freDFKPG0iYBQqJ9fvA/edit?pli=1&tab=t.0#bookmark=kix.eb5vjy241s96

tl;dr: It needs a design doc. (See
https://github.com/prometheus/proposals )


--
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] bjo...@rabenste.in
Reply all
Reply to author
Forward
0 new messages