10 Jun 2024 10:49 AM - last edited on 24 Jun 2024 08:09 AM by MaciejNeumann
Hi,
We are on Dynatrace Managed and are trying our hand in implementing our Python Extensions 2.0 using the dt-sdk.
For this reason we have setup a "development" server with VSCode and Python 3.10 with dt-sdk module. We initialized the workspace and connected VSCode to our Environment and from there downloaded an existing 2.0 extension to modify. We made a couple minor changes, crated an activation configuration for remote execution and run it locally. In the output, it's polling the endpoints and logs sending data to EEC(which is not running in this development server), yet no metrics are reported in the DT environment.
Now, my theory is that I'm missing something in the configuration. Considering the DEV server has access to an AG, can I somehow instruct the sdk module to send the data to the AG in order to reach the environment. Also, I guess that putting an agent in the server and using the --local-ingest would achieve the same result.
Thanks,
George
Solved! Go to Solution.
10 Jun 2024 11:38 AM - edited 10 Jun 2024 11:40 AM
Data is reported to Dynatrace environment only if the extension is running in the environment. If you run it locally using dt simulate or in the vs code, it does not send data, but writes it on the stdout output. To have data in your environment, you must build your extension and deploy it.
10 Jun 2024 11:47 AM
I was hoping to be able to test the metric ingestion without having to build and deploy every time, and based on the existence of a --local-ingest flag I assumed something could be done to communicate with a remote EEC. Oh well, it's probably less hassle to do it your way than digging through the framework 🙂
Thank you for the answer.
10 Jun 2024 04:36 PM - edited 10 Jun 2024 04:40 PM
In theory we could add support for it, but it comes with quite a bit of maintenance burden:
11 Jun 2024 08:04 AM
Thank you David for the detailed insights. It makes total sense the way you put it, although testing metrics/dashboards/entities without uploading the extension over and over again sounds quite appealing to be honest.
23 Jun 2024 12:26 AM
You can still do it yourself without much trouble by the way:
For this method you need to install our python api client (pip install dt)
from dynatrace_extension import Extension
import os
try:
from dynatrace import Dynatrace
except ImportError:
pass
class ExtensionImpl(Extension):
def rest_api_metrics(self, mint_lines: list[str]):
dt = Dynatrace(os.getenv("DT_API_URL"), os.getenv("DT_API_TOKEN"))
print(dt.metrics.ingest(mint_lines))
return []
def initialize(self):
if self._running_in_sim:
self._client.send_metrics = self.rest_api_metrics
def query(self):
self.logger.info("method query start")
self.report_metric("test.metric", 1)
def main():
ExtensionImpl().run()
if __name__ == '__main__':
main()
This will override the way the SDK sends metrics, so it sends via the API only when running on the simulator.