# \[RUM\] StartTransaction not writing to apm server in javascript

**URL:** <https://discuss.elastic.co/t/rum-starttransaction-not-writing-to-apm-server-in-javascript/203140>\
**Category:** APM\
**Tags:** rum\
**Created:** [October 11, 2019, 4:28am UTC](https://discuss.elastic.co/t/rum-starttransaction-not-writing-to-apm-server-in-javascript/203140 "2019-10-11T04:28:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skyskai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skyskai/32/55745_2.png) [@skyskai](https://discuss.elastic.co/u/skyskai)\
**Post date:** [October 11, 2019, 4:28am UTC](https://discuss.elastic.co/t/rum-starttransaction-not-writing-to-apm-server-in-javascript/203140/1 "2019-10-11T04:28:04Z")

</div>

**APM Agent language and version** : Javascript, 4.5.1  
**Browser version** : Chrome Latest

I set up apm agent on Javascript based web page. Init (), which is called at the first loading, uses the following code to check that it is normally recorded on the apm server.

> init:function(){  
> var \_apm = window.elasticApm;
> 
> var fioriUser = sap.ushell.Container.getService("UserInfo").getUser();  
> var sCHash = document.location.hash;  
> var sHash = sCHash.indexOf("&")\>-1 ? sCHash.split("&")[0] : sCHash;  
> //10. Set User Info  
> \_apm.setUserContext({  
> id: fioriUser.getId(),  
> username: fioriUser.getFullName(),  
> email: fioriUser.getEmail()  
> });  
> //20. Initialize  
> var agent = \_apm.init({  
> serviceName: 'fioriNew',  
> serverUrl: '[https://server.url](https://server.url)',  
> serviceVersion: '0.90',  
> pageLoadTransactionName : sHash  
> });  
> this.\_agent = agent;  
> },

After that, add the following code to the hashchange event as follows to record a new transaction whenever the browser's url changes. However, the problem is that the apm server cannot be recorded normally.

> onHashChanged: function (oEvent) {  
> var \_agent = this.\_agent;  
> var oCurrentTransaction = \_agent.getCurrentTransaction();  
> if(oCurrentTransaction && oCurrentTransaction.ended===false){  
> oCurrentTransaction.end();  
> }  
> var sCHash = oEvent.target.document.location.hash;  
> var sHash = sCHash.indexOf("&")\>-1 ? sCHash.split("&")[0] : sCHash;  
> \_agent.startTransaction(sHash);
> 
> },  
> If it's a problem with my code, I would be grateful if you could tell me what the best practices are for the code.

---

<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 15, 2019, 10:29am UTC](https://discuss.elastic.co/t/rum-starttransaction-not-writing-to-apm-server-in-javascript/203140/2 "2019-10-15T10:29:31Z")

</div>

Hi Yang,

Thanks for trying out RUM, Can you enable the debug flag in the config and share us the logs?

```auto
apm.init({debug: true})

```

From the code, I feel like the hash change transaction was discarded since there was no spans present on it. The debug logs would confirm it if thats the case.

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:** [November 5, 2019, 6:29am UTC](https://discuss.elastic.co/t/rum-starttransaction-not-writing-to-apm-server-in-javascript/203140/3 "2019-11-05T06:29:33Z")

</div>

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