@firebase/performance 0.7.6-canary.8072572f9 → 0.7.6-canary.86155b3c8

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.
@@ -6,7 +6,7 @@ import { Component } from '@firebase/component';
6
6
  import '@firebase/installations';
7
7
 
8
8
  const name = "@firebase/performance";
9
- const version = "0.7.6-canary.8072572f9";
9
+ const version = "0.7.6-canary.86155b3c8";
10
10
 
11
11
  /**
12
12
  * @license
@@ -327,9 +327,6 @@ class SettingsService {
327
327
  this.logNetworkAfterSampling = false;
328
328
  // TTL of config retrieved from remote config in hours.
329
329
  this.configTimeToLive = 12;
330
- // The max number of events to send during a flush. This number is kept low to since Chrome has a
331
- // shared payload limit for all sendBeacon calls in the same nav context.
332
- this.logMaxFlushSize = 40;
333
330
  }
334
331
  getFlTransportFullUrl() {
335
332
  return this.flTransportEndpointUrl.concat('?key=', this.transportKey);
@@ -617,12 +614,6 @@ function processConfig(config) {
617
614
  settingsServiceInstance.tracesSamplingRate =
618
615
  DEFAULT_CONFIGS.tracesSamplingRate;
619
616
  }
620
- if (entries.fpr_log_max_flush_size) {
621
- settingsServiceInstance.logMaxFlushSize = Number(entries.fpr_log_max_flush_size);
622
- }
623
- else if (DEFAULT_CONFIGS.logMaxFlushSize) {
624
- settingsServiceInstance.logMaxFlushSize = DEFAULT_CONFIGS.logMaxFlushSize;
625
- }
626
617
  // Set the per session trace and network logging flags.
627
618
  settingsServiceInstance.logTraceAfterSampling = shouldLogAfterSampling(settingsServiceInstance.tracesSamplingRate);
628
619
  settingsServiceInstance.logNetworkAfterSampling = shouldLogAfterSampling(settingsServiceInstance.networkRequestsSamplingRate);
@@ -713,9 +704,6 @@ const DEFAULT_SEND_INTERVAL_MS = 10 * 1000;
713
704
  const INITIAL_SEND_TIME_DELAY_MS = 5.5 * 1000;
714
705
  const MAX_EVENT_COUNT_PER_REQUEST = 1000;
715
706
  const DEFAULT_REMAINING_TRIES = 3;
716
- // Most browsers have a max payload of 64KB for sendbeacon/keep alive payload.
717
- const MAX_SEND_BEACON_PAYLOAD_SIZE = 65536;
718
- const TEXT_ENCODER = new TextEncoder();
719
707
  let remainingTries = DEFAULT_REMAINING_TRIES;
720
708
  /* eslint-enable camelcase */
721
709
  let queue = [];
@@ -743,28 +731,13 @@ function dispatchQueueEvents() {
743
731
  // The staged events will be used for current logRequest attempt, remaining events will be kept
744
732
  // for next attempt.
745
733
  const staged = queue.splice(0, MAX_EVENT_COUNT_PER_REQUEST);
746
- const data = buildPayload(staged);
747
- postToFlEndpoint(data)
748
- .then(() => {
749
- remainingTries = DEFAULT_REMAINING_TRIES;
750
- })
751
- .catch(() => {
752
- // If the request fails for some reason, add the events that were attempted
753
- // back to the primary queue to retry later.
754
- queue = [...staged, ...queue];
755
- remainingTries--;
756
- consoleLogger.info(`Tries left: ${remainingTries}.`);
757
- processQueue(DEFAULT_SEND_INTERVAL_MS);
758
- });
759
- }
760
- function buildPayload(events) {
761
734
  /* eslint-disable camelcase */
762
735
  // We will pass the JSON serialized event to the backend.
763
- const log_event = events.map(evt => ({
736
+ const log_event = staged.map(evt => ({
764
737
  source_extension_json_proto3: evt.message,
765
738
  event_time_ms: String(evt.eventTime)
766
739
  }));
767
- const transportBatchLog = {
740
+ const data = {
768
741
  request_time_ms: String(Date.now()),
769
742
  client_info: {
770
743
  client_type: 1, // 1 is JS
@@ -774,23 +747,29 @@ function buildPayload(events) {
774
747
  log_event
775
748
  };
776
749
  /* eslint-enable camelcase */
777
- return JSON.stringify(transportBatchLog);
750
+ postToFlEndpoint(data)
751
+ .then(() => {
752
+ remainingTries = DEFAULT_REMAINING_TRIES;
753
+ })
754
+ .catch(() => {
755
+ // If the request fails for some reason, add the events that were attempted
756
+ // back to the primary queue to retry later.
757
+ queue = [...staged, ...queue];
758
+ remainingTries--;
759
+ consoleLogger.info(`Tries left: ${remainingTries}.`);
760
+ processQueue(DEFAULT_SEND_INTERVAL_MS);
761
+ });
778
762
  }
779
- /** Sends to Firelog. Atempts to use sendBeacon otherwsise uses fetch. */
780
- function postToFlEndpoint(body) {
763
+ function postToFlEndpoint(data) {
781
764
  const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
782
- const size = TEXT_ENCODER.encode(body).length;
783
- if (size <= MAX_SEND_BEACON_PAYLOAD_SIZE &&
784
- navigator.sendBeacon &&
785
- navigator.sendBeacon(flTransportFullUrl, body)) {
786
- return Promise.resolve();
787
- }
788
- else {
789
- return fetch(flTransportFullUrl, {
765
+ const body = JSON.stringify(data);
766
+ return navigator.sendBeacon && navigator.sendBeacon(flTransportFullUrl, body)
767
+ ? Promise.resolve()
768
+ : fetch(flTransportFullUrl, {
790
769
  method: 'POST',
791
- body
792
- });
793
- }
770
+ body,
771
+ keepalive: true
772
+ }).then();
794
773
  }
795
774
  function addToQueue(evt) {
796
775
  if (!evt.eventTime || !evt.message) {
@@ -812,33 +791,12 @@ serializer) {
812
791
  };
813
792
  }
814
793
  /**
815
- * Force flush the queued events. Useful at page unload time to ensure all events are uploaded.
816
- * Flush will attempt to use sendBeacon to send events async and defaults back to fetch as soon as a
817
- * sendBeacon fails. Firefox
794
+ * Force flush the queued events. Useful at page unload time to ensure all
795
+ * events are uploaded.
818
796
  */
819
797
  function flushQueuedEvents() {
820
- const flTransportFullUrl = SettingsService.getInstance().getFlTransportFullUrl();
821
798
  while (queue.length > 0) {
822
- // Send the last events first to prioritize page load traces
823
- const staged = queue.splice(-SettingsService.getInstance().logMaxFlushSize);
824
- const body = buildPayload(staged);
825
- if (navigator.sendBeacon &&
826
- navigator.sendBeacon(flTransportFullUrl, body)) {
827
- continue;
828
- }
829
- else {
830
- queue = [...queue, ...staged];
831
- break;
832
- }
833
- }
834
- if (queue.length > 0) {
835
- const body = buildPayload(queue);
836
- fetch(flTransportFullUrl, {
837
- method: 'POST',
838
- body
839
- }).catch(() => {
840
- consoleLogger.info(`Failed flushing queued events.`);
841
- });
799
+ dispatchQueueEvents();
842
800
  }
843
801
  }
844
802