# Custom transaction for single page applications route changes

**URL:** <https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585>\
**Category:** APM\
**Tags:** rum\
**Created:** [July 15, 2019, 4:51pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585 "2019-07-15T16:51:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jesusgarcia](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@jesusgarcia](https://discuss.elastic.co/u/jesusgarcia)\
**Post date:** [July 15, 2019, 4:51pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/1 "2019-07-15T16:51:23Z")

</div>

Hi,

We want to use custom transactions for client side navigations in a single page application, as suggested by the documentation. However, we found that the RUM agent is already creating automatically transactions for route changes (transaction.type = "route-change").

As the RUM agent don't support to have multiple open transactions simultaneously, our custom transaction is automatically closed when the agent creates the "route-change" transaction automatically.

Is there any way to disable the automatic monitoring of the route changes events?

Thanks;

---

<div class="post-metadata">

**Author:** ![Hamidreza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza/32/21369_2.png) [@Hamidreza](https://discuss.elastic.co/u/Hamidreza)\
**Post date:** [July 16, 2019, 12:09pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/2 "2019-07-16T12:09:19Z")

</div>

Hi @jesusgarcia,

Thanks for reaching out and welcome to the forum.

Currently, it's not possible to disable the automatic instrumentations we have [this issue](https://github.com/elastic/apm-agent-rum-js/issues/192) to address this.

Would you please provide more detail about your use-case?  
Would it work in your case, if the `route-change` transaction used the custom transaction you've created and only extended/renamed it?

Cheers,  
Hamid

---

<div class="post-metadata">

**Author:** ![jesusgarcia](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@jesusgarcia](https://discuss.elastic.co/u/jesusgarcia)\
**Post date:** [July 18, 2019, 4:37pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/3 "2019-07-18T16:37:41Z")

</div>

Hi Hamidreza:

There are three reasons why that automatic instrumentation is not enough for us, and why we thought that creating custom transactions could solve our problem:

1. In our application, the navigation performs some tasks before actually try to change the browser url (history.pushState) which is when the automatic instrumentation starts the 'route-change' transaction. This tasks do some requests to our backends that we want to include as spans in the 'navigation' transaction.
2. On the other hand, the automatic 'route-change' transaction is ended before when we consider the navigation has finished, hence not reporting some requests and reporting a shorter duration
3. We as well want to customise the transaction name; 'route-change' transactions are reported with 'Unknown' in name because we don't update the browser title.

Thanks in advance !

---

<div class="post-metadata">

**Author:** ![Hamidreza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza/32/21369_2.png) [@Hamidreza](https://discuss.elastic.co/u/Hamidreza)\
**Post date:** [July 23, 2019, 8:49am UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/4 "2019-07-23T08:49:01Z")

</div>

Thanks for your reply @jesusgarcia!

I've also created [this issue](https://github.com/elastic/apm-agent-rum-js/issues/334) to make handling automatic vs manual instrumentations easier to use.

---

<div class="post-metadata">

**Author:** ![jesusgarcia](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@jesusgarcia](https://discuss.elastic.co/u/jesusgarcia)\
**Post date:** [July 24, 2019, 3:51pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/5 "2019-07-24T15:51:44Z")

</div>

Thanks Hamidreza,

If I understood correctly, from what I read in [the issue](https://github.com/elastic/apm-agent-rum-js/issues/334), I don't think that approach fit our particular needs.

Removing the automatic spans capturing for 'manual mode' transactions stop us from using that 'manual mode' for for client navigations transactions, since we are mostly interested in those spans. On the other hand, if we use the 'automatic mode', we'll have the same problems since the 'route-change' transaction will 'kill' our custom transaction.

It would be possible to just add a setting flag to enable/disable automatic 'route-change' instrumentation?

Thanks !

---

<div class="post-metadata">

**Author:** ![Hamidreza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza/32/21369_2.png) [@Hamidreza](https://discuss.elastic.co/u/Hamidreza)\
**Post date:** [July 25, 2019, 1:36pm UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/6 "2019-07-25T13:36:34Z")

</div>

Hi @jesusgarcia,

We've decided to provide both of the solutions described in [#192](https://github.com/elastic/apm-agent-rum-js/issues/192) and [#334](https://github.com/elastic/apm-agent-rum-js/issues/334). Therefore, you would be able to choose the one that fits your use-case.

Cheers,  
Hamid

---

<div class="post-metadata">

**Author:** ![jesusgarcia](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@jesusgarcia](https://discuss.elastic.co/u/jesusgarcia)\
**Post date:** [July 29, 2019, 7:04am UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/7 "2019-07-29T07:04:10Z")

</div>

Thanks, that would be great.

---

<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:** [August 19, 2019, 3:04am UTC](https://discuss.elastic.co/t/custom-transaction-for-single-page-applications-route-changes/190585/8 "2019-08-19T03:04:17Z")

</div>

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