function endAndRestoreSegment(shim, { request, error }) {
  const { config } = shim.agent
  const activeSegment = request[symbols.segment]
  const parentSegment = request[symbols.parentSegment]
  const tx = request[symbols.transaction]
  if (activeSegment) {
    activeSegment.end()
  }

  if (error && tx && config.feature_flag.undici_error_tracking === true) {
    handleError(shim, tx, error)
  }

  if (parentSegment) {
    shim.setActiveSegment(parentSegment)
  }
}
Gets the active segment, parent segment and transaction from given ctx(request, client connector)
and ends segment and sets the previous parent segment as the active segment.  If an error exists it will add the error to the transaction

@param {Shim} shim instance of shim
@param {object} params object from undici hook
@param {object} params.request or client connector
@param {Error} params.error error from undici request