CDR - Linking Call Legs Across Transfer

I am just getting to grips with Asterisk, and have all the basics set up (phones, trunks etc).

Now I am moving onto recording call data, and have configured CDR for this. This will be used for a bespoke application I am developing.

I can get all the information I need, and it is logging to MySQL fine, however I have hit an issue in regards to linking calls together.

I have noticed two fields of interest; uniqueid, and linkedid.

What I need is some kind of ID that will link all calls together as they are passed around.

For example:
Jane Smith (1003) calls Jason Rennie (1001) on the switchboard, Jason Rennie puts Jane Smith on hold, announces the call to (1002) Bob Jones, then transfers the call to Bob Jones.

As you can see, this has taken place with the CDR data below:

mysql> select src,dst,clid,channel,dstchannel,start,answer,end,disposition,uniqueid,linkedid from cdr order by start desc;
+------+------+-----------------------+---------------------+---------------------+---------------------+---------------------+---------------------+-------------+---------------+---------------+
| src  | dst  | clid                  | channel             | dstchannel          | start               | answer              | end                 | disposition | uniqueid      | linkedid      |
+------+------+-----------------------+---------------------+---------------------+---------------------+---------------------+---------------------+-------------+---------------+---------------+
| 1003 | 1001 | "Jane Smith" <1003>   | PJSIP/1003-0000000a | PJSIP/1002-0000000d | 2017-10-29 23:05:00 | 2017-10-29 23:05:00 | 2017-10-29 23:05:14 | ANSWERED    | 1509318282.25 | 1509318282.25 |
| 1001 | 1002 | "Jason Rennie" <1001> | PJSIP/1001-0000000c | PJSIP/1002-0000000d | 2017-10-29 23:04:52 | 2017-10-29 23:04:52 | 2017-10-29 23:05:00 | ANSWERED    | 1509318292.27 | 1509318292.27 |
| 1003 | 1001 | "Jane Smith" <1003>   | PJSIP/1003-0000000a | PJSIP/1001-0000000b | 2017-10-29 23:04:42 | 2017-10-29 23:04:42 | 2017-10-29 23:05:00 | ANSWERED    | 1509318282.25 | 1509318282.25 |
+------+------+-----------------------+---------------------+---------------------+---------------------+---------------------+---------------------+-------------+---------------+---------------+
3 rows in set (0.00 sec)

I see that uniqueid is the same for leg 1 and leg 3, but not leg 2. Also, linkedid seems redundant in all legs as it is the same as the uniqueid?
Fair enough, I am able to link the first, and last call, but I would like to also add into the mix the part of the call in the middle.
Although I have noticed that it’s also not so easy to see the call between Jane and Bob (src, dst).

Is there any way to achieve what I want to do?
Have I misconfigured something?
Is there some kind of limitation in PJSIP?
Could I do something in the dialplan using variables instead?

All help appreciated.

Use CEL instead of the CDR, to track a the channel https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=5242932

This is talked about in the specification[1]. The suggestion there is to use something else (like the channel names) to link that to know.

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+CDR+Specification#Asterisk12CDRSpecification-SIPProtocolAttendedTransfer