Problem with using ksm($entity) in hook_entity_insert() As the title states, I've encountered a weird problem with hook_entity_insert():

Array ( [:db_update_placeholder_0] =&gt; 1 [:db_update_placeholder_1] =&gt; 127.0.0.1 [:db_update_placeholder_2] =&gt;


I get a error screen, and this is what's displayed when I attempt to use ksm($entity).  

I also checked the logs: 

Warning: Error while sending QUERY packet. PID=18801 in Drupal\Core\Database\Statement-&gt;execute()....

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away: CREATE TABLE {cache_config}....


This is troubling, as the custom module I'm developing heavily relies on nodes. 

I thought maybe this was an issue with the DB, and so I used a new one, but the problem persist. I'll be attempting to create a new Drupal project using the same modules. 

Therefore I'm asking if anyone else have encountered anything similar to this and found a solution?
Found another post that provides a solution to my problem:
How to preserve kint output upon form submit redirection?

In my case, while 

ksm($entity) 


would display nothing, or show errors, 

ksm($entity-&gt;toArray()) 


seems to display correctly.  

I'm a bit baffled myself why this happens, and will continue to investigate.