# Autoinstrument and transaction handling logic

**URL:** <https://discuss.elastic.co/t/autoinstrument-and-transaction-handling-logic/202140>\
**Category:** APM\
**Tags:** rum\
**Created:** [October 3, 2019, 9:52am UTC](https://discuss.elastic.co/t/autoinstrument-and-transaction-handling-logic/202140 "2019-10-03T09:52:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![igmdvc](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@igmdvc](https://discuss.elastic.co/u/igmdvc)\
**Post date:** [October 3, 2019, 9:52am UTC](https://discuss.elastic.co/t/autoinstrument-and-transaction-handling-logic/202140/1 "2019-10-03T09:52:26Z")

</div>

Hi,

We were trying the autoinstrument feature and we experienced the following behavior with the RUM JS library:

When autoinstrumentation detects an AJAX call, it creates a task (an internal object that represents the task of creating a span for that event), and adds it to a task list.  
If another AJAX call is detected before the previous task is completed, it creates a new task and adds it to the list.  
When a task is completed, is removed from the tasks list, and the execution continues with the next task in the list.  
If the tasks list is empty, the current transaction is closed, and subsequent calls are not sent to the APM server.

We are using version 4.4.4.

We are wondering if there is a way to have autoinstrument to automatically create spans but not closing the transaction when all then but leave the control to the user to finish the transaction manually.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![vigneshshanmugam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vigneshshanmugam/32/40324_2.png) [@vigneshshanmugam](https://discuss.elastic.co/u/vigneshshanmugam)\
**Post date:** [October 3, 2019, 10:44am UTC](https://discuss.elastic.co/t/autoinstrument-and-transaction-handling-logic/202140/2 "2019-10-03T10:44:52Z")

</div>

Hi Ignacio,

We have changed the auto instrumentation logic a bit in our latest version and the users of the library would be able to tune the transaction according to the needs (PR Link - [https://github.com/elastic/apm-agent-rum-js/pull/440](https://github.com/elastic/apm-agent-rum-js/pull/440)) and its released as part of version `@elastic/apm-rum@4.5.0` [https://github.com/elastic/apm-agent-rum-js/blob/master/CHANGELOG.md#450-2019-09-30](https://github.com/elastic/apm-agent-rum-js/blob/master/CHANGELOG.md#450-2019-09-30).

We are working on docs at the moment. Let us know if this works for you.

But as a interim solution if you want to hold the transaction for any specific needs, you can add a task manually and end the transaction when needed.

```auto
const tr = agent.getCurrentTransaction();
const id = tr.addTask('hold-tr');

// forcefully end it later somewhere.
tr.end()

// or you can remove task which would trigger our internal closing logic
tr.removeTask(id)

```

Thanks,  
Vignesh

---

<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:** [October 24, 2019, 6:44am UTC](https://discuss.elastic.co/t/autoinstrument-and-transaction-handling-logic/202140/3 "2019-10-24T06:44:54Z")

</div>

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