in xray/segment.go [359:400]
func (seg *Segment) Close(err error) {
// If SDK is disabled then return
if SdkDisabled() {
return
}
if seg == nil {
logger.Debugf("No input subsegment to end. No-op")
return
}
seg.Lock()
if seg.parent != nil {
logger.Debugf("Closing subsegment named %s", seg.Name)
} else {
logger.Debugf("Closing segment named %s", seg.Name)
}
seg.EndTime = float64(time.Now().UnixNano()) / float64(time.Second)
seg.InProgress = false
if err != nil {
seg.addError(err)
}
cancelSegCtx := seg.cancelCtx
seg.Unlock()
// If a goroutine was started to close the extra context (made for
// cancelling the segment), stop the goroutine before we close the segment
// and lose access to it.
if cancelSegCtx != nil {
cancelSegCtx()
}
// If segment is dummy we return
if seg.Dummy {
return
}
seg.send()
}