getsentry / sentry

Developer-first error tracking and performance monitoring
https://sentry.io
Other
39.05k stars 4.19k forks source link

showReportDialog not possible to override comments and have empty email #14682

Open mackelito opened 5 years ago

mackelito commented 5 years ago

Package + Version

Version:

5.2.0

Description

Not possible to set all values

`

<script>
  Sentry.init({
    dsn: 'https://ed58eb2eff024a25bc01ca28831053fd@sentry.io/1456805',
    beforeSend(event, hint) {
      // Check if it is an exception, and if so, show the report dialog
      if (event.exception) {
        Sentry.showReportDialog({
          eventId: event.event_id,
          lang: 'sv', //Swedish does not seem to exist?
          title: 'Hoppas något gick visst fel!',
          subtitle: 'Vi behöver din hjälp för att lösa problemt',
          subtitle2: '',
          labelName: 'Namn',
          name: ' ',
          labelEmail: 'Epost',
          email: ' ', // Not possible to have blank/placeholder
          labelComments: 'Hur uppstod felet?',
          comments: 'Försök beskriva stegen innan detta fönster visades?', // NOT WORKING
          labelClose: 'Stäng',
          labelSubmit: 'Skicka',
          errorGeneric: 'Ett okänt fel uppstod när du skickade in din rapport. Vänligen försök igen.',
          errorFormEntry: 'Har du fyllt i all rödmarkerade fält?.',
          successMessage: 'Tack så mycket för din hjälp!'
        });
      }
      return event;
    }
  });
</script>`
BYK commented 3 years ago

Ping @getsentry/team-webplatform for triage

lobsterkatie commented 3 years ago

This is actually a django issue. The problem is that name, email, and comments are all baked into the modal rather than being context variables one can set. See https://github.com/getsentry/sentry/blob/86fed44b9edffcd4a6f2398368ba4e4a0112e05e/src/sentry/web/frontend/error_page_embed.py#L49-L58.

It's also the backend that actually puts it all together and passes it off to the front end, see

https://github.com/getsentry/sentry-javascript/blob/478af3a5ccaad4eb1b7a22f56e0592fe90dd5d2c/packages/browser/src/helpers.ts#L207

and https://github.com/getsentry/sentry/blob/86fed44b9edffcd4a6f2398368ba4e4a0112e05e/src/sentry/web/frontend/error_page_embed.py#L193-L227. So I don't think there's much we can do on the SDK side.

(In case this is useful to whoever ends up handling this, there's actually already a JIRA ticket (FEEDBACK-284) about it, which I made a while back while doing prod support.)

constgen commented 2 years ago

Try to pass them namespaced with user

user: {
   email: " ",
   name: " "
},
paolosanchi commented 1 year ago

This worked for me, just add an onLoad handle and replace the placeholder value

    Sentry.showReportDialog({
     [...]
      onLoad: () => {
        const elem = document.querySelector(".sentry-error-embed");
        elem.querySelector("input[name='name']").attributes["placeholder"].value = 'ciao';
        elem.querySelector("input[name='email']").attributes["placeholder"].value = 'ciao';
        elem.querySelector("textarea[name='comments']").attributes["placeholder"].value = 'ciao';
      }
    });