Call sentry only when it was set up.

Fixes issue 1727.