All spans not being captured in custom transactions

I am capturing the custom spans for a transaction and storing it in 'Transaction.custom'.
I am using "Thread.getAllStackTraces()" inside "beforeEnd()" function in "co.elastic.apm.agent.impl.transaction.Transaction.java". But in this case some of my spans inside the transactions are not being captured.
In a naïve language, I can say that all classes are not being captured with this.
Please help me I this regard, as I want to capture all the classes for the particular transaction.

Kibana version: 8.5.1

Elasticsearch version: 8.5.1

APM Server version: 8.5.1

APM Agent language and version: Java and 1.x.x

This topic looks very similar to: Want to get interface classes for the current transaction.
I obviously couldn't understand what this is about and how we can assist.
Hopefully someone else can.
Good luck!

Hi,
I was able to capture interfaces, but all the spans are not being captured for their interfaces to get captured.