# Custom Alert Not Firing When Using Code-based Metric Query

**URL:** <https://community.dynatrace.com/t/custom-alert-not-firing-when-using-code-based-metric-query/35694>\
**Category:** Alerting\
**Tags:** anomaly-detection, problems-classic\
**Created:** [June 30, 2022, 5:07pm UTC](https://community.dynatrace.com/t/custom-alert-not-firing-when-using-code-based-metric-query/35694 "2022-06-30T17:07:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![swin12](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@swin12](https://community.dynatrace.com/u/swin12)\
**Post date:** [June 30, 2022, 5:07pm UTC](https://community.dynatrace.com/t/custom-alert-not-firing-when-using-code-based-metric-query/35694/1 "2022-06-30T17:07:04Z")

</div>

Hi,

I am trying to configure custom alerts for a service’s processing time. These alerts are based on a calculated service metric I created that allows me to filter request data by certain dimension; request attributes.

I have configured this alarm end-to-end and gotten an alert to successfully fire under the condition I configure the alert using the ‘build’ option (filtering by only a single dimension value):

 ![swin12_1-1656607461563.png](https://global.discourse-cdn.com/dynatrace/original/3X/8/f/8fa1748306a1fe0a8bcb361422a8a73540e54556.png)

 ![swin12_2-1656607540101.png](https://global.discourse-cdn.com/dynatrace/original/2X/9/99b1eed7cdb4a9e86ba854a26f35d5c1cf5fbc1d.png)

When I try to create a very similar alert using the ‘code’ option (because I need to filter on multiple values for the dimension, which doesn’t seem possible using the ‘build’ option), I get a preview that indicates alerts should fire, but they never actually fire:

 ![swin12_0-1656607450089.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/3/93cb929a207f35d051abb9a257dcc5bdc6830c76.png)

 ![swin12_3-1656607858215.png](https://global.discourse-cdn.com/dynatrace/original/3X/b/1/b153e88de053bab2c69545613ecaed7b5ddd61f7.png)

The settings for the two alarms are identical, in that:

- They have identical static threshold settings
- They have identical severity settings (Slowdown)

Where they differ is:

- I used the ‘build’ option for one and the ‘code’ option for the other.

- For the alert that uses the ‘build’ option, I am able to set entity scopes for the alert (such as management zone).

- For the alert that uses the ‘code’ option, I am unable to set these entity scopes (i.e. I can’t select management zone from the dropdown).

My leading theory is that the issue lies with the fact that the code-based alert does not have a management zone entity set (it doesn’t seem to let me set one). As a result, the alert doesn’t match the management zone for my alerting profile, and therefore I don’t get an alert.

How would I associate a code-based alert with a specific management zone, such that it is picked up by the alerting profile when the alarm fires? Is there something I can add to the metric query?

---

<div class="post-metadata">

**Author:** ![swin12](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@swin12](https://community.dynatrace.com/u/swin12)\
**Post date:** [June 30, 2022, 8:41pm UTC](https://community.dynatrace.com/t/custom-alert-not-firing-when-using-code-based-metric-query/35694/2 "2022-06-30T20:41:06Z")

</div>

The problem was that the custom alert wasn’t related to the management zone condition that I had configured in my alerting profile.

I ended up removing the management zone condition from the alerting profile, instead relying on a different condition on the alerting profile; matching on the name of the custom alert. Once I did this, the alert starting sending notifications as expected.

I still don’t fully understand which conditions cause a custom alert to be associated with a management zone (such that it is ‘respected’ by an alerting profile that has a management zone condition set). My best guess is that you must have a management zone entity filter applied in the custom alert configuration. I still don’t understand how this is possible when the custom alert uses a code-based metric expression (as you seem to lose the ability to set a management zone entity filter this way).
