Distributed Tracing question about how to implement

Hi James,

As you already figured out, custom transactions does not support automatic instrumentations (XHR, Fetch, Resources) which means the user would have to start span and attach it to the transaction manually.

And yes by setting { managed: true } in the startTransaction option the transaction would be managed automatically which means the transaction would end as soon as current tasks(api calls) are done.

  1. However you can hold of the current managed transaction from closing by adding a task and removing the task when you want to end the transaction.
const tr = apm.startTransaction('custom', 'custom', { managed: true })

const id = tr.addTask();
// the above call would make sure the transaction cannot be automatically ended till all scheduled tasks are done. 


// remove task once you are done instrumenting
tr.removeTask(id)

tr.end()

By this way, you are in full control of the transaction plus also you get the benefits of instrumenting other parts of code.

  1. Since the above solution is not what we would like for a custom transaction, we would expose an API in the next versions to allow users to inject headers for the custom transactions/spans to make the DT work as intended. created an issue for the same - https://github.com/elastic/apm-agent-rum-js/issues/468

Thanks for the feedback and detailed info.

Cheers,
Vignesh