# How to get the trace\_id and span\_id using the OneAgent SDK for Python?

**URL:** <https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590>\
**Category:** Extensions\
**Tags:** python, oneagent-sdk\
**Created:** [December 6, 2022, 1:22pm UTC](https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590 "2022-12-06T13:22:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AymericM](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/aymericm/32/38607_2.png) [@AymericM](https://community.dynatrace.com/u/AymericM)\
**Post date:** [December 6, 2022, 1:22pm UTC](https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590/1 "2022-12-06T13:22:04Z")

</div>

Hi,

I see in the OneAgent SDK documentation that there is a way to get a trace\_i and span\_id from the&nbsp;TraceContextInfo&nbsp;([OneAgent-SDK/README.md at master · Dynatrace/OneAgent-SDK · GitHub](https://github.com/Dynatrace/OneAgent-SDK/blob/master/README.md#trace-context))

I may be missing something but I can’t find how to do it with the OneAgent SDK for Python.

Is there a way to enrich logs with trace\_id and span\_id dierctly from a Python script/app ?

---

<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:** [December 7, 2022, 5:21pm UTC](https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590/2 "2022-12-07T17:21:54Z")

</div>

Curious to know too - it seems the TraceContextInfo is implemented only in OneAgent SDK for .NET. OneAgent SDK for Python is based on the SDK for C/C++ which does not have the feature.

I suppose switching to OpenTelemetry is not a simple solution here as you likely already have your code dependent on OneAgent SDK. But in a long term I’d consider switching, since due to Otel being a vendor-angostic standard, OneAgent SDKs won’t have much attention anymore.

FYI -&nbsp;[@\_Alexander\_](https://community.dynatrace.com/user/4565)&nbsp; - are they any plans to get the other SDKs on part with this feature (NodeJS/Java/C++)?

---

<div class="post-metadata">

**Author:** ![AymericM](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/aymericm/32/38607_2.png) [@AymericM](https://community.dynatrace.com/u/AymericM)\
**Post date:** [December 7, 2022, 5:33pm UTC](https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590/3 "2022-12-07T17:33:40Z")

</div>

Funny coincidence 🙂 we just did a POC using OpenTelemetry and decided we’ll switch to it.

While searching the Dynatrace documentation we saw that a lot of it have changed toward pointing to Opentelemetry and tried&nbsp; it.

---

<div class="post-metadata">

**Author:** ![arlindo](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/arlindo/32/16085_2.png) [@arlindo](https://community.dynatrace.com/u/arlindo)\
**Post date:** [December 16, 2022, 3:40pm UTC](https://community.dynatrace.com/t/how-to-get-the-trace-id-and-span-id-using-the-oneagent-sdk-for-python/37590/4 "2022-12-16T15:40:40Z")

</div>

As&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;mentioned - OpenTelemetry would be the immediate way to go. But the good news is that we’re bringing&nbsp;TraceContextInfo&nbsp;to C/C++ and Python around the end of January. So, if you can wait until then, that’s another way to go.
