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

feat: Remove deps and use Envelope Endpoint #252

Merged
merged 23 commits into from
Aug 13, 2020
Merged

feat: Remove deps and use Envelope Endpoint #252

merged 23 commits into from
Aug 13, 2020

Conversation

HazAT
Copy link
Member

@HazAT HazAT commented Jul 24, 2020

This greatly reduced bundle size and make the minidump upload a bit more robust.

Size of bundle before:
image

Size after:
image

This will become a major version bump because it will only work with on-premise Sentry 20.6.0 or older since we use the envelope endpoint. https://develop.sentry.dev/sdk/envelopes/

@HazAT HazAT self-assigned this Jul 24, 2020
@HazAT HazAT changed the title feat: Remove deps and use Envelope Endpoint for minidumps feat: Remove deps and use Envelope Endpoint Jul 27, 2020
@@ -24,6 +31,26 @@ export class NetTransport extends Transports.BaseTransport {
* @inheritDoc
*/
public async sendEvent(event: Event): Promise<Response> {
const envelopeHeaders = JSON.stringify({
event_id: event.event_id,
sent_at: new Date(timestampWithMs() * 1000).toISOString(),
Copy link
Member

Choose a reason for hiding this comment

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

Would new Date().toISOString() suffice here?

Copy link
Member Author

Choose a reason for hiding this comment

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

timestampWithMs has some internal logic how to get the "initial" clock reading. We use this clock everywhere so I would keep it like that for now.

});
const itemHeaders = JSON.stringify({
content_type: 'application/json',
type: event.type ?? 'event',
Copy link
Member

Choose a reason for hiding this comment

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

event.type can be something like "error" or "default", but those are not valid item types. Probably it's better to put this in a utility function that resembles this logic:

https://github.com/getsentry/relay/blob/69b6bd5d8428ca42583ea2c79846532c473ef782/relay-common/src/constants.rs#L136-L146

type: 'event',
});

const stat = await statAsync(minidumpPath);
Copy link
Member

Choose a reason for hiding this comment

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

You can avoid this stat, since you can simply query for minidumpContent.length below. That will return the binary size of the buffer. That way, you avoid differences between the FS metadata and the file contents, if any.


// Too many requests, so we queue the event and send it later
if (response.status === CODE_RETRY) {
if (response.status === Status.RateLimit) {
Copy link
Member

Choose a reason for hiding this comment

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

Here, we have to make two changes:

  1. On a 429 response, we should never retry.
  2. On top of that, the envelope endpoint may return a 429, even if the event was accepted. Please check the corresponding X-Sentry-Rate-Limits header if a rate limit for the "error" category is supported, and ignore the ones for attachments for now.

We can later follow up with a more nuanced rate limiting logic.

private async _toMinidumpRequest(event: Event, minidumpPath: string): Promise<SentryElectronRequest> {
const envelopeHeaders = JSON.stringify({
event_id: event.event_id,
sent_at: new Date(timestampWithMs() * 1000).toISOString(),
Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth noting that every time you retry a request, you have to generate a new sent_at timestamp. Otherwise, clock drift correction will see an old timestamp and assume your clock is lagging behind.

It seems that you do this correctly, can you confirm? I'd suggest to add a comment at some appropriate place for the future.

@HazAT HazAT merged commit 7afa7c2 into master Aug 13, 2020
@HazAT HazAT deleted the feat/envelopes branch August 13, 2020 08:42
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.

None yet

2 participants