# Pro Tip - Tagging entities which have no autotagging rule support with relationships

**URL:** <https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251>\
**Category:** Dynatrace Tips\
**Tags:** tagging, tips-and-tricks\
**Created:** [November 11, 2021, 11:38am UTC](https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251 "2021-11-11T11:38:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [November 11, 2021, 11:38am UTC](https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251/1 "2021-11-11T11:38:52Z")

</div>

When creating Dynatrace autotags via the UI supported rules you might miss a few entities you’d like to tag. For example there is no easy way to tag a Kubernetes Cluster or a Container Instance.

You might need that though for API analysis or other usecases.

The solution I use to tag the complete stack (K8s cluster, hosts, processes, services, applications, synthetic monitors) for everything that runs/is provided by a specific kubernetes cluster is the following:

(entity Selectors and relationship mapping to the rescue).

1. Identify and tag the kubernetes cluster
2. Tag all hosts of this cluster, using the toRelationship.isClusterOfHost
3. Tag all cloud application of this cluster, using the toRelationships.isClusterOfCa
4. Tag all process groups of the tagged cloud application, using the fromRelationships.isPgOfCa
5. Tag all process group instances of the tagged process groups, using the fromRelationships.isInstanceOf
6. Tag all services that are provided by the tagged process groups, using the fromRelationships.runsOn
7. Tag all applications that are calling the tagged service, using the&nbsp;fromRelationships.calls
8. tag all synthetic monitors that are monitoring the tagged applications, using the&nbsp;fromRelationships.monitors

A concrete example (I’m using YAML notation for the JSON formated auto-tag rule used by the DT API):

```markup
name: dev-stage
  description:
  entitySelectorBasedRules:
  - enabled: true
    entitySelector: type(KUBERNETES_CLUSTER),entityName(_dev)
    valueFormat: ''
  - enabled: true
    entitySelector: type(HOST),toRelationships.isClusterOfHost(type(KUBERNETES_CLUSTER),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(CLOUD_APPLICATION_NAMESPACE),toRelationships.isClusterOfNamespace(type(KUBERNETES_CLUSTER),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(CLOUD_APPLICATION),toRelationships.isClusterOfCa(type(KUBERNETES_CLUSTER),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(PROCESS_GROUP),fromRelationships.isPgOfCa(type(CLOUD_APPLICATION),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(PROCESS_GROUP_INSTANCE),fromRelationships.isInstanceOf(type(PROCESS_GROUP),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(CONTAINER_GROUP_INSTANCE),fromRelationships.isCgiOfCluster(type(KUBERNETES_CLUSTER),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(SERVICE),fromRelationships.runsOn(type(PROCESS_GROUP),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(APPLICATION),fromRelationships.calls(type(SERVICE),tag(dev-stage))
    valueFormat: ''
  - enabled: true
    entitySelector: type(SYNTHETIC_TEST),fromRelationships.monitors(type(APPLICATION),tag(dev-stage))
    valueFormat: ''
  rules: []

```

At first this seems counter intuitive as the first rule would ONLY tag the Kubernetes cluster and the other rules would not do anything (because of the entitySelector filter tag(dev-stage) - which is a reference to the tag we are just defining).  
But once the first rule is applied to the K8s cluster all the other rules start to ‘unfold’: the HOSTs are tagged with the same tag, the CLOUD\_APPLICATIONS.  
Once the CLOUD\_APPLICATIONS are tagged the depending PROCESS\_GROUPS are also tagged and so on.  
The CONTAINER\_GROUP instances are tagged as well (you cannot directly select them in non-entity selector based rules).

This ruleset basically triggers a chain-reaction of applying the same tag across the different dependencies that Dynatrace detected on the fly. Which dependencies you want to consider for this is up to you (whatever you can find in the from/to relationships of an entity is possible).

Where would you like to use this:

- This is fantastic for “dynamic” and simplified management zone assignment
- It is also great in combination with custom metric charts (also using entity selectors) for metrics on entities that you cannot tag otherwise (e.g. container instance metrics)
- It’s also perfect for tagging entities that do not yet exist or create a dependency at some point.  
(e.g. a service that suddenly calls a already tagged service would be tagged and thus shows up on your dashboard that has a tagging filter)

Thought I share this tagging strategy 😉

kr,

Reinhard

---

<div class="post-metadata">

**Author:** ![Karolina\_Linda](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/karolina_linda/32/36089_2.png) [@Karolina\_Linda](https://community.dynatrace.com/u/Karolina_Linda)\
**Post date:** [November 12, 2021, 9:30am UTC](https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251/2 "2021-11-12T09:30:22Z")

</div>

Thank you, Reinhard! That’s a really comprehensive tip article 🙂 I hope many other Dynatrace users will find it super useful&nbsp;:dynatrace:

---

<div class="post-metadata">

**Author:** ![theharithsa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/theharithsa/32/16236_2.png) [@theharithsa](https://community.dynatrace.com/u/theharithsa)\
**Post date:** [November 12, 2021, 11:53am UTC](https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251/3 "2021-11-12T11:53:19Z")

</div>

This is super useful and indeed Protip. I’d love to use this in our customer places. Thanks for sharing, Reinhard.

---

<div class="post-metadata">

**Author:** ![Kenny\_Gillette](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/kenny_gillette/32/20170_2.png) [@Kenny\_Gillette](https://community.dynatrace.com/u/Kenny_Gillette)\
**Post date:** [April 19, 2022, 12:44pm UTC](https://community.dynatrace.com/t/pro-tip-tagging-entities-which-have-no-autotagging-rule-support-with-relationships/33251/4 "2022-04-19T12:44:47Z")

</div>

This is golden!&nbsp; Thanks for putting this together.&nbsp; Helped me a whole lot on learning how to do this tagging this morning.
