Skip to content
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
13 changes: 13 additions & 0 deletions examples/expo/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from 'react-native';
import {
generateDeviceCode,
getPreviousRunInfo,
getSessionURL,
info,
debug,
Expand All @@ -24,6 +25,7 @@ import {
warn,
logScreenView,
logAppLaunchTTI,
type PreviousRunInfo,
setFeatureFlagExposure,
} from '@bitdrift/react-native';
import axios from 'axios';
Expand Down Expand Up @@ -108,10 +110,13 @@ const HomeScreen = () => {
null,
);
const [sessionURL, setSessionURL] = useState<string | null>(null);
const [previousRunInfo, setPreviousRunInfo] = useState<PreviousRunInfo>(null);
const [showPickerModal, setShowPickerModal] = useState(false);
const [showErrorPickerModal, setShowErrorPickerModal] = useState(false);

useEffect(() => {
setPreviousRunInfo(getPreviousRunInfo());

getSessionURL()
.then(setSessionURL)
.catch(() => {});
Expand Down Expand Up @@ -163,6 +168,9 @@ const HomeScreen = () => {
<Text testID="sdk-status">
{sessionURL ? 'SDK Ready' : 'SDK Not Ready'}
</Text>
<Text testID="previous-run-info" style={styles.previousRunInfoText}>
Previous run info: {JSON.stringify(previousRunInfo)}
</Text>

{!hasAPIKeyConfigured && (
<InfoBlock
Expand Down Expand Up @@ -440,6 +448,11 @@ const styles = StyleSheet.create({
fontWeight: 'bold',
marginBottom: 20,
},
previousRunInfoText: {
marginTop: 8,
marginBottom: 8,
fontSize: 12,
},
button: {
backgroundColor: '#00A76F',
padding: 10,
Expand Down
157 changes: 157 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import io.bitdrift.capture.Capture
import io.bitdrift.capture.providers.session.SessionStrategy
import com.facebook.react.bridge.Promise
import okhttp3.HttpUrl.Companion.toHttpUrl
import kotlin.time.Duration
import kotlin.time.DurationUnit
import kotlin.time.toDuration
import io.bitdrift.capture.Configuration
import io.bitdrift.capture.experimental.ExperimentalBitdriftApi
import io.bitdrift.capture.reports.IssueCallbackConfiguration
import io.bitdrift.capture.reports.IssueReportCallback
import java.util.concurrent.ExecutorService
Expand Down Expand Up @@ -155,6 +155,16 @@ class BdReactNativeModule internal constructor(context: ReactApplicationContext)
}
}

@OptIn(ExperimentalBitdriftApi::class)
@ReactMethod(isBlockingSynchronousMethod = true)
override fun getPreviousRunInfo(): WritableMap? {
val info = Capture.Logger.getPreviousRunInfo() ?: return null
val map = Arguments.createMap()
map.putBoolean("hasFatallyTerminated", info.hasFatallyTerminated)
info.terminationReason?.let { map.putString("terminationReason", it.name) }
return map
}

@ReactMethod
override fun log(level: Double, message: String, jsFields: ReadableMap?) {
val fields = jsFields?.toHashMap()?.mapValues { it.value.toString() } ?: emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.WritableMap

abstract class BdReactNativeSpec internal constructor(context: ReactApplicationContext):
ReactContextBaseJavaModule(context) {
Expand All @@ -23,6 +24,8 @@ abstract class BdReactNativeSpec internal constructor(context: ReactApplicationC

abstract fun getSessionURL(promise: Promise)

abstract fun getPreviousRunInfo(): WritableMap?

abstract fun log(level: Double, message: String, jsFields: ReadableMap?)

abstract fun addField(key: String, value: String)
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/ios/BdReactNative.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ - (void)handleIssueReportNotification:(NSNotification *)notification
[CAPRNLogger getSessionURL:resolve rejecter:reject];
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(getPreviousRunInfo) {
return [CAPRNLogger getPreviousRunInfo];
}

RCT_EXPORT_METHOD(logScreenView:(NSString *)screenName)
{
[CAPRNLogger logScreenViewWithScreenName:screenName];
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native/ios/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ let CAPRNIssueReportDidEmitNotification = Notification.Name("BdReactNative.onBef
resolve(sessionURL)
}

@objc
public static func getPreviousRunInfo() -> [String: Any]? {
guard let info = Capture.Logger.previousRunInfo else {
return nil
}
return ["hasFatallyTerminated": info.hasFatallyTerminated]
}

@objc
public static func logScreenView(screenName: String) {
Capture.Logger.logScreenView(screenName: screenName)
Expand Down
7 changes: 7 additions & 0 deletions packages/react-native/src/NativeBdReactNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export type InitOptions = {
crashReporting?: CrashReportingOptions;
};

export type PreviousRunInfo = {
hasFatallyTerminated: boolean;
terminationReason?: string;
} | null;

export interface Spec extends TurboModule {
init(
key: string,
Expand All @@ -47,6 +52,8 @@ export interface Spec extends TurboModule {

getSessionURL(): Promise<string>;

getPreviousRunInfo(): PreviousRunInfo;

logScreenView(screenName: string): void;

logAppLaunchTTI(tti_ms: number): void;
Expand Down
11 changes: 11 additions & 0 deletions packages/react-native/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
InitOptions as NativeInitOptions,
CrashReportingOptions as NativeCrashReportingOptions,
PreviousRunInfo as PreviousRunInfoModel,
SessionStrategy,
} from './NativeBdReactNative';
import NativeBdReactNative from './NativeBdReactNative';
Expand Down Expand Up @@ -227,6 +228,16 @@ export async function getSessionURL(): Promise<string> {
return NativeBdReactNative.getSessionURL();
}

export type { PreviousRunInfo } from './NativeBdReactNative';

/**
* Returns information about the previous app run, or `null` when not available.
* Must be called after {@link init}.
*/
export function getPreviousRunInfo(): PreviousRunInfoModel {
return NativeBdReactNative.getPreviousRunInfo();
}

/**
* Logs a screen view event. This can be called to record that a screen was viewed.
* @param screenName The name of the screen that was viewed.
Expand Down
Loading