How To: Setting up Sentry with RedwoodJS

I wrote a post about how to set up Sentry with RedwoodJS. Sentry is a service that provides error monitoring for both the frontend and backend. They will catch exceptions and record the stacktraces with context data so that you can debug issues better. Sentry would be useful in Redwood Apps because it helps a lot in debugging issues in production. Sentry would work on the API and web sides and catch any exceptions that occur and alert you when exceptions happen.

I think Sentry is great for any production system. So you should definitely consider using it (or any of its competitors like Rollbar or Honeybadger)!

Hope it can help anybody else who wants to set up Sentry too.

1 Like

@rockymeza thanks so much for adding this! And the article is very helpful.

As someone who was not familiar with Sentry regarding what it is and does (but was delighted to find out about it!), could you add a sentence or two to the topic describing Sentry and how it’s helpful for Redwood Apps, e.g. problem/solution description? I think that would help people find this topic via Search as well as be more interested in reading it.

No pressure either way. And primarily suggesting because I had no idea but think it’s really important/helpful after spending time to dig in further.

:rocket:

@thedavid,

I can no longer edit the original post, but I just wanted to add that Sentry would be useful in Redwood Apps because it helps a lot in debugging issues in production. Sentry would work on the API and web sides and catch any exceptions that occur and alert you when exceptions happen.

I think Sentry is great for any production system. So you should definitely consider using it (or any of its competitors like Rollbar or Honeybadger)!

Hi @rockymeza Try editing the post again and let me know how it goes.

Appreciate this!

I don’t think it will let me edit.

Ah, sorry about that. It’s set to Wiki now if you want to try again. All good either way. Thanks again!

I think @rockymeza means he can’t edit the Medium post, while I think you, @thedavid, wants him to edit the first post in this thread :slight_smile:

1 Like

@Tobbe, no I meant that I couldn’t edit the first post in this thread. However, after @thedavid changed it to wiki mode, I was able to edit the first post in this thread this morning.

3 Likes

Great that you got it sorted, and thanks for writing that article :smiley:

1 Like

Thanks very much @rockymeza this worked for me.

I followed your instructions (using SENTRY_DSN everywhere & adding it to my redwood.toml) and setting SENTRY_DSN instead of SENTRY_AUTH_TOKEN in the .env.

given that it’s React, I safetied the /web init, as you did in the /api usage

  const [sentryInitialized, setSentryInitialized] = React.useState(false)
  if (process.env.SENTRY_DSN && !sentryInitialized) {
    setSentryInitialized(true)
    Sentry.init({
      dsn: process.env.SENTRY_DSN,
    })
  }

However, when I wrap my graphql as suggested all of my relations stop auto including

Very odd…

This code worked before loading a whole pile of relations automatically

  const attendee = await db.attendee.findUnique({ 
    where: { id },
  })
    .then(thenDebug(`[${__file}] attendee ~ db.attendee.findUnique`))
    .catch(logger.error)

I wonder if it has something to do with the redwood object for the table

export const Attendee = {
  event: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).event(),
  user: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).user(),
  answers: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).answers(),
  agreement: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).agreement(),
  guests: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).guests(),
  forwards: (_obj, { root }: ResolverArgs<ReturnType<typeof Attendee>>) =>
    db.attendee.findUnique({ where: { id: root.id } }).forwards(),
};

It’s as if this is no longer used…

Another option for Sentry integration at the GraphQL level is this envelop plug-in: Envelop

Please note, as of Redwood v0.37+ Setting up Sentry is significantly easier using graphql envelop!

Updated guide here: [Guide] Setting up Sentry with Redwood (envelop version)