How to add uplink metadata to the payload? Eg add 'metadata.data_rate' spreading factor info to my payload

I would like to add to my device payload the metadata information

For later analysis and storage
to see what sensors work best and what spread factor they use for each message,

Is this information available to the ‘function Decoder(bytes, port)’
I am struggling to find an example on how I can do this.

ie. {
“time”: “2019-02-16T07:22:04.3006654Z”,
“frequency”: 923.2,
“modulation”: “LORA”,
“data_rate”: “SF11BW125”,
“coding_rate”: “4/5”,
“gateways”: [
{
“gtw_id”: “newie-ventures-launch”,
“gtw_trusted”: true,
“timestamp”: 2580972788,
“time”: “2019-02-16T07:30:50Z”,
“channel”: 0,
“rssi”: -113,
“snr”: 5.25,
“latitude”: -32.883595,
“longitude”: 151.72795,
“altitude”: 20,
“location_source”: “registry”
}
]
}

Any help appreciated

See Access Metadata in decoder.