# Tagging custom metrics, API v2

**URL:** <https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011>\
**Category:** Dynatrace API\
**Tags:** tagging, dynatrace-api\
**Created:** [October 18, 2021, 1:53pm UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011 "2021-10-18T13:53:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conal\_Buchanan1](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Conal\_Buchanan1](https://community.dynatrace.com/u/Conal_Buchanan1)\
**Post date:** [October 18, 2021, 1:53pm UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011/1 "2021-10-18T13:53:17Z")

</div>

We are creating custom business metrics using the metrics API v2.

Before, when sending custom metrics with API v1 we used to tag the custom device and we could use those tags for alerting profile filters.

I might have missed it but I’m unsure if it’s possible to tag the v2 kind of metric.

Has anyone done something similar, how do you set up the tagging rules?

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [October 19, 2021, 1:08pm UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011/2 "2021-10-19T13:08:11Z")

</div>

If you are having troubles tagging them via custom device, you can always revert to the entity selector and tag them from that standpoint. The entity selector allows you to set a tag for any entity in Dynatrace.&nbsp;[Environment API v2 - Entity selector — Dynatrace Docs](https://www.dynatrace.com/support/help/dynatrace-api/environment-api/entity-v2/entity-selector/)

---

<div class="post-metadata">

**Author:** ![adam\_gardner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/adam_gardner/32/20087_2.png) [@adam\_gardner](https://community.dynatrace.com/u/adam_gardner)\
**Post date:** [October 21, 2021, 11:13pm UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011/3 "2021-10-21T23:13:41Z")

</div>

Extending what Chad said, you might want to look at the new [generic entity model](https://www.dynatrace.com/support/help/how-to-use-dynatrace/metrics/metric-ingestion/topology-model/custom-topology/). Basic workflow is:

1. Create an entity type (this can be anything you could model in the physical world - let’s say a soda can)
2. Push metrics with dimensions . An entity instance (an instance of a soda can) will be created. Metrics will be automatically attached to that entity. This also works with events.
3. Use the v2 tag API (or an autotag rule) to tag your entity with a key / value which then makes everything else easier.

You can see your soda cans by going to [abc123.live.dynatrace.com/ui/entity/list/entity:sodacan](http://abc123.live.dynatrace.com/ui/entity/list/entity:sodacan)

 ![adam_gardner_1-1634858071339.png](https://global.discourse-cdn.com/dynatrace/original/3X/4/4/4485b384e3ee4604c82577f53e465bee0ba1461b.png)

 ![adam_gardner_0-1634857948369.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/d/9d01475097cb06f4cdb3ea439cf0fa8547f92825.png)

---

<div class="post-metadata">

**Author:** ![Conal\_Buchanan1](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@Conal\_Buchanan1](https://community.dynatrace.com/u/Conal_Buchanan1)\
**Post date:** [October 22, 2021, 9:32am UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011/4 "2021-10-22T09:32:43Z")

</div>

The generic entity model looks interesting.

So I assume we cannot tag the metric directly but define a custom entity type that matches the dimension we send in order to create the entity we tag.

I’ll start digging deeper into it,&nbsp;thank you.

---

<div class="post-metadata">

**Author:** ![adam\_gardner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/adam_gardner/32/20087_2.png) [@adam\_gardner](https://community.dynatrace.com/u/adam_gardner)\
**Post date:** [October 24, 2021, 10:27pm UTC](https://community.dynatrace.com/t/tagging-custom-metrics-api-v2/33011/5 "2021-10-24T22:27:52Z")

</div>

Hi Conal,

Correct. In this case you’d define a new generic entity called **sodacan** and set the extractionrule to be some string (in my case **sodacanid** )

Then whenever you pass a metric, a new entity (think of an object in OOP) will be automatically created based on that unique ID.

 ![adam_gardner_0-1635114332990.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/2/e27b033bfdf6433b32f93e37ece2a3cde545f6ec.png)

Feel free to reach out on email (firstname.lastname&nbsp;@ [dynatrace.com](http://dynatrace.com)) if you want to describe your setup in more detail privately.
