-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(core): Introduce New Transports API #4716
Conversation
size-limit report
|
58eec6a
to
a4fc0b3
Compare
a4fc0b3
to
f0b49b4
Compare
packages/core/src/transports/base.ts
Outdated
|
||
export type TransportMakeRequestResponse = { | ||
body?: string; | ||
headers?: Record<string, string | null>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debating if I need to make the rate limiting headers mandatory here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I read through the PR I instinctively asked myself the same thing. In my very uneducated opinion it should be non-optional.
Also: Is there a reason we allow null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I will change this to be non-optional
We allow null
because most getters for headers return null if not defined. For example, https://developer.mozilla.org/en-US/docs/Web/API/Headers/get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good as far as I can tell. Checked out the branch and ran the tests. I just left a comment on the rate limit tests. Although, with our conversation from earlier in mind, feel free to ignore it if you want.
const retryAfterSeconds = 10; | ||
const beforeLimit = Date.now(); | ||
const withinLimit = beforeLimit + (retryAfterSeconds / 2) * 1000; | ||
const afterLimit = beforeLimit + retryAfterSeconds * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: Since these variables are identical in 5 tests, I think it would make sense to extract them into a helper function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the API - super clean! I left some comments on naming and a potential small bug (?). The tests also look great.
packages/core/src/transports/base.ts
Outdated
|
||
export type TransportMakeRequestResponse = { | ||
body?: string; | ||
headers?: Record<string, string | null>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I read through the PR I instinctively asked myself the same thing. In my very uneducated opinion it should be non-optional.
Also: Is there a reason we allow null
?
In the spirit of moving fast, I'm going to merge this in and start work on the client side stuff. We can make improvements to this later on. |
Part 1 of #4660
Supercedes #4662
This PR introduces a functional transport based on what was discussed in #4660.
The transport is defined by an interface, which sets two basic functions,
send
andflush
, which both interact directly with an internalPromiseBuffer
data structure, a queue of requests that represents the data that needs to be sent to Sentry.send
relies on an externally definedmakeRequest
function (that is passed into amakeTransport
constructor) to make a request, and then return a status based on it. It also updates internal rate-limits according to the response frommakeRequest
. The status will be also used by the client in the future for client outcomes (we will extract client outcomes from the transport -> client because it living in the transport is not the best pattern).send
takes in an envelope, which means that for now, no errors will go through this transport when we update the client to use this new transport.flush
, flushes the promise buffer, pretty much how it worked before.To make a custom transport (and how we'll be making fetch, xhr transports), you essentially define a
makeRequest
function.^^ Look how clean that is!!
Resolves https://getsentry.atlassian.net/browse/WEB-662