# Fix Partial Instrumentation Issues for Python Services on Kubernetes

**URL:** <https://community.dynatrace.com/t/fix-partial-instrumentation-issues-for-python-services-on-kubernetes/48954>\
**Category:** Container platforms\
**Tags:** python, kubernetes\
**Created:** [November 19, 2024, 1:34pm UTC](https://community.dynatrace.com/t/fix-partial-instrumentation-issues-for-python-services-on-kubernetes/48954 "2024-11-19T13:34:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![azacharov](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@azacharov](https://community.dynatrace.com/u/azacharov)\
**Post date:** [November 19, 2024, 1:34pm UTC](https://community.dynatrace.com/t/fix-partial-instrumentation-issues-for-python-services-on-kubernetes/48954/1 "2024-11-19T13:34:20Z")

</div>

_Summary:&nbsp;This post describes why Python services on Kubernetes may show only partial instrumentation. It walks through pod logs, OneAgent behavior, supported frameworks, and configuration checks needed to restore full visibility._

Hi,

I’m experiencing issues with Dynatrace instrumentation in my Python-based Kubernetes service

I have implemented tracing using the **autodynatrace SDK** in my FastAPI application, which runs on **Uvicorn**.

However, I see a lot of&nbsp;“_no response_” errors for my Kubernetes service endpoints in Dynatrace.  
As verified through application logs, these errors do not correspond to actual failures.

Additionally, I’m receiving the following diagnostic error in Dynatrace:

**“** _Some data could not be collected or transmitted. This is most likely due to resource congestion on the network, host, or process level in your monitored environment_

_(Diagnostic codes: C1, A5)_ **"**

Here are some details of my Kubernetes Python service:

- Framework: FastAPI.
- Server: Uvicorn.
- Autodynatrace Setup:
  - Installed autodynatrace in the Dockerfile.
  - Set the&nbsp;AUTOWRAPT\_BOOTSTRAP=autodynatrace environment variable

1. What could be causing these “no response” errors, given that the endpoints function correctly?

2.Could the diagnostic error codes (C1, A5) be related to this behavior?

3. Are there additional configurations or adjustments recommended for Python FastAPI services in Kubernetes to optimize tracing and prevent these issues?

**Here are OneAgent analyses:**

[C/Python SDK] end() order wrong or unsupported async/gevent usage (736)

Nov 17 2024, 16:10:43 - Yesterday, 15:40:38Classification: Warning

The end() calls on the SDK tracers are in a wrong order. Can result from usage of async/await or greenlets (gevent, green threads) e.g. with Python gunicorn. Please see&nbsp;[OneAgent-SDK-for-Python/README.md at master · Dynatrace/OneAgent-SDK-for-Python · GitHub](https://github.com/Dynatrace/OneAgent-SDK-for-Python/blob/master/README.md#tracers)&nbsp;Can also be simply forgetting to call start (tracers are not started at creation) or end, or skipping them (e.g., by exception)

**Recommendation:** &nbsp;Check that you are calling the end in the reverse order of the start and in the correct (OS) thread.&nbsp;In Python, prefer with blocks to explicit start/end calls.

Especially if using async/await, green thread,s or other threading abstractions, check&nbsp;[OneAgent-SDK-for-Python/README.md at master · Dynatrace/OneAgent-SDK-for-Python · GitHub](https://github.com/Dynatrace/OneAgent-SDK-for-Python/blob/master/README.md#tracers).

If using a server like gunicorn, you might be able to configure it to not use green threads (normal threads are fine) but be aware that this will have a performance impact.

---

<div class="post-metadata">

**Author:** ![christian\_neumu](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/christian_neumu/32/41778_2.png) [@christian\_neumu](https://community.dynatrace.com/u/christian_neumu)\
**Post date:** [November 20, 2024, 9:45am UTC](https://community.dynatrace.com/t/fix-partial-instrumentation-issues-for-python-services-on-kubernetes/48954/2 "2024-11-20T09:45:30Z")

</div>

> [@azacharov](https://community.dynatrace.com/user/44314)&nbsp;wrote:
> 
> 1. What could be causing these “no response” errors, given that the endpoints function correctly?

Most likely, due to the async usage, the SDK gets confused as to what is the current node and it detects the trace as corrupted before it would report the response code. See next question.

> 2.Could the diagnostic error codes (C1, A5) be related to this behavior?

Yes. Very likely these are caused by the issue the analysis pointed out. You can follow the link to the GitHub SDK README to get further background information.

> 3. Are there additional configurations or adjustments recommended for Python FastAPI services in Kubernetes to optimize tracing and prevent these issues?

Not really sensibly. The main purpose of using async in this case is to allow a single OS thread to handle multiple operations in an interleaved way, so that when one request is waiting for I/O the thread can already start the next request and then later get back to the previous request. But as the SDK uses OS-level thread local variables to track the current trace, this makes it break. This is explained in the GitHub SDK README link. It also explains a workaround that might be applicable when manually using the SDK but it is probably not usable as-is for autodynatrace. (Note that autodynatrace is also not supported through support tickets, it only has open source support via GitHub [GitHub - dynatrace-oss/OneAgent-SDK-Python-AutoInstrumentation: autodynatrace, a python library that implements automatic instrumentation using the OneAgent SDK for Python · GitHub](https://github.com/dynatrace-oss/OneAgent-SDK-Python-AutoInstrumentation))
