Skip to content

ref(browser): Introduce client reports envelope helper #4588

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

Merged
merged 15 commits into from
Feb 25, 2022

Conversation

AbhiPrasad
Copy link
Member

Leverage the new envelope utility functions to construct client report
envelopes sent in the browser transport. This also opens us up to more
easily add client reports to node or other environments.

Resolves https://getsentry.atlassian.net/browse/WEB-625

Dependent on #4587

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2022

size-limit report

Path Base Size (041186e) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.7 KB 19.77 KB +0.38% 🔺
@sentry/browser - ES5 CDN Bundle (minified) 63.31 KB 63.47 KB +0.27% 🔺
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.37 KB 18.44 KB +0.37% 🔺
@sentry/browser - ES6 CDN Bundle (minified) 56.48 KB 56.6 KB +0.22% 🔺
@sentry/browser - Webpack (gzipped + minified) 22.16 KB 22.2 KB +0.19% 🔺
@sentry/browser - Webpack (minified) 76.18 KB 76.36 KB +0.25% 🔺
@sentry/react - Webpack (gzipped + minified) 22.19 KB 22.23 KB +0.21% 🔺
@sentry/nextjs Client - Webpack (gzipped + minified) 46.33 KB 46.4 KB +0.16% 🔺
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 27.15 KB 27.23 KB +0.29% 🔺

@AbhiPrasad AbhiPrasad force-pushed the abhi-envelope-client-reports branch from fc6613d to 424d62d Compare February 16, 2022 00:36
This patch introduces functions that create, mutate and serialize
envelopes. It also adds some basic unit tests that sanity check their
functionality. It builds on top of the work done in
#4527.

Users are expected to not directly interact with the Envelope instance,
but instead use the helper functions to work with them. Essentially, we
can treat the envelope instance as an opaque handle, similar to how void
pointers are used in low-level languages. This was done to minimize the
bundle impact of working with the envelopes, and as the set of possible
envelope operations was fixed (and on the smaller end).

To directly create an envelope, the `createEnvelope()` function was
introduced. Users are encouraged to explicitly provide the generic type
arg to this function so that add headers/items are typed accordingly.

To add headers and items to envelopes, the `addHeaderToEnvelope()` and
`addItemToEnvelope()` functions are exposed respectively. The reason
that these functions are purely additive (or in the case of headers, can
re-write existing ones), instead of allow for headers/items to be
removed, is that removal functionality doesn't seem like it'll be used
at all. In the interest of keeping the API surface small, we settled
with these two functions, but we can come back and adjust this later on.

Finally, there is `serializeEnvelope()`, which is used to serialize an
envelope to a string. It does have some TypeScript complications, which
is explained in detail in a code comment, but otherwise is a pretty
simple implementation. You can notice the power of the tuple based
envelope implementation, where it becomes easy to access headers/items.

```js
const [headers, items] = envelope;
```

To illustrate how these functions will be used, another patch will be
added that adds a `createClientReportEnvelope()` util, and the base
transport in `@sentry/browser` will be updated to use that util.
@AbhiPrasad AbhiPrasad force-pushed the abhi-envelope-functions branch from 518332c to b342328 Compare February 23, 2022 14:18
@AbhiPrasad AbhiPrasad force-pushed the abhi-envelope-client-reports branch from 424d62d to 204b6c4 Compare February 23, 2022 15:07
@AbhiPrasad AbhiPrasad requested review from a team, Lms24 and lobsterkatie and removed request for a team February 23, 2022 17:01
@AbhiPrasad AbhiPrasad added this to the Pre 7.0.0 Work milestone Feb 23, 2022
@AbhiPrasad AbhiPrasad force-pushed the abhi-envelope-client-reports branch from b9333e2 to f603041 Compare February 24, 2022 19:28
Leverage the new envelope utility functions to construct client report
envelopes sent in the browser transport. This also opens us up to more
easily add client reports to node or other environments.
@AbhiPrasad AbhiPrasad force-pushed the abhi-envelope-client-reports branch from f603041 to df8a544 Compare February 24, 2022 19:34
Copy link
Member

@lobsterkatie lobsterkatie left a comment

Choose a reason for hiding this comment

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

👍🏻

Base automatically changed from abhi-envelope-functions to master February 25, 2022 14:16
@AbhiPrasad AbhiPrasad enabled auto-merge (squash) February 25, 2022 14:28
@AbhiPrasad AbhiPrasad merged commit 2e5b0b8 into master Feb 25, 2022
@AbhiPrasad AbhiPrasad deleted the abhi-envelope-client-reports branch February 25, 2022 14:39
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