sentry-electron icon indicating copy to clipboard operation
sentry-electron copied to clipboard

Don't manage to send attachments

Open stoefln opened this issue 3 years ago • 4 comments

  • [x] Review the documentation: https://docs.sentry.io/platforms/javascript/electron/
  • [x] Search for existing issues: https://github.com/getsentry/sentry-electron/issues
  • [x] Use the latest release: https://github.com/getsentry/sentry-electron/releases
  • [x] Provide a link to the affected event from your Sentry account https://sentry.io/organizations/stephan-petzl/issues/3499972015/attachments/?project=1554144&query=is%3Aunresolved

Versions + Platform

Description

I am configuring Sentry like this:

function configure() {
  var consoleError = console.error
  console.error = function() {
    var args = Array.prototype.slice.call(arguments)
    const error = reduceConsoleArgs(args)
    Sentry.configureScope(scope => {
      console.log('configureScope1')
      const runtimeData = getRuntimeData(store)
      scope.addAttachment({ filename: 'context.json', data: JSON.stringify(runtimeData) })
    })
    Sentry.captureException(error, { level: 'error' })
    return consoleError.apply(console, args)
  }
}

Unfortunately no attachment is added to the report. Can somebody give me a hint?

stoefln avatar Aug 13 '22 15:08 stoefln

The docs cover this. You should be using beforeSend: https://docs.sentry.io/platforms/javascript/guides/electron/enriching-events/attachments/#add-or-modify-attachments-before-sending

timfish avatar Aug 14 '22 11:08 timfish

Thanks @timfish, I read and tried that but it didn't work. Yesterday I figured out that I needed to set it up in the main thread instead of the renderer. However, the problem with this is that I don't have the attachment data in my main thread. Is there a way to pass it over? I know about IPC, but there is a timing issue: How would I know WHEN to send the attachment data to the main thread in order to have it available when beforeSend gets executed...?

stoefln avatar Aug 15 '22 05:08 stoefln

With the Electron SDK, all events are sent from the main process. The issue with adding attachments in the renderer is that they will need to be sent over IPC to the main process and this currently uses JSON which will likely have terrible performance sending anything large or binary.

~~On newer versions of Electron (>=v17) we can use structuredClone() instead which will have better performance.~~ This wont work when using the fetch IPC.

timfish avatar Aug 15 '22 09:08 timfish

I don't need to send a lot. Not a problem performance wise. But I still don't know how to get the data sent to the main thread in time so it can be used in "beforeSend"...?

stoefln avatar Aug 15 '22 17:08 stoefln

@timfish I just checked your PR, but unfortunately I can't seem to figure out:

  1. how do I make use of it?
  2. which version of electron/sentry is going to be fixing this issue?

stoefln avatar Jan 09 '23 16:01 stoefln

This hasn't made it into a release yet but once it has, you'll be able to add attachments in beforeSend in the renderers as per the browser docs: https://docs.sentry.io/platforms/javascript/enriching-events/attachments/#add-or-modify-attachments-before-sending

timfish avatar Jan 09 '23 16:01 timfish