# How to use traces with the intake API

**URL:** <https://discuss.elastic.co/t/how-to-use-traces-with-the-intake-api/211830>\
**Category:** APM\
**Created:** [December 13, 2019, 6:09pm UTC](https://discuss.elastic.co/t/how-to-use-traces-with-the-intake-api/211830 "2019-12-13T18:09:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordMathis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lordmathis/32/55044_2.png) [@LordMathis](https://discuss.elastic.co/u/LordMathis)\
**Post date:** [December 13, 2019, 6:09pm UTC](https://discuss.elastic.co/t/how-to-use-traces-with-the-intake-api/211830/1 "2019-12-13T18:09:05Z")

</div>

Kibana version: 7.3

Elasticsearch version: 7.3

APM Server version: 7.3

APM Agent language and version: New agent built for all versions of Delphi

Original install method (e.g. download page, yum, deb, from source, etc.) and version: Web download

I'd like to preface this discussion with the knowledge that I don't exactly quite understand what traces are used for. I believe it is some kind of method to clump all your transactions together so you can observe the flow of the entire application not just the flow of your transaction.

My issue is essentially this, the intake API docs don't specify how to properly create a Trace, so I assumed it would be as simple as generating a trace ID and passing that trace id in on all my JSON, but it would appear as though this does not work. When I go to my traces tab there is nothing there and the % of trace on the transaction is N/A.

What is it that I need to do to properly create a trace using the intake API?

---

<div class="post-metadata">

**Author:** ![Sergey\_Kleyman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_kleyman/32/39333_2.png) [@Sergey\_Kleyman](https://discuss.elastic.co/u/Sergey_Kleyman)\
**Post date:** [December 15, 2019, 10:56pm UTC](https://discuss.elastic.co/t/how-to-use-traces-with-the-intake-api/211830/2 "2019-12-15T22:56:25Z")

</div>

> I don't exactly quite understand what traces are used for

Traces are very useful for applications composed of more than one layer/service. You can have an agent on each layer/service and each agent will produce a transaction but trace ties these transactions together by using [distributed tracing](https://www.elastic.co/guide/en/kibana/current/traces.html#distributed-tracing). One of the mechanisms for distributed tracing is to pass tracing context from agent of the caller service to agent of the callee service. For example by using [dedicated HTTP headers](https://www.w3.org/TR/trace-context-1/). Please note that official Elastic APM Agents use different header names but [it might change soon](https://github.com/elastic/apm/issues/71).

> the intake API docs don't specify how to properly create a Trace

As you correctly noted [Elastic APM Intake API](https://www.elastic.co/guide/en/apm/server/current/events-api.html) doesn't have an event for trace. This is because trace is an ephemeral entity. It's not like other events (transaction, span, etc.) that are produced by one of the agents and sent to APM Server. Trace is a composed of transactions that have the same [`trace_id` property](https://www.elastic.co/guide/en/apm/server/current/transaction-api.html) and the way agents decide on which `trace_id` to assign to each transaction is based on distributed tracing I mentioned above. If the transaction is the first one (i.e., there was no incoming tracing context) then the agent will generate a new `trace_id`, otherwise agent will use `trace_id` from the incoming tracing context and in any case the agent will propagate `trace_id` to downstream (AKA "callee") agents. In addition transaction event has [`parent_id`](https://www.elastic.co/guide/en/apm/server/current/transaction-api.html) which also arrives via [incoming tracing context](https://www.w3.org/TR/trace-context-1/#parent-id) and determines where the transaction should be placed in the trace's tree of transactions.

---

<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:** [January 5, 2020, 6:56pm UTC](https://discuss.elastic.co/t/how-to-use-traces-with-the-intake-api/211830/3 "2020-01-05T18:56:32Z")

</div>

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