Skip to content

Commit db7585c

Browse files
antonislucas-zimermankrystofwoldrichclaude
authored
feat(expo): Add RNSentrySDK APIs support to @sentry/react-native/expo plugin (#4633)
* useNativeInit Android implementation * Adds changelog * useNativeInit iOS implementation * Fix indentation * Extend test cases with realistic data * Adds code sample in the changelog * Fix CHANGELOG.md Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com> * Warn if RESentySDK.init/start wasn't injected * Make useNativeInit opt-in * Make Android failure warning more clear Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> * Make Android no update warning more clear Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> * Use path.basename to get last path component * Update tests to account for the new warnings * Explicitly check for kotlin * Add filename in the warning message * Import only if init injection succeeds * Explicitly check for Objective-C * Add filename in the warning * Make iOS file not found warning more clear * Import only if init injection succeeds * Reset test mock config in a function * Lint issue * Add missing quote Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com> * Remove unneeded async Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> * Set useNativeInit = false by default * dynamically fill white spaces * Add unsupported language in warning message * Add objcpp in detected languages Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> * Update tests for objcpp * ref(expo-plugin): Split utils to logger, version and utils (#4906) Co-authored-by: Antonis Lilis <antonis.lilis@gmail.com> * Update changelog * fix(ios): Add Swift module support for RNSentrySDK native init Fixes Swift compilation errors when using the useNativeInit Expo plugin feature. Changes: - Updated RNSentry.h to use angle bracket import for RNSentrySDK, properly exposing it through the module system - Added DEFINES_MODULE to RNSentry.podspec to enable Swift module generation - Fixed Expo plugin to insert import after first import statement (supports modern Expo AppDelegate structure without UIKit import) This enables Swift code to successfully import RNSentry and call RNSentrySDK.start() when using native initialization. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> * Fix test * Update changelog * Fix native tests * Fix lint issue * Fix native tests * Revert unneeded changes * Fix sample app build --------- Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com> Co-authored-by: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent db88ae9 commit db7585c

20 files changed

+633
-79
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@
1212

1313
- Fixes Android incompatibility with Firebase dependencies ([#5563](https://github.com/getsentry/sentry-react-native/pull/5563))
1414

15+
### Features
16+
17+
- Add RNSentrySDK APIs support to @sentry/react-native/expo plugin ([#4633](https://github.com/getsentry/sentry-react-native/pull/4633))
18+
- Adds `useNativeInit` option to automatically initialize Sentry natively before JavaScript loads, enabling capture of app start errors
19+
```json
20+
{
21+
"expo": {
22+
"plugins": [
23+
[
24+
"@sentry/react-native/expo",
25+
{
26+
"useNativeInit": true
27+
}
28+
]
29+
]
30+
}
31+
}
32+
```
33+
1534
### Dependencies
1635

1736
- Bump Bundler Plugins from v4.6.2 to v4.7.0 ([#5554](https://github.com/getsentry/sentry-react-native/pull/5554))

packages/core/RNSentry.podspec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Pod::Spec.new do |s|
4646

4747
s.compiler_flags = other_cflags
4848

49+
s.pod_target_xcconfig = {
50+
'DEFINES_MODULE' => 'YES'
51+
}
52+
4953
s.dependency 'Sentry/HybridSDK', '8.58.0'
5054

5155
if defined? install_modules_dependencies
@@ -56,10 +60,10 @@ Pod::Spec.new do |s|
5660

5761
if is_new_arch_enabled then
5862
# New Architecture on React Native 0.70 and older
59-
s.pod_target_xcconfig = {
63+
s.pod_target_xcconfig.merge!({
6064
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
6165
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
62-
}
66+
})
6367

6468
s.dependency "React-RCTFabric" # Required for Fabric Components (like RCTViewComponentView)
6569
s.dependency "React-Codegen"

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryCocoaTesterTests-Bridging-Header.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use this file to import your target's public headers that you would like to expose to Swift.
33
//
44

5+
#import <React/RCTViewManager.h>
6+
57
#import "../RNSentrySDK+Test.h"
68
#import "RNSentryBreadcrumb.h"
79
#import "RNSentryOnDrawReporter+Test.h"
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#import "SentryFramesTracker.h"
21
#import <Foundation/Foundation.h>
3-
#import <RNSentry/RNSentry.h>
4-
5-
@interface SentryDependencyContainer : NSObject
6-
+ (instancetype)sharedInstance;
7-
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
8-
@end
2+
@import Sentry;
3+
#import "RNSentryDependencyContainer.h"
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
#import "SentryFramesTracker.h"
21
#import <Foundation/Foundation.h>
3-
#import <RNSentry/RNSentry.h>
4-
5-
@interface SentryDependencyContainer : NSObject
6-
+ (instancetype)sharedInstance;
7-
@property (nonatomic, strong) SentryFramesTracker *framesTracker;
8-
@end
2+
@import Sentry;
3+
#import "RNSentryDependencyContainer.h"

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#import <Foundation/Foundation.h>
22
#import <RNSentry/RNSentry.h>
3+
#import <RNSentry/RNSentryReplay.h>
34

45
@class SentryOptions;
56
@class SentryUser;

packages/core/RNSentryCocoaTester/RNSentrySDK+Test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "RNSentrySDK.h"
2+
@import Sentry;
23

34
@interface RNSentrySDK (Test)
45

packages/core/plugin/src/logger.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const warningMap = new Map<string, boolean>();
2+
3+
/**
4+
* Log a warning message only once per run.
5+
* This is used to avoid spamming the console with the same message.
6+
*/
7+
export function warnOnce(message: string): void {
8+
if (!warningMap.has(message)) {
9+
warningMap.set(message, true);
10+
// eslint-disable-next-line no-console
11+
console.warn(yellow(prefix(message)));
12+
}
13+
}
14+
15+
/**
16+
* Prefix message with `› [value]`.
17+
*
18+
* Example:
19+
* ```
20+
* › [@sentry/react-native/expo] This is a warning message
21+
* ```
22+
*/
23+
export function prefix(value: string): string {
24+
return `› ${bold('[@sentry/react-native/expo]')} ${value}`;
25+
}
26+
27+
/**
28+
* The same as `chalk.yellow`
29+
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
30+
*/
31+
export function yellow(message: string): string {
32+
return `\x1b[33m${message}\x1b[0m`;
33+
}
34+
35+
/**
36+
* The same as `chalk.bold`
37+
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
38+
*/
39+
export function bold(message: string): string {
40+
return `\x1b[1m${message}\x1b[22m`;
41+
}

packages/core/plugin/src/utils.ts

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,3 @@ export function writeSentryPropertiesTo(filepath: string, sentryProperties: stri
88

99
fs.writeFileSync(path.resolve(filepath, 'sentry.properties'), sentryProperties);
1010
}
11-
12-
const sdkPackage: {
13-
name: string;
14-
version: string;
15-
// eslint-disable-next-line @typescript-eslint/no-var-requires
16-
} = require('../../package.json');
17-
18-
const SDK_PACKAGE_NAME = `${sdkPackage.name}/expo`;
19-
20-
const warningMap = new Map<string, boolean>();
21-
export function warnOnce(message: string): void {
22-
if (!warningMap.has(message)) {
23-
warningMap.set(message, true);
24-
// eslint-disable-next-line no-console
25-
console.warn(yellow(`${logPrefix()} ${message}`));
26-
}
27-
}
28-
29-
export function logPrefix(): string {
30-
return `› ${bold('[@sentry/react-native/expo]')}`;
31-
}
32-
33-
/**
34-
* The same as `chalk.yellow`
35-
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
36-
*/
37-
export function yellow(message: string): string {
38-
return `\x1b[33m${message}\x1b[0m`;
39-
}
40-
41-
/**
42-
* The same as `chalk.bold`
43-
* This code is part of the SDK, we don't want to introduce a dependency on `chalk` just for this.
44-
*/
45-
export function bold(message: string): string {
46-
return `\x1b[1m${message}\x1b[22m`;
47-
}
48-
49-
export { sdkPackage, SDK_PACKAGE_NAME };
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const packageJson: {
2+
name: string;
3+
version: string;
4+
// eslint-disable-next-line @typescript-eslint/no-var-requires
5+
} = require('../../package.json');
6+
7+
export const PLUGIN_NAME = `${packageJson.name}/expo`;
8+
export const PLUGIN_VERSION = packageJson.version;

0 commit comments

Comments
 (0)