Skip to content
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

Fix: add conditional to queue restoration error reporting #999

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,11 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
};
Expand Down Expand Up @@ -672,7 +676,11 @@
"-DFOLLY_MOBILE=1",
"-DFOLLY_USE_LIBCPP=1",
);
OTHER_LDFLAGS = "$(inherited)";
OTHER_LDFLAGS = (
"$(inherited)",
"-Wl",
"-ld_classic",
);
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
4 changes: 2 additions & 2 deletions examples/AnalyticsReactNativeExample/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ PODS:
- RNScreens (3.27.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- segment-analytics-react-native (2.19.3):
- segment-analytics-react-native (2.19.4):
- React-Core
- sovran-react-native
- SocketRocket (0.6.1)
Expand Down Expand Up @@ -752,7 +752,7 @@ SPEC CHECKSUMS:
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581
segment-analytics-react-native: a803de6a9406f7b18928d352962c2f49663a0869
segment-analytics-react-native: 49ce29a68e86b38c084f1ce07b0c128273d169f9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
sovran-react-native: 5f02bd2d111ffe226d00c7b0435290eae6f10934
Yoga: eddf2bbe4a896454c248a8f23b4355891eb720a6
Expand Down
10 changes: 5 additions & 5 deletions examples/E2E/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ PODS:
- RNScreens (3.27.0):
- RCT-Folly (= 2021.07.22.00)
- React-Core
- segment-analytics-react-native (2.19.2):
- segment-analytics-react-native (2.19.4):
- React-Core
- sovran-react-native
- SocketRocket (0.6.1)
- sovran-react-native (1.1.1):
- sovran-react-native (1.1.2):
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -752,12 +752,12 @@ SPEC CHECKSUMS:
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
RNGestureHandler: 32a01c29ecc9bb0b5bf7bc0a33547f61b4dc2741
RNScreens: 3c2d122f5e08c192e254c510b212306da97d2581
segment-analytics-react-native: 962494a9edbe3f6c5829e3b471484c85c304601c
segment-analytics-react-native: 49ce29a68e86b38c084f1ce07b0c128273d169f9
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
sovran-react-native: e6a9c963a8a6b9ebc3563394c39c30f33ab1453f
sovran-react-native: 5f02bd2d111ffe226d00c7b0435290eae6f10934
Yoga: eddf2bbe4a896454c248a8f23b4355891eb720a6
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 9d352ca8db1e31a063d2585ed47fdadabf87fe90

COCOAPODS: 1.15.2
COCOAPODS: 1.11.3
27 changes: 24 additions & 3 deletions packages/core/src/plugins/QueueFlushingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultConfig } from '../constants';
import { UtilityPlugin } from '../plugin';
import { PluginType, SegmentEvent } from '../types';
import { createPromise } from '../util';

import { ErrorType, SegmentError } from '../errors';
/**
* This plugin manages a queue where all events get added to after timeline processing.
* It takes a onFlush callback to trigger any action particular to your destination sending events.
Expand All @@ -20,6 +20,7 @@ export class QueueFlushingPlugin extends UtilityPlugin {
private onFlush: (events: SegmentEvent[]) => Promise<void>;
private isRestoredResolve: () => void;
private isRestored: Promise<void>;
private timeoutWarned = false;

/**
* @param onFlush callback to execute when the queue is flushed (either by reaching the limit or manually) e.g. code to upload events to your destination
Expand Down Expand Up @@ -75,12 +76,32 @@ export class QueueFlushingPlugin extends UtilityPlugin {
// Wait for the queue to be restored
try {
await this.isRestored;

if (this.timeoutWarned === true) {
alanjcharles marked this conversation as resolved.
Show resolved Hide resolved
this.analytics?.logger.info('Flush triggered successfully.');

this.timeoutWarned = false;
}
} catch (e) {
// If the queue is not restored before the timeout, we will notify but not block flushing events
console.info(
'Flush triggered but queue restoration and settings loading not complete. Flush will be retried.'
this.analytics?.reportInternalError(
new SegmentError(
ErrorType.InitializationError,
'Queue restoration timeout',
e
)
);

if (this.timeoutWarned === false) {
this.analytics?.logger.warn(
'Flush triggered but queue restoration and settings loading not complete. Flush will be retried.',
e
);

this.timeoutWarned = true;
}
}

const events = (await this.queueStore?.getState(true))?.events ?? [];
if (!this.isPendingUpload) {
try {
Expand Down
Loading