-
Notifications
You must be signed in to change notification settings - Fork 153
Some custom spans not included in payload in Angular + @elastic/apm-rum #1648
Description
I’m integrating @elastic/apm-rum manually into an Angular app to track custom transactions and spans. I’m not using apm-rum-angular.
I’ve noticed that under certain conditions, some spans or even the transaction itself are not sent to the APM server, even though console logging shows that they were created and ended properly.
async function doSomething(transaction: Transaction) {
const spanA = transaction?.startSpan('SpanA');
let result: any;
try {
result = await callA(); // some async call
} finally {
spanA?.end();
console.log('spanA', spanA);
}
if (result && result.value === 'true') {
const spanB = transaction?.startSpan('SpanB');
try {
await callB(); // some other async call
} finally {
spanB?.end();
console.log('spanB', spanB);
}
}
transaction?.end();
console.log('transaction', transaction);
}Observed behavior
I’ve added an apm.addFilter() to log the payload before it’s sent to the APM server, so I can confirm what data is actually being transmitted.
- Logging always occurs in order: spanA, spanB, transaction.
- spanA and spanB’s parentId matches the transaction ID.
- If the condition passes (result.value === 'true'), the transaction is sent to APM but only includes spanB.
- If the condition does not pass, spanA logs correctly, but the transaction is not sent at all; no errors appear in DevTools.
- Making spanA blocking causes spanB to be undefined and the transaction is never sent.
Expected behavior
All spans and transactions that are started and ended should appear in the APM server payload, regardless of conditional logic.
Question
Has anyone seen similar behavior with conditional spans? Could there be a timing issue with ending spans before a transaction?