@scalebun/react-native 1.2.1 → 1.2.2-beta.0

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.
@@ -717,8 +717,16 @@ export class BackendSessionAdapter implements SessionTransport {
717
717
  type: string; screenName?: string; duration?: number; value?: number;
718
718
  metadata?: Record<string, unknown>;
719
719
  }): void {
720
- if (this.destroyed || !this.config.clientKey) return;
720
+ if (this.destroyed || !this.config.clientKey) {
721
+ logger.warn('[perf.queue] dropped — no clientKey or adapter destroyed', {
722
+ type: data.type, destroyed: this.destroyed, hasClientKey: !!this.config.clientKey,
723
+ });
724
+ return;
725
+ }
721
726
  this.pendingPerformanceMetrics.push({ ...data, clientId: this._clientId(), timestamp: new Date().toISOString() });
727
+ logger.debug('[perf.queue] enqueued performance metric', {
728
+ type: data.type, pending: this.pendingPerformanceMetrics.length,
729
+ });
722
730
  if (this.pendingPerformanceMetrics.length >= 20) {
723
731
  this._flushPerformance().catch(() => {});
724
732
  }
@@ -1405,14 +1413,31 @@ export class BackendSessionAdapter implements SessionTransport {
1405
1413
  }
1406
1414
 
1407
1415
  private async _flushPerformance(): Promise<void> {
1408
- if (this.pendingPerformanceMetrics.length === 0 || !this.currentSessionId || !this.config.clientKey) return;
1416
+ if (this.pendingPerformanceMetrics.length === 0) return;
1417
+ if (!this.currentSessionId || !this.config.clientKey) {
1418
+ logger.debug('[perf.flush] waiting — not deliverable yet', {
1419
+ pending: this.pendingPerformanceMetrics.length,
1420
+ hasSession: !!this.currentSessionId, hasClientKey: !!this.config.clientKey,
1421
+ });
1422
+ return;
1423
+ }
1409
1424
  const batch = this.pendingPerformanceMetrics.splice(0, 50);
1410
1425
  try {
1411
- if (await this._enqueueNative('performance', batch)) return;
1412
- if (!this._sessionRowReady()) { this.pendingPerformanceMetrics.unshift(...batch); return; }
1426
+ if (await this._enqueueNative('performance', batch)) {
1427
+ logger.debug('[perf.flush] handed to native outbox', { count: batch.length });
1428
+ return;
1429
+ }
1430
+ if (!this._sessionRowReady()) {
1431
+ logger.debug('[perf.flush] session row not ready — re-buffering', { count: batch.length });
1432
+ this.pendingPerformanceMetrics.unshift(...batch);
1433
+ return;
1434
+ }
1413
1435
  await this._post(ENDPOINTS.INGESTION_PERFORMANCE(this.currentSessionId), { metrics: batch });
1436
+ logger.info('[perf.flush] POST performance metrics ok', { count: batch.length });
1414
1437
  } catch (err) {
1415
- if (!BackendSessionAdapter._isPermanentHttpError(err)) this.pendingPerformanceMetrics.unshift(...batch);
1438
+ const permanent = BackendSessionAdapter._isPermanentHttpError(err);
1439
+ logger.warn('[perf.flush] POST performance metrics failed', { count: batch.length, permanent });
1440
+ if (!permanent) this.pendingPerformanceMetrics.unshift(...batch);
1416
1441
  }
1417
1442
  }
1418
1443