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

Python extensions 2.0 migration

Eyad
Participant

Hello everyone,

I am new to Python extensions and am currently working on a 2.0 migration. I am facing some issues and would like to identify the root cause of the problem.

My Setup:

  • IDE: VS Code
  • Local Environment: Windows with Python 3.10
  • Deployment Environment: Linux (Ubuntu 20.04.2) with Python 3.8

Issue:

I am mainly encountering dependency issues, such as missing modules or the following error:
ModuleNotFoundError: No module named 'pymssql._pymssql' # this was in the pytho3_fastcheck.log

In the 1.0 version, my team was including dependencies in the plugin.json file. like this 
Screenshot 2025-02-18 094758.png

Can I include install_ requires in 2.0 or can i have requirements.txt then from the Linux i install the libs where my Ext folder will be located in the VM, and where should it be? Also, do I need to install Linux on my machine? Will Python 3.8 work with the 2.0 extension?

any direction will be helpful. Thank you!

 

5 REPLIES 5

mark_bley
Dynatrace Champion
Dynatrace Champion

The new extension package contains a setup.py file which contains this dependencies field, add them here.

% tail sample_extension/setup.py
setup(name="sample_extension",
      version=find_version(),
      description="Sample_extension python EF2 extension",
      author="Dynatrace",
      packages=find_packages(),
      python_requires=">=3.10",
      include_package_data=True,
      install_requires=["dt-extensions-sdk"],
      extras_require={"dev": ["dt-extensions-sdk[cli]"]},
      )

 Also in case you haven't done already when building extension from windows to *nix systems follow this guide to build for cross platform https://dynatrace-extensions.github.io/dt-extensions-python-sdk/guides/building.html#native-dependen...

 

 

 


any recommendations?

mark_bley
Dynatrace Champion
Dynatrace Champion

If you want to include a function from another python file you can do it like this:

% head __main__.py
from dynatrace_extension import Extension, Status, StatusValue

import datetime
import croniter

from .templates import get_mz_template

and the folder/file structure should look like this:

% tree ./
./
├── __init__.py
├── __main__.py
└── templates.py

 (adapt the paths to your needs, this is just an example and not intended to be a best practice)

I am still getting an error message ..


my code 

from .iam_dynatrace_ad_service_user_keys import iam_dynatrace_ad_service_user_keys
from .iam_dynatrace_api_rest_client import iam_dynatrace_rest_client





cannot import name 'iam_dynatrace_ad_service_user_keys' from 'iam_ad_status_check.iam_dynatrace_ad_service_user_keys' (/var/lib/dynatrace/remotepluginmodule/agent/runtime/extensions/python_venvs/custom_iam-ad-status-check_0.0.5/lib/python3.10/site-packages/iam_ad_status_check/iam_dynatrace_ad_service_user_keys.py)

mark_bley
Dynatrace Champion
Dynatrace Champion

In my example I was just importing a function.

Please review some python documentation on how to import function or classes e.g.: https://stackoverflow.com/questions/4383571/importing-files-from-different-folder

Also try a dt-sdk run <extension_name> to test the extension locally.

Featured Posts