# Public API using startTransactionWithRemoteParent for Kafka headers

**URL:** <https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183>\
**Category:** APM\
**Tags:** java, server\
**Created:** [June 16, 2023, 1:57am UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183 "2023-06-16T01:57:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sangramreddy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sangramreddy/32/122068_2.png) [@sangramreddy](https://discuss.elastic.co/u/sangramreddy)\
**Post date:** [June 16, 2023, 1:57am UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183/1 "2023-06-16T01:57:19Z")

</div>

**APM Agent language and version** : 1.38.0

We need to manually instrument our Kafka apps as Kafka streams is not supported yet by Elastic APM agent .

In order make the tracing work across all apps, we need to create transactions with remote parent.

> **[Public API | APM Java Agent Reference \[1.x\] | Elastic](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-start-transaction-with-remote-parent-header)**

How to create a transaction remote parent with kafka headers?

Above method seems to be specifically targeted for HTTP headers. How to do the same for Kafka headers?

It's unclear from the above link on how exactly the functional interface is defined and what needs to be the output of that method.

Thanks,  
Sangram

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [June 19, 2023, 12:50pm UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183/2 "2023-06-19T12:50:55Z")

</div>

The `HeaderExtractor` interface is very generic, as you can see from that example it's really just any lambda that returns a string. So you can use that for anything, you just need to specify extracting the header from kafka

---

<div class="post-metadata">

**Author:** ![sangramreddy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sangramreddy/32/122068_2.png) [@sangramreddy](https://discuss.elastic.co/u/sangramreddy)\
**Post date:** [June 22, 2023, 2:49am UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183/3 "2023-06-22T02:49:48Z")

</div>

I was able to figure that out. But there are stil some issues:

1. How to decode the byte array? I had to look at the open source code to figure this out : [apm-agent-java/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java at main · elastic/apm-agent-java · GitHub](https://github.com/elastic/apm-agent-java/blob/main/apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java)

Ideally we should not be writing our own decode() function to convert byte array into a hex string according to your specification. Is there any other way to do this? directly passing the byte array to your API?

1. The argument passed to the functional interface doesn't match with the header key

Argument passed is "elastic-apm-traceparent" but the header is populated with "elasticapmtraceparent".

---

<div class="post-metadata">

**Author:** ![Jack\_Shirazi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_shirazi/32/91641_2.png) [@Jack\_Shirazi](https://discuss.elastic.co/u/Jack_Shirazi)\
**Post date:** [June 22, 2023, 11:05am UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183/4 "2023-06-22T11:05:39Z")

</div>

The TraceContext is internal to the agent, not part of the public API. For now you need to write your own decoder using that as a template. That should also resolve the header name since you'll be passing that

---

<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:** [July 20, 2023, 11:06am UTC](https://discuss.elastic.co/t/public-api-using-starttransactionwithremoteparent-for-kafka-headers/336183/5 "2023-07-20T11:06:14Z")

</div>

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