I am using Lambda. I want to send a subsegment to Xray with an custom end_time. Xray is enabled in my Lambda.
When I use the aws-xray-sdk-core and addNewSubsegment('postgres') I do not find the possibility to add an end_time. It looks like the end_time is being set when you close() the Segment.
To try and solve this limitation I base myself on the following to send a custom segment to the Xray Daemon using UDP. Use UDP to send segment to XRay
Below code is not sending a SubSegment to Xray. I am not receiving any errors when sending the segment with client.send(...).
Does someone knows more about this limitation of setting an custom end_time/ knows if it's possible with UDP inside a Lambda?
import AWSXRay from 'aws-xray-sdk-core'
const traceDocument = {
trace_id,
id: generateRandomHex(16),
name: 'postgres',
start_time,
end_time,
type: 'subsegment',
parent_id,
sql: { sanitized_query: query },
}
const client = createSocket('udp4')
const udpSegment = `{"format": "json", "version": 1}\n${traceDocument}`
client.send(udpSegment, 2000, '127.0.0.1', (e, b) => {
console.log(e, b)
})
flush()command which seems to send the subsegment without setting the end_time. Lets say the documentation is scarce and I had to look into the sdk itself to figure out what was happening. - Lucasz