I have added the javascript agent to a test application as described in the docs:
<script src="https://unpkg.com/@elastic/apm-rum@4.0.1/dist/bundles/elastic-apm-rum.umd.min.js"></script>
<script>
// set up tracing (elastic apm) - see https://www.elastic.co/guide/en/apm/agent/js-base/current/api.html
// TODO find a better place for apm object to live
window.elasticapm = elasticApm.init({
serviceName: 'ui',
//serverUrl: 'http://localhost:30200/proxy',
serverUrl: 'http://maxant.ch:30200',
serviceVersion: 'beta',
logLevel: 'trace',
environment: 'test'
});
window.elasticapm.setUserContext({id: "UserNumber", username: "ant", email: "someaddress@maxant.ch"});
</script>
I've then added the calls to the API in the "controller" of my single page app:
async createClaim(claim) {
const tracingTransaction = window.elasticapm.startTransaction("createClaim", "ui-tx");
try {
await service.createClaim(claim, model.partner.entity.id);
} catch (error) {
window.elasticapm.captureError(error);
model.claims.error = error;
} finally {
tracingTransaction.end();
}
}
The tracing is visible in Kibana, but it doesn't show it as a transaction which is related to further downstream calls. No transaction ID or trace ID is sent from the browser to the backend, so the backend starts a new transaction.
Should the propagation occur automatically, or do I have to do something special? The Javascript object called "service" above, uses the axios library and does this:
function createClaim(form, partnerId) {
return new Promise(function (resolve, reject) {
setTimeout(function(){ // so that demo shows "in progress" message
const claim = {"summary": form.summary, "description": form.description, "partnerId": partnerId, "reserve": form.reserve, "date": form.date.replace(/\//g, "-")};
axios.post(CLAIMS_BASE_URL + 'claims', claim)
.then(function(response) {
if(response.status === 202) {
console.log("claim creation request accepted");
resolve();
} else reject("Unexpected response code " + response.status);
}).catch(function(call) {
console.error("Failed to create claim: " + JSON.stringify(call));
reject("Failed to create claim. See console for details. (" + (call.response?call.response.status:"-") + ")");
});
}, 1000);
});
}
Maybe axios needs to be setup somehow? Altho under the hood it should be using XMLHTTPRequest.
Calls to the events UI are successful. there are no http errors anywhere.
Chrome logs the request which axios makes to the backend as only having these headers:
- Accept: application/json, text/plain, /
- Origin: http://localhost:8083
- Referer: http://localhost:8083/
- User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36
As you can see, there is none with a transaction ID. Backend-to-Backend contains headers like the following to propagate the transaction:
Elastic-Apm-Traceparent
[
"00-62f406aea109c9f76ddcd800f6548a51-ec5a373da6a5d2c0-01"
]
I tried adding the current trace ID to the headers which are sent to the backend, but I still don't see the backend calls as part of the UI transaction when I look at it in kibana apm:
axios.post(CLAIMS_BASE_URL + 'claims', claim, {headers: {"Elastic-Apm-Traceparent": elasticApm.getCurrentTransaction().traceId}})
.then(function(response) {
I noticed that the traceId returned from "getCurrentTransaction" is really short, compared to the example show above from backend-to-backend, e.g. 5f8684e59724df24309ae961395e65b3
I also noticed that the ID returned from getCurrentTransaction().traceId is not the same as the one created when I called elasticapm.startTransaction("createClaim", "ui-tx"); I've tried sending both IDs to the backend, but the timeline of the UI never shows the backend call as part of the transaction.
Is it possible to see a timeline with the UI, and all backends together?
Kibana version:
7.0.0
Elasticsearch version:
7.0.0
APM Server version:
7.0.0
APM Agent language and version:
javascript 4.0.1
Browser version:
chrome 73
Original install method (e.g. download page, yum, deb, from source, etc.) and version:
docker images running in minikube
Fresh install or upgraded from other version?
fresh
Is there anything special in your setup? For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.
ES output
no loadbalancers
no index patterns changed
no custom templates
Errors in browser console (if relevant):
none
Provide logs and/or server output (if relevant):