The following page contains development steps for creating a custom python extension 2.0 in Visual Studio Code and deploying to Dynatrace.
✅ Prerequisites
- Python Installation
- Python 3.10 or later is installed. (YT video)
- VS Code Installation
- Install VS Code (VS Code Website)
- Certificate and Access Token
- Contact the Enterprise Monitoring team for
- Developer certificate PEM.
- Extension Development API token
- Contact the Enterprise Monitoring team for
Setup and Configuration
🧰 Install Dynatrace Extension Add-On
- You can find Dynatrace Extensions in the Visual Studio Code marketplace. Install it from there or via the VS Code extension search.
🧰 Install Dynatrace Extension SDK CLI via PIP
-
From command prompt execute the following command
pip install dt-extensions-sdk[cli]
🧰 Save Developer Certificate PEM file locally
From the prerequisites you should have received a Developer PEM file (developer_netid.pem) from the Enterprise Monitoring team.
- Save the developer_netid.pem file on your localmachine and record the path
🧰 Connect VS Code to your Dynatrace Environemnt
Note: The Dynatrace environment is the URL you use to access your Dynatrace instance.
- Navigate to the Dynatrace Extensions in VS Code, then select the Add environment button.
- NOTE: If this is a second environment being added then the button will not exist and you use the ‘+’ button on the top right.
- Provide the base URL for your environment following this structure: https://<Id>.apps.dynatrace.com
- NOTE: This is the same as the URL you use to access your Dynatrace instance. Contact Enterprise Monitoring team if you require assistance.
- NOTE: It’s best practice to test in the POC environment. Contact Enterprise Monitoring team if you do not know the POC tenant URL
- Provide the ‘Extension Developmetn API Token’ from the prerequisites phase of this document.
- NOTE: If you do not have the ‘Extension Development API Token’ you will need to contact Enterprise Monitoring team to generate one for you.
- Set this as your current environment.
🧰 Initialization your VS Code Workspace
- Open an empty folder in Visual Studio Code
- Open command pallet and run
>Dynatrace extensions: Initialize workspace
- Choose the second to latest available schema version (e.g. 1.328)
- Download the schema
- From the above step ‘Save Developer Certificate PEM file locally’, provide the path to your developer certificate.
- Select Python Extension 2.0 when asked “What type of project are you starting?”
- Name Your Module
- No spaces or capital letters.
- Name must be under 50 characters.
🗂 File Setup & Configuration
Each bullet below corresponds to a file that was created when installing dt-extensions-sdk. See Fig.1 for example
🔹 setup.py file - add necessary libraries Additional details
This is a standard Python setup file that is used to package the extension and is used by the extension execution controller to install the extension on the ActiveGate or OneAgent along with required dependencies.
- In the install_requires field, add all required libraries (dt-extensions-sdk is added by default).
- Example:
🔹 activation.json Additional details
This is a config file that can be used for local testing when extension instance is launched using the Run contain. It must contain all the mandatory fields as defined in the activationSchema.json. During development, the SDK reads the configuration values from this file. When extension is deployed to the Dynatrace environment and monitoring configuration is created, then the environment provides an individual activation config for each instance of the extension.
“endpoints”: [
{
“api_token”: “”, //provided by Enterprise Monitoring Team
“cron”: “” //how often you want the extension to run
- *It is recommended to use Yale’s custom cron. Contact the Enterprise Monitoring team for details
🔹 activationSchema.json Additional details
This is the schema file that describes the structure of the monitoring configuration
- Update the module name inside this file to match your actual module.
🔹 extension.yaml Additional details
This is the main configuration file of the extension. In this file, you can examine the construction of a Python extension.
It declares the Python module name, the minimum Python version, and the activation schema for a remote ActiveGate or local OneAgent extension.
- In the activation: section, remove any local: path.
- Make sure to increment the module version field if the current version has been deployed, and is trying to modify
🔹 {your extension name} file
- This will contain the _init_.py and _main_.py (where you will configure code)
- This is “my_first_extension” in Fig.1
Fig.1 Example Files Created
Code Migration
Once complete, testing can be done in the POC environment. Please contact the Enterprise Monitoring team stating that you have created a custom ActiveGate Extension 2.0 and are ready to test. We will then go through the process with you.
🚀 Publish your Extension
- Press the F1 key and choose the Dynatrace extensions: Build command. The workflow will build your extension, creating a package inside your
distfolder. - When prompted about uploading your extension to Dynatrace, choose Yes.
- When prompted about activating this extension version, choose Yes
Congratulations. You created, built, uploaded, and activated your first ActiveGate Extension 2.0. You can view this in the Dynatrace UI by navigating to Extensions.