# How to use injectTraceHeaders?

**URL:** <https://discuss.elastic.co/t/how-to-use-injecttraceheaders/189451>\
**Category:** APM\
**Tags:** java\
**Created:** [July 9, 2019, 4:30am UTC](https://discuss.elastic.co/t/how-to-use-injecttraceheaders/189451 "2019-07-09T04:30:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 9, 2019, 4:55am UTC](https://discuss.elastic.co/t/how-to-use-injecttraceheaders/189451/2 "2019-07-09T04:55:01Z")

</div>

Yes that is a Java Lambda Expression which require Java 8+

You can take a look at this sample repo that has a very simple example of how to use the `HeaderInjector` and `HeaderExtractor` framework.

> **[GitHub - bvader/pipelineapmexample: Example of pipeline that uses APM...](https://github.com/bvader/pipelineapmexample)**
>
> Example of pipeline that uses APM pefrormance metrics - GitHub - bvader/pipelineapmexample: Example of pipeline that uses APM pefrormance metrics

You need to implement the

`HeaderInjector`

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

and the `HeaderExtractor`

> **[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)**

It is up to you how you do that, in the message itself, in the header etc. This is just an example you probably want to do it more thoughtfully for production. This is an example with just raw TCP.

Note the Trace Timeline / Waterfall will probably not look correct in Elasticsearch 6.5.1 as there were fixes in Elasticsearch 7.2 for that visualization.

There is also this thread

> [@Highly Custom Distributed Tracing?](https://discuss.elastic.co/t/highly-custom-distributed-tracing/187206):
>
> So I would love to get distributed tracing working for our application but there is a case here when we do not use the standard infrastructure and move to a websocket. Essentially there are cases when we go `API --\> Websocket (UWS) --\> Node.JS Application --\> API (Localhost) --\> Node.js Worker Cluster (Express routed by PM2) In the worker cluster there will be plenty going on such as db requests and such. The API is just a localhost express app but it only has a single route so I would want t…

---

_[View the full topic](https://discuss.elastic.co/t/how-to-use-injecttraceheaders/189451)._
