entry is nil inside rake tasks or rails console

I see error logs
```
Could not log "sql.active_record" event. NoMethodError: undefined method `fields' for nil:NilClass
```

when it is in rails console or in rake task.