How do I get "dialled digits" after an originate

Using Aster* 11.15

Am doing an originate in the dialplan
the destination is nominated in the channel parameter (I have made calls to a local and in a separate test over sip channel - eg SIP/trunk-cpe2/1234 - dial plan code below)
the “extn” part of the originate is a local device in the same context as the originate.
The calls work ok -
Afer connection the extn does a monitor. this works ok too

I want the monitor recording file name to contain the “dialled digits”, or some identifier of the call’s destination
I have tried a number of channel variables like ${DIALEDPEERNUMBER} and ${CALLERID(dnid)}.
these do not work. How can I get the calls destination detains from the extn? and can it be generic, so it will work when calls are made over PRI too?

Setting a variable containing the destination details at the point of the originate is an option (even easier hen I move the originate to the AMI), but surely this info is already in there some where?



exten => mon,1,noop()
exten => mon,n,Answer()
exten => mon,n,sendDTMF(1)
exten => mon,n,verbose(${DIALEDPEERNUMBER})
exten => mon,n,verbose(${CALLERID(num)})
exten => mon,n,verbose(${CALLERID(dnid)})
exten => mon,n, Monitor(wav,testrecord) ; change to provide file name containing destination details
exten => mon,n,wait(100)
exten => mon,n,Hangup()

From what I can tell looking at the Asterisk code/function call chain
the call to originate (dialplan and AMI) gets to channel.c in the function

__ast_request_and_dial(const char *type, … const char *addr,…

where the type and addr would be found in the original originate channel as
originate (type/addr,…

so for instance
type ="SIP"
addr = “trunk-cpe2/1234”

but this addr does not get stored generically at the channel level.

later on in __ast_request_and_dial a cdr is created and initialised but the cdr(dst) is set to the extn value and not the addr !!!
This implies that cdr is suited to the storing of call data for inbound calls. For outbound calls it actually stores the originating exten as the cdr(dst)…if this is correct then this is a significant gap in Asterisk. Even TAPI - 20 years ago - had simple and consistent access to destination information.