Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(event): Message event contains stacktrace if attachStacktrace o… #2577

Merged
merged 4 commits into from
Oct 31, 2022

Conversation

krystofwoldrich
Copy link
Member

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Theoretically only passing the option to the browser client should solve the problem. But for some unexplainable reason, the frames are always an empty array, if the synthetic error is not passed from the RN JS code.

function eventFromString(
  stackParser,
  input,
  syntheticException,
  attachStacktrace,
) {
  const event = {
    message: input,
  };
  let frames;
  if (attachStacktrace && syntheticException) {
    frames = parseStackFrames(stackParser, syntheticException); // 29 frames parsed
    if (frames.length) {
      console.log('frames:', frames, frames.length); //frames: Array(29) 29 Array(29)
      event.exception = {
        values: [{ value: input, stacktrace: { frames } }],
      };
    }
  }

  console.log('event with stack', event, frames);//event with stack Object Array(29)
  //but event.exception.values[0].stacktrace.frames is Array(0)
}

Code from JS SDK.
https://github.com/getsentry/sentry-javascript/blob/e1d43ebb34086605aefb9243fce03fc97425b4be/packages/browser/src/eventbuilder.ts#L276

💡 Motivation and Context

Fixes: #2131

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • No breaking changes

🔮 Next steps

src/js/sdk.tsx Outdated Show resolved Hide resolved
@krystofwoldrich krystofwoldrich marked this pull request as ready for review October 28, 2022 08:43
@krystofwoldrich krystofwoldrich requested review from a team, lforst, Lms24 and AbhiPrasad and removed request for a team October 28, 2022 08:43
@marandaneto
Copy link
Contributor

@krystofwoldrich I lack context here, didn't agree on fixing this on JS? getsentry/sentry-javascript#6038

@krystofwoldrich
Copy link
Member Author

@marandaneto

Yes, we will fix the JS part, but besides that, there was an option missing in RN.

But after adding this option the stack trace is still missing when captureMessage is called thru the hub. The example code from the description shows what goes wrong. But I don't know why.

@marandaneto
Copy link
Contributor

@marandaneto

Yes, we will fix the JS part, but besides that, there was an option missing in RN.

But after adding this option the stack trace is still missing when captureMessage is called thru the hub. The example code from the description shows what goes wrong. But I don't know why.

Gotcha, I'd expect this change to be part of #2461 and not #2131
Why do we have its own captureMessage? isn't already defined in the JS SDK?

@krystofwoldrich
Copy link
Member Author

@marandaneto I can split it into two PRs, first "enable stack trace by default" and the second this one.

When we use the captureMessage defined by the JS SDK the stacktrace.frames disappear. When we use hub.captureMessage the stacktrace.frames also disappear.

Only when calling the hub.client.captureMessage the stacktrace.frames stay.

This is some extreme magic, but at least we are not blocked by it when calling the method on the client directly.

The issue happens in eventFromString function from the JS SDK. The following code example shows what we tried with @AbhiPrasad but still no luck the frames keep disappearing.

function eventFromString(
  stackParser,
  input,
  syntheticException,
  attachStacktrace,
) {
  const event = {
    message: input,
  };

  console.log('syntheticException', syntheticException);
  if (attachStacktrace && syntheticException) {
    const frames = parseStackFrames(stackParser, syntheticException); # frames.length > 0
    if (frames.length) {
      console.log('frames', frames);
      console.log('stacktrace', {stacktrace: { frames }});
      console.log('values', [{ value: input, stacktrace: { frames } }]);
      console.log('exception', {
        values: [{ value: input, stacktrace: { frames } }],
      });
      console.log('event.exception before', event.exception); # till here everything works as expected, frames are present 
      event.exception = {
        values: [{ value: input, stacktrace: { frames, my_frames: frames } }],
      };
      event.super_long_name_12345678 = {
        values: [{ value: input, stacktrace: { frames } }],
      };
      console.log('event.exception', event.exception); # event.exception.values.stacktrace.frames = []
      #  event.exception.values.stacktrace.my_frames = [the correct frames]
      #  event.super_long_name_12345678.values.stacktrace.frames = [the correct frames]
    }
  }

  console.log('event_final', event);
  return event;
}

@AbhiPrasad
Copy link
Member

This is the weirdest bug I've seen in a loooong time.

As discussed with @krystofwoldrich we probably want to address the bug like so:

  1. merge this PR (or if we split this up, it's parts) to unblock users and get it working
  2. validate that this is not happening for regular browser JS
  • if it is happening, we need to investigate further on the JS team
  1. create a minimal reproduction for react native that just shows the broken functionality and file a ticket with React Native directly to see what is happening

@marandaneto
Copy link
Contributor

This is the weirdest bug I've seen in a loooong time.

As discussed with @krystofwoldrich we probably want to address the bug like so:

  1. merge this PR (or if we split this up, it's parts) to unblock users and get it working
  2. validate that this is not happening for regular browser JS
  • if it is happening, we need to investigate further on the JS team
  1. create a minimal reproduction for react native that just shows the broken functionality and file a ticket with React Native directly to see what is happening

Ok, that makes sense, I just lacked the context around this and the ingestion.

@krystofwoldrich
Copy link
Member Author

krystofwoldrich commented Oct 31, 2022

Thank you @AbhiPrasad and @marandaneto

So the bug is caused by DebugSymbolicator

So I think this can be reviewed and merged since in production the stack frames will be sent correctly.

For #2461 I will create a new PR that will merge to 5.0.0 branch.

@marandaneto
Copy link
Contributor

Thank you @AbhiPrasad and @marandaneto

So the bug is caused by DebugSymbolicator

So I think this can be reviewed and merged since in production the stack frames will be sent correctly.

For #2461 I will create a new PR that will merge to 5.0.0 branch.

This still depends on the JS SDK bump, after the other PR, right?

@krystofwoldrich
Copy link
Member Author

Thank you @AbhiPrasad and @marandaneto
So the bug is caused by DebugSymbolicator
So I think this can be reviewed and merged since in production the stack frames will be sent correctly.
For #2461 I will create a new PR that will merge to 5.0.0 branch.

This still depends on the JS SDK bump, after the other PR, right?

The JS SDK bump will move the stack traces from exceptions to threads, but from sentry.io user perspective it will start working right away after merging this.

@krystofwoldrich krystofwoldrich merged commit 1db4acc into main Oct 31, 2022
@krystofwoldrich krystofwoldrich deleted the fix-missing-message-stacktrace branch October 31, 2022 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

captureMessage on Android using attachStacktrace=true does not send the stacktrace
3 participants