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: Breadcrumbs added on forked context are now captured #629

Closed
wants to merge 11 commits into from

Conversation

lucas-zimerman
Copy link
Collaborator

@lucas-zimerman lucas-zimerman commented Apr 17, 2024

This PR brings more native context data to be synced with captured events and also allows hint breadcrumbs to be properly registered, for example:

    Sentry.captureException(new Error(`${Date.now()}: a test error occurred`), (context) => {
      return context.addBreadcrumb({ message: 'test' });
    });

will now be registered on the event, including the native events:
image

Additional notes on the PR:

  • No Required changes were needed to support it on iOS.
  • Android had an required refactor in order to capture Envelopes no longer by files.
  • some iOS specific properties are now working with both Android and iOS
  • Improved the device context sync on both Android and iOS.

Closes #263

@lucas-zimerman lucas-zimerman changed the title Fix: Merge breadcrumbs from envelope with native breadcrumbs. Fix: Breadcrumbs added on hints are now captured Apr 17, 2024
…version. Added tests. used a better name for the new function that joins two groups of breadcrumbs. Removed comment from java layer. Removed duplicated tests on the wrapper test file
@lucas-zimerman lucas-zimerman marked this pull request as ready for review April 18, 2024 21:16
@lucas-zimerman lucas-zimerman changed the title Fix: Breadcrumbs added on hints are now captured Fix: Breadcrumbs added on forked context are now captured Apr 18, 2024
* @param nativeList The second group of breadcrumbs from the native layer.
* @returns An array of unique breadcrumbs merged from both lists.
*/
private _mergeUniqueBreadcrumbs(jsList: Breadcrumb[], nativeList: Breadcrumb[]): Breadcrumb[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding test for this method, it makes it super easy to understand how it would behave.

m: I'm not sure if we can be sure that the breadcrumbs are in the same order in both arrays.

If I'm looking at the correctly in case they would not be in the same order the duplicates would not be removed. Creating possible double the size.

We should also respect the maxBreadcrumbs size.

}
});

describe('Device Context Breadcrumb filter', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test like this would not pass, but from the code I understand that the breadcrumbs should always be ordered the same in both arrays?

I think we should add this test so it's clear in the future we were aware of what happens in this situation. And also keep maxBreadcrumbs.

const jsList = [
  { timestamp: 2, message: 'new js' },
  { timestamp: 1, message: 'new js' },
  { timestamp: 3, message: 'new js' },
  { timestamp: 4, message: 'new js' },
] as Breadcrumb[];
const nativeList = [
  { timestamp: 2, message: 'new native' },
  { timestamp: 1, message: 'new js' },
  { timestamp: 2, message: 'new js' },
  { timestamp: 3, message: 'new native' },
  { timestamp: 4, message: 'new native' },
] as Breadcrumb[];

}
});

describe('Device Context Breadcrumb filter', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add test for user set timeout. Something like this:

const jsList = [
  { timestamp: 2, message: 'new js' },
  { timestamp: 1, message: 'new js' },
] as Breadcrumb[];
const nativeList = [
  { timestamp: 2, message: 'new native' },
  { timestamp: 2, message: 'new js' },
  { timestamp: 1, message: 'new js' },
  { timestamp: 3, message: 'new native' },
] as Breadcrumb[];
const expected = [
  { timestamp: 2, message: 'new native' },
  { timestamp: 2, message: 'new js' },
  { timestamp: 1, message: 'new js' },
  { timestamp: 3, message: 'new native' },
] as Breadcrumb[];

Comment on lines -271 to -273
if (!this.isNativeClientAvailable()) {
throw this._NativeClientError;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

@@ -316,22 +310,9 @@ export const NATIVE = {
// @ts-ignore Android still uses the old message object, without this the serialization of events will break.
event.message = { message: event.message };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be execute only for Android.

Copy link
Contributor

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Breadcrumb filters
2 participants