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',
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.