@firebase/performance 0.7.6-canary.3d44792f1 → 0.7.6-canary.41e3c4cdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.esm2017.js +26 -68
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/services/settings_service.d.ts +0 -1
- package/dist/esm/src/services/transport_service.d.ts +2 -3
- package/dist/index.cjs.js +26 -68
- package/dist/index.cjs.js.map +1 -1
- package/dist/src/services/settings_service.d.ts +0 -1
- package/dist/src/services/transport_service.d.ts +2 -3
- package/package.json +7 -7
package/dist/index.cjs.js
CHANGED
|
@@ -10,7 +10,7 @@ var component = require('@firebase/component');
|
|
|
10
10
|
require('@firebase/installations');
|
|
11
11
|
|
|
12
12
|
const name = "@firebase/performance";
|
|
13
|
-
const version = "0.7.6-canary.
|
|
13
|
+
const version = "0.7.6-canary.41e3c4cdf";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @license
|
|
@@ -331,9 +331,6 @@ class SettingsService {
|
|
|
331
331
|
this.logNetworkAfterSampling = false;
|
|
332
332
|
// TTL of config retrieved from remote config in hours.
|
|
333
333
|
this.configTimeToLive = 12;
|
|
334
|
-
// The max number of events to send during a flush. This number is kept low to since Chrome has a
|
|
335
|
-
// shared payload limit for all sendBeacon calls in the same nav context.
|
|
336
|
-
this.logMaxFlushSize = 40;
|
|
337
334
|
}
|
|
338
335
|
getFlTransportFullUrl() {
|
|
339
336
|
return this.flTransportEndpointUrl.concat('?key=', this.transportKey);
|
|
@@ -621,12 +618,6 @@ function processConfig(config) {
|
|
|
621
618
|
settingsServiceInstance.tracesSamplingRate =
|
|
622
619
|
DEFAULT_CONFIGS.tracesSamplingRate;
|
|
623
620
|
}
|
|
624
|
-
if (entries.fpr_log_max_flush_size) {
|
|
625
|
-
settingsServiceInstance.logMaxFlushSize = Number(entries.fpr_log_max_flush_size);
|
|
626
|
-
}
|
|
627
|
-
else if (DEFAULT_CONFIGS.logMaxFlushSize) {
|
|
628
|
-
settingsServiceInstance.logMaxFlushSize = DEFAULT_CONFIGS.logMaxFlushSize;
|
|
629
|
-
}
|
|
630
621
|
// Set the per session trace and network logging flags.
|
|
631
622
|
settingsServiceInstance.logTraceAfterSampling = shouldLogAfterSampling(settingsServiceInstance.tracesSamplingRate);
|
|
632
623
|
settingsServiceInstance.logNetworkAfterSampling = shouldLogAfterSampling(settingsServiceInstance.networkRequestsSamplingRate);
|
|
@@ -717,9 +708,6 @@ const DEFAULT_SEND_INTERVAL_MS = 10 * 1000;
|
|
|
717
708
|
const INITIAL_SEND_TIME_DELAY_MS = 5.5 * 1000;
|
|
718
709
|
const MAX_EVENT_COUNT_PER_REQUEST = 1000;
|
|
719
710
|
const DEFAULT_REMAINING_TRIES = 3;
|
|
720
|
-
// Most browsers have a max payload of 64KB for sendbeacon/keep alive payload.
|
|
721
|
-
const MAX_SEND_BEACON_PAYLOAD_SIZE = 65536;
|
|
722
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
723
711
|
let remainingTries = DEFAULT_REMAINING_TRIES;
|
|
724
712
|
/* eslint-enable camelcase */
|
|
725
713
|
let queue = [];
|
|
@@ -747,28 +735,13 @@ function dispatchQueueEvents() {
|
|
|
747
735
|
// The staged events will be used for current logRequest attempt, remaining events will be kept
|
|
748
736
|
// for next attempt.
|
|
749
737
|
const staged = queue.splice(0, MAX_EVENT_COUNT_PER_REQUEST);
|
|
750
|
-
const data = buildPayload(staged);
|
|
751
|
-
postToFlEndpoint(data)
|
|
752
|
-
.then(() => {
|
|
753
|
-
remainingTries = DEFAULT_REMAINING_TRIES;
|
|
754
|
-
})
|
|
755
|
-
.catch(() => {
|
|
756
|
-
// If the request fails for some reason, add the events that were attempted
|
|
757
|
-
// back to the primary queue to retry later.
|
|
758
|
-
queue = [...staged, ...queue];
|
|
759
|
-
remainingTries--;
|
|
760
|
-
consoleLogger.info(`Tries left: ${remainingTries}.`);
|
|
761
|
-
processQueue(DEFAULT_SEND_INTERVAL_MS);
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
function buildPayload(events) {
|
|
765
738
|
/* eslint-disable camelcase */
|
|
766
739
|
// We will pass the JSON serialized event to the backend.
|
|
767
|
-
const log_event =
|
|
740
|
+
const log_event = staged.map(evt => ({
|
|
768
741
|
source_extension_json_proto3: evt.message,
|
|
769
742
|
event_time_ms: String(evt.eventTime)
|
|
770
743
|
}));
|
|
771
|
-
const
|
|
744
|
+
const data = {
|
|
772
745
|
request_time_ms: String(Date.now()),
|
|
773
746
|
client_info: {
|
|
774
747
|
client_type: 1, // 1 is JS
|
|
@@ -778,23 +751,29 @@ function buildPayload(events) {
|
|
|
778
751
|
log_event
|
|
779
752
|
};
|
|
780
753
|
/* eslint-enable camelcase */
|
|
781
|
-
|
|
754
|
+
postToFlEndpoint(data)
|
|
755
|
+
.then(() => {
|
|
756
|
+
remainingTries = DEFAULT_REMAINING_TRIES;
|
|
757
|
+
})
|
|
758
|
+
.catch(() => {
|
|
759
|
+
// If the request fails for some reason, add the events that were attempted
|
|
760
|
+
// back to the primary queue to retry later.
|
|
761
|
+
queue = [...staged, ...queue];
|
|
762
|
+
remainingTries--;
|
|
763
|
+
consoleLogger.info(`Tries left: ${remainingTries}.`);
|
|
764
|
+
processQueue(DEFAULT_SEND_INTERVAL_MS);
|
|
765
|
+
});
|
|
782
766
|
}
|
|
783
|
-
|
|
784
|
-
function postToFlEndpoint(body) {
|
|
767
|
+
function postToFlEndpoint(data) {
|
|
785
768
|
const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
|
|
786
|
-
const
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
return Promise.resolve();
|
|
791
|
-
}
|
|
792
|
-
else {
|
|
793
|
-
return fetch(flTransportFullUrl, {
|
|
769
|
+
const body = JSON.stringify(data);
|
|
770
|
+
return navigator.sendBeacon && navigator.sendBeacon(flTransportFullUrl, body)
|
|
771
|
+
? Promise.resolve()
|
|
772
|
+
: fetch(flTransportFullUrl, {
|
|
794
773
|
method: 'POST',
|
|
795
|
-
body
|
|
796
|
-
|
|
797
|
-
|
|
774
|
+
body,
|
|
775
|
+
keepalive: true
|
|
776
|
+
}).then();
|
|
798
777
|
}
|
|
799
778
|
function addToQueue(evt) {
|
|
800
779
|
if (!evt.eventTime || !evt.message) {
|
|
@@ -816,33 +795,12 @@ serializer) {
|
|
|
816
795
|
};
|
|
817
796
|
}
|
|
818
797
|
/**
|
|
819
|
-
* Force flush the queued events. Useful at page unload time to ensure all
|
|
820
|
-
*
|
|
821
|
-
* sendBeacon fails. Firefox
|
|
798
|
+
* Force flush the queued events. Useful at page unload time to ensure all
|
|
799
|
+
* events are uploaded.
|
|
822
800
|
*/
|
|
823
801
|
function flushQueuedEvents() {
|
|
824
|
-
const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
|
|
825
802
|
while (queue.length > 0) {
|
|
826
|
-
|
|
827
|
-
const staged = queue.splice(-SettingsService.getInstance().logMaxFlushSize);
|
|
828
|
-
const body = buildPayload(staged);
|
|
829
|
-
if (navigator.sendBeacon &&
|
|
830
|
-
navigator.sendBeacon(flTransportFullUrl, body)) {
|
|
831
|
-
continue;
|
|
832
|
-
}
|
|
833
|
-
else {
|
|
834
|
-
queue = [...queue, ...staged];
|
|
835
|
-
break;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
if (queue.length > 0) {
|
|
839
|
-
const body = buildPayload(queue);
|
|
840
|
-
fetch(flTransportFullUrl, {
|
|
841
|
-
method: 'POST',
|
|
842
|
-
body
|
|
843
|
-
}).catch(() => {
|
|
844
|
-
consoleLogger.info(`Failed flushing queued events.`);
|
|
845
|
-
});
|
|
803
|
+
dispatchQueueEvents();
|
|
846
804
|
}
|
|
847
805
|
}
|
|
848
806
|
|