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(utils): Fix envelope parsing edge cases #13191

Closed
wants to merge 18 commits into from

Conversation

BYK
Copy link
Member

@BYK BYK commented Aug 2, 2024

This PR backports the new envelope parser in getsentry/spotlight#447 as it fixes some edge cases that the current parser does not handle. This covers binary payloads and implicit ending with EOF and line endings, and empty envelopes. The PR also adds test cases for all these and more.

This PR backports the new envelope parser in getsentry/spotlight#447 as it fixes some edge cases that the current parser does not handle. This covers binary payloads and implicit ending with EOF and line endings, and empty envelopes. The PR also adds tests cases for all these and more.
Comment on lines +183 to +189
// data sanitization
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (itemHeader.type && typeof itemPayload === 'object') {
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// @ts-expect-error -- Does not like assigning to `type` on random object
itemPayload.type = itemHeader.type;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The root of all the test changes with type: 'event' or type: 'span' etc is this. I assumed Spotlight was the correct one here and all events should have a proper type that said in many places, we assume error events to not have any type.

I feel like an explicit type is important so even if this implementation is not correct, we should have a default event type like 'event' or 'error'.

Anyway, I'll leave this to the reviewers and will address change requests accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

h: I wouldn't do this because we use parseEnvelope in all our tests to assert on what exactly our SDK sends to Sentry. Adding fields that were not included in the envelope when it was serialized by the SDK would be really confusing.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Would you mind elaborating what concrete edge case this fix fixes?

I might be missing some context but generally, Spotlight's envelope parsing logic needs to handle envelopes from all SDKs while the JS SDK's parseEnvelope function only handles JS SDK-sent envelopes.

That being said, if there's a bug in the logic, I'm happy to merge a fix.

For some context, we use this function

  • in the SDK's optional offlineTransport (code), meaning it is used in production code
  • in various E2E and integration tests for us to check what exactly we send to Sentry.
    • That's also why I want to avoid adding fields during parsing that are not present beforehand.

@@ -79,6 +79,7 @@ sentryTest(
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
trace_id: traceId,
type: 'span',
Copy link
Member

Choose a reason for hiding this comment

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

h: We should not add this field to standalone span envelopes.

@@ -119,7 +119,7 @@ sentryTest('error after navigation has navigation traceId', async ({ getLocalTes
await page.locator('#errorBtn').click();
const [errorEvent, errorTraceHeader] = await errorEventPromise;

expect(errorEvent.type).toEqual(undefined);
expect(errorEvent.type).toEqual('event');
Copy link
Member

Choose a reason for hiding this comment

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

h: let's not change this please unless there's a good reason to (is there?). So far, sending error events without a type worked well.

@@ -3,7 +3,7 @@ import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';

test('sends an error', async ({ page }) => {
const errorPromise = waitForError('ember-classic', async errorEvent => {
return !errorEvent.type;
return errorEvent.type !== 'transaction';
Copy link
Member

Choose a reason for hiding this comment

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

m: I don't think this change is correct because event.type could be a lot more than 'transaction' or undefined. However, it probably doesn't matter because waitForError already checks for type === undefined before even invoking the callback :)

Comment on lines +183 to +189
// data sanitization
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (itemHeader.type && typeof itemPayload === 'object') {
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
// @ts-expect-error -- Does not like assigning to `type` on random object
itemPayload.type = itemHeader.type;
}
Copy link
Member

Choose a reason for hiding this comment

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

h: I wouldn't do this because we use parseEnvelope in all our tests to assert on what exactly our SDK sends to Sentry. Adding fields that were not included in the envelope when it was serialized by the SDK would be really confusing.

Copy link
Member

Choose a reason for hiding this comment

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

m: I don't think we should test against payloads from other language SDKs. parseEnvelope is used in the JS SDK and it only needs to work with JS SDK-sent events.

@BYK
Copy link
Member Author

BYK commented Aug 5, 2024

Scrapping this PR as the decision is to keep the @sentry/utils parser specific to JS SDKs where the edge cases this fixes does not matter.

@BYK BYK closed this Aug 5, 2024
@BYK BYK deleted the byk/fix/envelope-parsing branch August 5, 2024 11:09
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.

2 participants