# Add custom Information for correlation using JavaScript agent (RUM)

**URL:** <https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205>\
**Category:** APM\
**Tags:** rum\
**Created:** [December 30, 2021, 1:29pm UTC](https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205 "2021-12-30T13:29:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuphil](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@fuphil](https://discuss.elastic.co/u/fuphil)\
**Post date:** [December 30, 2021, 1:29pm UTC](https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205/1 "2021-12-30T13:29:41Z")

</div>

Hi,

we have the JavaScript agent (RUM) in place and are also collecting the logs via filebeat.  
In order to be able to correlate the data between RUM and the Logs I would like to add some custom information on the client via the JS agent, e.g. the session id from a cookie.  
Is this possible? How? Unfortunately I did not find any useful information so far...  
I just found the possibility to correlate APM data and logs via trace ids using the Java agent, but I would like to correlate on an existing information e.g. session id from the application, which is already in the logs.

Thanks in advance for any help!

ciao

---

<div class="post-metadata">

**Author:** ![Alberto\_Delgado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alberto_delgado/32/98488_2.png) [@Alberto\_Delgado](https://discuss.elastic.co/u/Alberto_Delgado)\
**Post date:** [December 31, 2021, 12:11pm UTC](https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205/2 "2021-12-31T12:11:57Z")

</div>

Hi @fuphil

Thanks for reaching out!

There is a way to add custom metadata on all transaction, error and span events:

```auto
elasticApm.init({
   serviceName: 'your-service-name',
   serverUrl: 'https://yourAPMendpoint/'
})
// Set metadata on all transaction, error and span events
elasticApm.addLabels({
  label1: 'value1',
  label2: 'value2'
})

```

More info [here](https://www.elastic.co/guide/en/apm/agent/rum-js/master/agent-api.html#apm-add-labels)

On the other hand, you can also add labels to specific transactions and spans as you can see in the [transaction API documentation](https://www.elastic.co/guide/en/apm/agent/rum-js/master/transaction-api.html#transaction-add-labels) and [span API documentation](https://www.elastic.co/guide/en/apm/agent/rum-js/master/span-api.html#span-add-labels)

In the JavaScript agent we have also available [distributed tracing](https://www.elastic.co/guide/en/apm/guide/7.16/apm-distributed-tracing.html), specific documentation for JavaScript agent [here](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html)

Important to take into account that in the case of RUM the trace data are only appended to API calls (fetch/xhr). If you want to trace the HTML document generation, you would have to set up the RUM agent with appropriate [page-load trace details](https://www.elastic.co/guide/en/apm/agent/rum-js/current/distributed-tracing-guide.html#dynamic-html-doc).

Hope this helps you

Thanks,  
Alberto

---

<div class="post-metadata">

**Author:** ![fuphil](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@fuphil](https://discuss.elastic.co/u/fuphil)\
**Post date:** [January 4, 2022, 7:08am UTC](https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205/3 "2022-01-04T07:08:59Z")

</div>

Thank you very much, I will try it with the lables!

---

<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 25, 2022, 3:09am UTC](https://discuss.elastic.co/t/add-custom-information-for-correlation-using-javascript-agent-rum/293205/4 "2022-01-25T03:09:14Z")

</div>

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