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
1 change: 1 addition & 0 deletions samples/react-native/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 39
versionName "6.7.0-alpha.0"
buildConfigField "boolean", "SENTRY_DISABLE_NATIVE_START", System.getenv('SENTRY_DISABLE_NATIVE_START') ?: String.valueOf(sentryDisableNativeStart)
}

signingConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,14 @@ class MainApplication :

override fun onCreate() {
super.onCreate()
// When the native init is enabled the `autoInitializeNativeSdk`
// in JS has to be set to `false`
// this.initializeSentry()
if (!BuildConfig.SENTRY_DISABLE_NATIVE_START) {
RNSentrySDK.init(this)
}

SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}

private fun initializeSentry() {
RNSentrySDK.init(this) { options ->
// Options set here will apply to the Android SDK overriding the ones from `sentry.options.json`
options.dsn = "https://[email protected]/5428561"
options.isDebug = true
}

// RNSentrySDK.init(this)
}
}
5 changes: 5 additions & 0 deletions samples/react-native/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ newArchEnabled=true
# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true

# Only implemented in this sample project.
# It's used for testing the native SDK auto-start feature.
# true means manual native start is disabled and JS auto initializes native SDK.
sentryDisableNativeStart=false
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
ReferencedContainer = "container:sentryreactnativesample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "--sentry-disable-native-start"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// When the native init is enabled the `autoInitializeNativeSdk`
// in JS has to be set to `false`
// [RNSentrySDK start];
if ([self shouldStartSentry]) {
[RNSentrySDK start];
}

self.moduleName = @"sentry-react-native-sample";
// You can add your custom initial props in the dictionary below.
Expand Down Expand Up @@ -73,4 +73,9 @@ - (BOOL)concurrentRootEnabled
return nullptr;
}

- (BOOL) shouldStartSentry {
NSArray<NSString*>* arguments = [[NSProcessInfo processInfo] arguments];
return ![arguments containsObject:@"--sentry-disable-native-start"];
}

@end
2 changes: 2 additions & 0 deletions samples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"delay": "^6.0.0",
"react": "18.3.1",
"react-native": "0.76.3",
"react-native-build-config": "^0.3.2",
"react-native-gesture-handler": "^2.21.1",
"react-native-launch-arguments": "^4.0.4",
"react-native-reanimated": "3.16.1",
"react-native-safe-area-context": "4.14.0",
"react-native-screens": "4.1.0",
Expand Down
8 changes: 6 additions & 2 deletions samples/react-native/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ import GesturesTracingScreen from './Screens/GesturesTracingScreen';
import { LogBox, Platform, StyleSheet, View } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import PlaygroundScreen from './Screens/PlaygroundScreen';
import { logWithoutTracing } from './utils';
import { clearSentryOptionsFromFile, logWithoutTracing, shouldUseAutoStart } from './utils';
import { ErrorEvent } from '@sentry/core';
import HeavyNavigationScreen from './Screens/HeavyNavigationScreen';
import WebviewScreen from './Screens/WebviewScreen';
import { isTurboModuleEnabled } from '@sentry/react-native/dist/js/utils/environment';

if (shouldUseAutoStart()) {
clearSentryOptionsFromFile();
}

if (typeof setImmediate === 'undefined') {
require('setimmediate');
}
Expand Down Expand Up @@ -130,7 +134,7 @@ Sentry.init({
spotlight: true,
// This should be disabled when manually initializing the native SDK
// Note that options from JS are not passed to the native SDKs when initialized manually
autoInitializeNativeSdk: true,
// autoInitializeNativeSdk: true,
});

const Stack = isMobileOs
Expand Down
30 changes: 30 additions & 0 deletions samples/react-native/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
import { LaunchArguments } from 'react-native-launch-arguments';
import BuildConfig from 'react-native-build-config';
import { Platform } from 'react-native';

export function logWithoutTracing(...args: unknown[]) {
if ('__sentry_original__' in console.log) {
console.log.__sentry_original__(...args);
} else {
console.log(...args);
}
}

export function shouldUseAutoStart(): boolean {
if (Platform.OS === 'android') {
return !!(
BuildConfig as {
SENTRY_DISABLE_NATIVE_START?: boolean;
}
).SENTRY_DISABLE_NATIVE_START;
} else if (Platform.OS === 'ios') {
const args = LaunchArguments.value<{
sentrydisablenativestart?: boolean;
}>();
return !!args.sentrydisablenativestart;
} else {
return false;
}
}

export function clearSentryOptionsFromFile() {
(
globalThis as {
__SENTRY_OPTIONS__?: Record<string, unknown>;
}
).__SENTRY_OPTIONS__ = undefined;
logWithoutTracing('Sentry options from file cleared.');
}
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22463,6 +22463,13 @@ __metadata:
languageName: node
linkType: hard

"react-native-build-config@npm:^0.3.2":
version: 0.3.2
resolution: "react-native-build-config@npm:0.3.2"
checksum: d2095580be7e6662c968bce5d64cc6524b7f34380999756fb9d4ad24a34e3566b203f93e9bc63bd1e0213d28e1e76dae0c0f39b0b65c55528a876e96dd6c5810
languageName: node
linkType: hard

"react-native-codegen@npm:^0.70.7":
version: 0.70.7
resolution: "react-native-codegen@npm:0.70.7"
Expand Down Expand Up @@ -22561,6 +22568,16 @@ __metadata:
languageName: node
linkType: hard

"react-native-launch-arguments@npm:^4.0.4":
version: 4.0.4
resolution: "react-native-launch-arguments@npm:4.0.4"
peerDependencies:
react: ">=16.8.1"
react-native: ">=0.60.0-rc.0 <1.0.x"
checksum: 7346af606cedc35c58bdccabd88a8ef9b2b55138accf490fe8291c6d7110679f9125af072eaaf896909554cd54be20e863c987d1ce91c39a2f401a999c7fde9f
languageName: node
linkType: hard

"react-native-macos@npm:0.73.34":
version: 0.73.34
resolution: "react-native-macos@npm:0.73.34"
Expand Down Expand Up @@ -24283,7 +24300,9 @@ __metadata:
prettier: 2.8.8
react: 18.3.1
react-native: 0.76.3
react-native-build-config: ^0.3.2
react-native-gesture-handler: ^2.21.1
react-native-launch-arguments: ^4.0.4
react-native-reanimated: 3.16.1
react-native-safe-area-context: 4.14.0
react-native-screens: 4.1.0
Expand Down