Log errors in production

I would like to just log errors that happens in elm during production, e.g. when it doesn’t receive something in the correct format etc. How can I do this? Either to a file or another system like Rollbar, Timber or Sentry? At the moment I have started to look into having a separate endpoints that just sends a requests back to the backend, but this would involve adding a lot of lines in most files, since I would also have to create an update that receive the response (but does nothing with it).

If logging error is an outgoing Port Cmd Msg, then it should be quite lightweight (in terms of elm code) just stick it at the end of update; fire and forget?

3 Likes

Thank you! That worked.

1 Like

We use Sentry.

In addition to ports, we use window.addEventListener("error", function() { ... }) for runtime errors. Some of those are caused by Debug.todo (which we use also in production by not using --optimize) and others are caused by unexpected behavior of elm (which includes interruption by browser extensions).

2 Likes

at NoRedInk we use rollbar, and have made a wrapper so we don’t have to use ports for it: https://package.elm-lang.org/packages/NoRedInk/elm-rollbar/latest/Rollbar

The docs are not great, sorry! scoped has an example if you’re interested. :slight_smile:

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.