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
🔹 setup.py file - add necessary libraries
- This will provide metadata about your extension
- In the install_requires field, add all required libraries (dt-extensions-sdk is added by default).
- Example:
🔹 activation.json
“endpoints”: [
{
“api_token”: “”, //provided by Enterprise Monitoring Team
“cron”: “” //how often you want the extension to run
🔹 activationSchema.json (under “extension”)
- Use activationSchemaTemplate.json as a reference.
- Update the module name inside this file to match your actual module.
🔹 extension.yaml (under “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}
- This will contain the _init_.py and _main_.py (where you will configure code)
🚀 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 Extension 2.0. You can view this in the Dynatrace UI by navigating to Extensions.