# Send data to Dynatrace Managed Cluster through a locally run extension\[dt-sdk\]

**URL:** <https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011>\
**Category:** Extensions\
**Tags:** dynatrace-sdk, python, extensions\
**Created:** [June 10, 2024, 9:49am UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011 "2024-06-10T09:49:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![g\_kat](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/g_kat/32/34573_2.png) [@g\_kat](https://community.dynatrace.com/u/g_kat)\
**Post date:** [June 10, 2024, 9:49am UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/1 "2024-06-10T09:49:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [June 10, 2024, 10:38am UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/2 "2024-06-10T10:38:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![g\_kat](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/g_kat/32/34573_2.png) [@g\_kat](https://community.dynatrace.com/u/g_kat)\
**Post date:** [June 10, 2024, 10:47am UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/3 "2024-06-10T10:47:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [June 10, 2024, 3:36pm UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/4 "2024-06-10T15:36:55Z")

</div>

In theory we could add support for it, but it comes with quite a bit of maintenance burden:

- Support custom certificates for managed, which our simple http client doesn’t

- Support proxy configurations, which the http client also doesn’t support

- Add parameters for the tenant URL, the API token, the proxy, etc

---

<div class="post-metadata">

**Author:** ![g\_kat](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/g_kat/32/34573_2.png) [@g\_kat](https://community.dynatrace.com/u/g_kat)\
**Post date:** [June 11, 2024, 7:04am UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/5 "2024-06-11T07:04:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![david\_lopes](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/david_lopes/32/27273_2.png) [@david\_lopes](https://community.dynatrace.com/u/david_lopes)\
**Post date:** [June 22, 2024, 11:26pm UTC](https://community.dynatrace.com/t/send-data-to-dynatrace-managed-cluster-through-a-locally-run-extension-dt-sdk/46011/6 "2024-06-22T23:26:30Z")

</div>

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)

```python
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.
