# How to grab kafka traceparent and tracestate headers？

**URL:** <https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [April 22, 2022, 6:21am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982 "2022-04-22T06:21:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [April 22, 2022, 6:21am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/1 "2022-04-22T06:21:23Z")

</div>

We use dapr framework, which includes opentelemetry trace, all trace data is sent to apmserver, and finally queried on kibana.  
Everything is fine, but I noticed that if the request goes through kafka (or other middleware), then the whole request chain is broken, as shown in the picture below.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/7/977d3c96086109a9a64d6fe01575cfd4dbfae68f.png)

Is there any way to integrate kafka?

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [May 11, 2022, 8:23pm UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/2 "2022-05-11T20:23:59Z")

</div>

Hey @wajika

the profiler based agent (which is currently in beta) has built in kafka support with auto instrumentation (in other words: you just add the agent and it'll be able to trace across kafka calls). [Here is the docs of the profiler based agent](https://www.elastic.co/guide/en/apm/agent/dotnet/current/setup-auto-instrumentation.html). Have you tried that?

If that does not work, the other option is to do this manually with the public API. [Here](https://www.elastic.co/guide/en/apm/agent/dotnet/current/public-api.html#manually-propagating-distributed-tracing-context) is how you can manually propagate tracing context - you can just call those methods and pass the string you get back via Kafka. If you do that, the whole chain will be in a single trace.

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [May 12, 2022, 1:44am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/3 "2022-05-12T01:44:09Z")

</div>

Thank you for your reply.  
I believe I should be able to get kafka spans if I use APM agent directly.  
` service (apm agent) >> apmserver >> es`  
But let me clarify, we are currently using opentelemetry dotnet client (it is similar to apm agent), its data is sent to apmserver and then stored in Elasticsearch and finally displayed on kibana.  
the path is like this  
`service (otel sdk) >> otlp-collector >> apmserver >> es`  
We've been using it for a while and didn't find the markup for kafka on the kibana apm UI.

The code will operate kafka at the red box mark, but it is not displayed on the UI.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/5/b51eb60c50234b3af31ffe4508e9412fcf5146de.png)

I can't determine whether the otel client does not get the kafka header or the apmserver cannot integrate the kafka span. Is there any way to debug it?  
BTW: I am using elastic stack 7.16.3

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [May 31, 2022, 9:38am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/4 "2022-05-31T09:38:39Z")

</div>

I see,

well, you could turn on debug logs on APM Server to see how the OTel data looks which comes in - that'd be one options.

Or you can ask directly in the OTel GitHub repo: [GitHub - open-telemetry/opentelemetry-dotnet: The OpenTelemetry .NET Client](https://github.com/open-telemetry/opentelemetry-dotnet)

---

<div class="post-metadata">

**Author:** ![wajika](https://avatars.discourse-cdn.com/v4/letter/w/977dab/32.png) [@wajika](https://discuss.elastic.co/u/wajika)\
**Post date:** [June 1, 2022, 4:00am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/5 "2022-06-01T04:00:48Z")

</div>

Well, the .NET Client community isn't very happy to answer any questions.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 22, 2022, 12:01am UTC](https://discuss.elastic.co/t/how-to-grab-kafka-traceparent-and-tracestate-headers/302982/6 "2022-06-22T00:01:32Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
