Add an emitter and event store interface in the tracker core to be used both by the browser and node trackers and use fetch API for making requests (close #1076) - #1337
Merged
Conversation
…ed both by the browser and node trackers and use fetch for making requests
Matus Tomlein (matus-tomlein)
requested review from
Greg Leonard (greg-el),
Peter Perlepes (igneel64) and
Jethro Nederhof (jethron)
August 20, 2024 10:26
BundleMonFiles added (6)
Total files change +106.18KB 0% Final result: ✅ View report in BundleMon website ➡️ |
Jethro Nederhof (jethron)
left a comment
Contributor
There was a problem hiding this comment.
Awesome changes! Mostly LGTM, just a few things.
… tracker initialization
…setting before adding to event store
…out so they are non-blocking
Matus Tomlein (matus-tomlein)
requested a review
from Jethro Nederhof (jethron)
August 28, 2024 15:24
Jethro Nederhof (jethron)
approved these changes
Aug 29, 2024
Contributor
There was a problem hiding this comment.
LGTM. Appropriately epic PR for 1337, great work!
(Pretty sure tests just need to be more async friendly because it's a whole new task rather than microtask:)
it('should fire on a successful request', async () => {
const callbacks: EventBatch[] = [];
- const onSuccess = (e: EventBatch) => {
- callbacks.push(e);
- };
- const postQueue = createQueue({ method, onSuccess });
- await postQueue.enqueueRequest(request);
+ await new Promise<void>(async (resolve) => {
+ const onSuccess = (e: EventBatch) => {
+ callbacks.push(e);
+ resolve();
+ };
+
+ const postQueue = createQueue({ method, onSuccess });
+ await postQueue.enqueueRequest(request);
+ });
expect(requests).toHaveLength(1);
expect(eventStore.addCount()).toEqual(1);
Contributor
Author
|
Thanks a lot for the in depth review Jethro Nederhof (@jethron), that was super helpful! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces the
XMLHttpRequestAPI in the browser tracker and the got library in the Node tracker with the fetch API in order to make requests to the collector using a common code base.The changes are:
Emitterin the tracker-core for making requests to the collector. This is used both by the Web and Node trackers.EventStoreinterface including an in-memory implementation in the tracker-core. On top of this, the Web trackers implement a local storage based event store. The Node tracker uses the tracker-core implementation.The new
EmitterandEventStoreinterfaces are Promise-based so can be used to await when the events are stored or sent to the collector. I didn't change any outward facing Web tracker APIs to expose the promises, we can consider that though.There are various breaking changes, I'll need to make a full list and publish in docs.
As part of the work, I also had to update the Node.JS version used for the build – I set the supported versions to
>=18.0.0 <25.0.0.