How do I define tags based on environment variables?

Dynatrace does provide the ability to define tags as in environment variables for processes and process groups.

Recommendation

Defining Tags in the environment itself has its uses however it is not recommended as a general purpose solution. The reason is that this is cumbersome and requires a lot of preplanning. It also makes it hard to make changes later. Use it with caution.

It's recommended that you define additional metadata at the deployed system. Typically, you should think about additional metadata and standard metadata and not about tags (i.e, labels). you should use the environment variable DT_CUSTOM_PROP to define your metadata. This variable needs to be present at the application startup. For WebSphere, you can do this in the WebSphere console in the JVM section. For Tomcat and others, simply define it as part of the startup script.

This enables you to use automated tagging rules, based on existing or custom metadata, to define your filter sets for charts, alerting, and more. These tags and rules can be changed and adapted any time and will apply almost immediately without any change to the monitored environment or applications.

Define tags as environment variables

You can define an environment variable called DT_TAGS on the process or host level. The format of the variable is simple. The variable can contain simple strings or key/value pairs (for example, DT_TAGS=MikesStuff easyTravel=Mike). As you can see in the Windows process example below, you can define multiple tags. Spaces are used to separate tag values.

Note: Applying tags to hosts (instead of thoughtfully setting up environment variables as explained here) isn't recommended. The same applies to applications and processes. For details on setting up the DT_CUSTOM_PROPS environment variable for Tomcat or WebSphere application metadata, Kubernetes annotations for Kubernetes-based deployments, or AWS tagging, see Application metadata & tagging.

Filter entities based on environment variables

In the Dynatrace UI, the example environment variable shown above results in new filters being displayed on the related process overview page (see below). Process group overview pages display the sum of all the tags of all processes in the group.



This feature is currently only available for processes that are deep monitored via Dynatrace Dynatrace OneAgent (Java, Apache Webserver, NGINX, .NET, Node.js, PHP, Go, and IIS).