on 29 Jul 2024 08:42 AM - edited on 30 Jul 2024 10:25 AM by MaciejNeumann
Dynatrace automatically detects the metadata values of processes and displays them in UI. However, in circumstances where the metadata cannot be detected, and used for TAGGING or process group Detection etc, we have Environment variables options to set to achieve this.
Environment variables cover most technologies (Java and non-Java processes like NGINX, Apache HTTP server, FPM/PHP, Node.js, IIS, and .NET.)
After setting environment variables in the HTTPD file and restarting, the environment variables do not show up in Dynatrace. The below example shows that some environment variables have been set in /etc/httpd/conf/httpd.conf. However, even after a restart of the relevant services it doesn't reflect in the properties and tags section of the Process page.
Dynatrace doesn't support/ apply metadata in environment variables within the Apache httpd.conf file. Httpd.conf is specifically for configuring the Apache web server itself, not for setting environment variables. Also the "SetEnv" is not the correct parameter for this.
There are few options users can try setting the environment variables outside of httpd.conf and letting them influence the processes spawned by Apache
After adding the variable and restarting the services it starts reflecting in the Process page.
Setting Environment Variables in a Script:
Create a script that sets the environment variables and then starts Apache.
Example (bash script):
#!/bin/bash
export DT_CUSTOM_PROP=TeamName=DevOps,Environment=Production /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf
# Alternatively, use exec to replace the script with Apache process
# exec /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf
This script sets the DT_CUSTOM_PROP and then executes the Apache process with the environment variable available.
Important Note: Remember to adjust the paths and variable names according to your specific setup. Make sure the script or systemd service has proper permissions to execute Apache.
There are also many ways to set the Environment variables but that depends on the requirement.
Using a Batch or PowerShell Script where Applications started via scripts.
Create a batch or PowerShell script to set the environment variables and start the application.
Execute the script to start the application with the desired environment variables.
$env:DT_CUSTOM_PROP = "TeamName=DevOps,Environment=Production" Start-Process "path_to_your_application.exe"
Modifying the Registry of the Service
Open Registry Editor (regedit.exe).
Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<service_name>.
Create a new key named "Environment" with type REG_MULTI_SZ.
Add string values for your environment variables in the format DT_CUSTOM_PROP=TeamName=DevOps,Environment=Production.
Below is an example of one of the dynatrace service which we applied Environment variable and TAG.