Add shard_id to record, and add error logging in thread