Support for transaction parentIds in Elastic Rum agent

Hello Elastic team,

In the context of a web extension, we are using the Elastic RUM agent. We created an agent in both the "FE" of the web extension and in the service worker of the web extension and we would now like to relate the transaction from both processes.

In order to do this, I'm passing the parent id and trace id of the span that I wish to correlate my new transaction with in the service worker. in more concrete details, I'm doing the following:

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
...
transaction.parentId = message.parentId;
transaction.traceId = message.traceId;
...
}

This didn't work out of the box, and I found that it was due to the truncation happening in the performance-monitoring.js file discarding the parent ids, causing them to not be passed onto the APM Server.
To allow for my scenario I added, the parentId mapping, in the file, as such:

id: transaction.id,
trace_id: transaction.traceId,
session: transaction.session,
name: transaction.name,
type: transaction.type,
duration: transaction.duration(),
spans: spans,
context: transaction.context,
marks: transaction.marks,
breakdown: transaction.breakdownTimings,
span_count: {
  started: spans.length
},
sampled: transaction.sampled,
sample_rate: transaction.sampleRate,
experience: transaction.experience,
outcome: transaction.outcome,
**parent_id: transaction.parentId** <- added this line

I believe this to be a welcome change and after testing my use case is solved, but I would like some clarification if this was not done for a particular reason or if there is any limitation that you can see. I see that for other agents this seems to be allowed in conjunction with the traceparent.

Thank you in advance

Hi @pedrogranja,

Welcome! Thanks so much for your detailed response. I had a quick dig in the code and I see what you mean. To confirm, are you recommending this change for method createTransactionModel in the references file? Would this apply to just the created transaction and not the spans?

I did have a quick dig in the repo and can't seem to find an issue or PR covering this topic, or a discussion suggesting a particular reason why this wasn't done. The closest I found was this one on incomplete type definitions having them omitted to ensure distributed tracing didn't break. But I'm not sure if this is the reason.

To get feedback from the engineers on this change, would you be happy to raise a PR or a GitHub issue to discuss the change further?

Hope that helps!

Hello Carly,

yes I confirm it's this method. Pretty sure this only applies for transaction and not span. From my experimentation, this problem only applies to transactions, spans are fine as they are connect by parent id to their parent spans or transactions. In the same file, if you check the span map they are mapping the parent id in spans.

I see, this post is relevant indeed, seems like the engineering team is aware of this change and decided against it because no use case is present. I think it's an interesting discussion to have again since now I do have a use case that needs it for web extensions.

I will open a PR for the discussion then

Thanks for the help!