cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
chiranjitdutta
Dynatrace Guide
Dynatrace Guide

 

Description

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.)

Issue

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.

 

chiranjitdutta_6-1721728473415.png

Solution

For Linux

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

Option 1

  • Modify the systemd service file (or similar init script) that starts the Apache service.
    • Example (systemd):
      [Service]
      ... (other service configurations)
      Environment="DT_CUSTOM_PROP=TeamName=DevOps,Environment=Production"
      ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/httpd.conf
      ... (other service configurations)
  • This injects the DT_CUSTOM_PROP environment variable with your desired metadata before starting Apache. The Apache processes will inherit this variable and Dynatrace can pick it up.
  • Make sure the script or systemd service has proper permissions to execute Apache.

After adding the variable and restarting the services it starts reflecting in the Process page.

 

chiranjitdutta_7-1721728511555.png

Option 2

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.

For Windows

There are also many ways to set the Environment variables but that depends on the requirement.

Option 1

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"

Option 2 (recommended/easy way)

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. 

     
    chiranjitdutta_9-1721728636173.pngchiranjitdutta_10-1721728649283.png

     

     

    Note

    For every change a Service restart is required
Version history
Last update:
‎30 Jul 2024 10:25 AM
Updated by:
Comments
AntonPineiro
DynaMight Guru
DynaMight Guru

Thank you! :take_my_money:

Miguel_RinconG
Dynatrace Advisor
Dynatrace Advisor

Thanks!!!!