Skip to content

Commit 1b0b11d

Browse files
committed
Merge branch 'antonis/ref-convertToWritable' into antonis/ref-RNSentryJsonUtils
2 parents 5fb03ef + cc8183b commit 1b0b11d

File tree

10 files changed

+294
-232
lines changed

10 files changed

+294
-232
lines changed

CHANGELOG.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Fixes
1212

13+
- Add mechanism field to unhandled rejection errors ([#4457](https://github.com/getsentry/sentry-react-native/pull/4457))
1314
- Use proper SDK name for Session Replay tags ([#4428](https://github.com/getsentry/sentry-react-native/pull/4428))
1415
- Use `makeDsn` from `core` to extract the URL from DSN avoiding unimplemented `URL.protocol` errors ([#4395](https://github.com/getsentry/sentry-react-native/pull/4395))
1516

@@ -22,6 +23,8 @@
2223
### Internal
2324

2425
- Initialize `RNSentryTimeToDisplay` during native module `init` on iOS ([#4443](https://github.com/getsentry/sentry-react-native/pull/4443))
26+
- Extract iOS native initialization to standalone structures ([#4442](https://github.com/getsentry/sentry-react-native/pull/4442))
27+
- Extract Android native initialization to standalone structures ([#4445](https://github.com/getsentry/sentry-react-native/pull/4445))
2528

2629
### Dependencies
2730

@@ -35,10 +38,6 @@
3538
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#7201)
3639
- [diff](https://github.com/getsentry/sentry-java/compare/7.20.0...7.20.1)
3740

38-
### Internal
39-
40-
- Extract Android native initialization to standalone structures ([#4445](https://github.com/getsentry/sentry-react-native/pull/4445))
41-
4241
## 6.5.0
4342

4443
### Features

packages/core/RNSentryCocoaTester/RNSentryCocoaTester.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
332D33482CDBDC7300547D76 /* RNSentry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentry.h; path = ../ios/RNSentry.h; sourceTree = SOURCE_ROOT; };
2626
332D33492CDCC8E100547D76 /* RNSentryTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryTests.h; sourceTree = "<group>"; };
2727
332D334A2CDCC8EB00547D76 /* RNSentryCocoaTesterTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSentryCocoaTesterTests-Bridging-Header.h"; sourceTree = "<group>"; };
28+
333B58A82D35BA93000F8D04 /* RNSentryStart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryStart.h; path = ../ios/RNSentryStart.h; sourceTree = SOURCE_ROOT; };
29+
333B58A92D35BB2D000F8D04 /* RNSentryStart+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "RNSentryStart+Test.h"; path = "RNSentryCocoaTesterTests/RNSentryStart+Test.h"; sourceTree = SOURCE_ROOT; };
2830
336084382C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNSentryReplayBreadcrumbConverterTests.swift; sourceTree = "<group>"; };
2931
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryReplayBreadcrumbConverter.h; path = ../ios/RNSentryReplayBreadcrumbConverter.h; sourceTree = "<group>"; };
3032
3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryBreadcrumbTests.swift; sourceTree = "<group>"; };
@@ -116,6 +118,8 @@
116118
33AFE0122B8F319000AAB120 /* RNSentry */ = {
117119
isa = PBXGroup;
118120
children = (
121+
333B58A92D35BB2D000F8D04 /* RNSentryStart+Test.h */,
122+
333B58A82D35BA93000F8D04 /* RNSentryStart.h */,
119123
3380C6C02CDEC56B0018B9B6 /* Replay */,
120124
332D33482CDBDC7300547D76 /* RNSentry.h */,
121125
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import "RNSentryStart.h"
2+
3+
@interface
4+
RNSentryStart (Test)
5+
6+
+ (void)setEventOriginTag:(SentryEvent *)event;
7+
8+
@end

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.mm

+39-54
Large diffs are not rendered by default.

packages/core/ios/RNSentry.h

-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ SentrySDK (Private)
2020

2121
@interface RNSentry : RCTEventEmitter <RCTBridgeModule>
2222

23-
- (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options
24-
error:(NSError *_Nullable *_Nonnull)errorPointer;
25-
26-
- (void)setEventOriginTag:(SentryEvent *)event;
27-
2823
- (NSDictionary *_Nonnull)fetchNativeStackFramesBy:(NSArray<NSNumber *> *)instructionsAddr
2924
symbolicate:(SymbolicateCallbackType)symbolicate;
3025

packages/core/ios/RNSentry.mm

+3-168
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# import "RNSentryRNSScreen.h"
5050
#endif
5151

52+
#import "RNSentryStart.h"
5253
#import "RNSentryVersion.h"
5354

5455
@interface
@@ -63,7 +64,6 @@ + (void)storeEnvelope:(SentryEnvelope *)envelope;
6364
static bool hasFetchedAppStart;
6465

6566
@implementation RNSentry {
66-
bool sentHybridSdkDidBecomeActive;
6767
bool hasListeners;
6868
RNSentryTimeToDisplay *_timeToDisplay;
6969
}
@@ -94,181 +94,16 @@ - (instancetype)init
9494
: (RCTPromiseRejectBlock)reject)
9595
{
9696
NSError *error = nil;
97-
SentryOptions *sentryOptions = [self createOptionsWithDictionary:options error:&error];
97+
SentryOptions *sentryOptions = [RNSentryStart createOptionsWithDictionary:options error:&error];
9898
if (error != nil) {
9999
reject(@"SentryReactNative", error.localizedDescription, error);
100100
return;
101101
}
102102

103-
NSString *sdkVersion = [PrivateSentrySDKOnly getSdkVersionString];
104-
[PrivateSentrySDKOnly setSdkName:NATIVE_SDK_NAME andVersionString:sdkVersion];
105-
[PrivateSentrySDKOnly addSdkPackage:REACT_NATIVE_SDK_PACKAGE_NAME
106-
version:REACT_NATIVE_SDK_PACKAGE_VERSION];
107-
108-
[SentrySDK startWithOptions:sentryOptions];
109-
110-
#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
111-
BOOL appIsActive =
112-
[[UIApplication sharedApplication] applicationState] == UIApplicationStateActive;
113-
#else
114-
BOOL appIsActive = [[NSApplication sharedApplication] isActive];
115-
#endif
116-
117-
// If the app is active/in foreground, and we have not sent the SentryHybridSdkDidBecomeActive
118-
// notification, send it.
119-
if (appIsActive && !sentHybridSdkDidBecomeActive
120-
&& (PrivateSentrySDKOnly.options.enableAutoSessionTracking
121-
|| PrivateSentrySDKOnly.options.enableWatchdogTerminationTracking)) {
122-
[[NSNotificationCenter defaultCenter] postNotificationName:@"SentryHybridSdkDidBecomeActive"
123-
object:nil];
124-
125-
sentHybridSdkDidBecomeActive = true;
126-
}
127-
128-
#if SENTRY_TARGET_REPLAY_SUPPORTED
129-
[RNSentryReplay postInit];
130-
#endif
131-
103+
[RNSentryStart startWithOptions:sentryOptions];
132104
resolve(@YES);
133105
}
134106

135-
- (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options
136-
error:(NSError *_Nonnull *_Nonnull)errorPointer
137-
{
138-
SentryBeforeSendEventCallback beforeSend = ^SentryEvent *(SentryEvent *event)
139-
{
140-
// We don't want to send an event after startup that came from a Unhandled JS Exception of
141-
// react native Because we sent it already before the app crashed.
142-
if (nil != event.exceptions.firstObject.type &&
143-
[event.exceptions.firstObject.type rangeOfString:@"Unhandled JS Exception"].location
144-
!= NSNotFound) {
145-
return nil;
146-
}
147-
148-
[self setEventOriginTag:event];
149-
150-
return event;
151-
};
152-
153-
NSMutableDictionary *mutableOptions = [options mutableCopy];
154-
[mutableOptions setValue:beforeSend forKey:@"beforeSend"];
155-
156-
// remove performance traces sample rate and traces sampler since we don't want to synchronize
157-
// these configurations to the Native SDKs. The user could tho initialize the SDK manually and
158-
// set themselves.
159-
[mutableOptions removeObjectForKey:@"tracesSampleRate"];
160-
[mutableOptions removeObjectForKey:@"tracesSampler"];
161-
[mutableOptions removeObjectForKey:@"enableTracing"];
162-
163-
#if SENTRY_TARGET_REPLAY_SUPPORTED
164-
[RNSentryReplay updateOptions:mutableOptions];
165-
#endif
166-
167-
SentryOptions *sentryOptions = [[SentryOptions alloc] initWithDict:mutableOptions
168-
didFailWithError:errorPointer];
169-
if (*errorPointer != nil) {
170-
return nil;
171-
}
172-
173-
// Exclude Dev Server and Sentry Dsn request from Breadcrumbs
174-
NSString *dsn = [self getURLFromDSN:[mutableOptions valueForKey:@"dsn"]];
175-
NSString *devServerUrl = [mutableOptions valueForKey:@"devServerUrl"];
176-
sentryOptions.beforeBreadcrumb
177-
= ^SentryBreadcrumb *_Nullable(SentryBreadcrumb *_Nonnull breadcrumb)
178-
{
179-
NSString *url = breadcrumb.data[@"url"] ?: @"";
180-
181-
if ([@"http" isEqualToString:breadcrumb.type]
182-
&& ((dsn != nil && [url hasPrefix:dsn])
183-
|| (devServerUrl != nil && [url hasPrefix:devServerUrl]))) {
184-
return nil;
185-
}
186-
return breadcrumb;
187-
};
188-
189-
if ([mutableOptions valueForKey:@"enableNativeCrashHandling"] != nil) {
190-
BOOL enableNativeCrashHandling = [mutableOptions[@"enableNativeCrashHandling"] boolValue];
191-
192-
if (!enableNativeCrashHandling) {
193-
NSMutableArray *integrations = sentryOptions.integrations.mutableCopy;
194-
[integrations removeObject:@"SentryCrashIntegration"];
195-
sentryOptions.integrations = integrations;
196-
}
197-
}
198-
199-
// Set spotlight option
200-
if ([mutableOptions valueForKey:@"spotlight"] != nil) {
201-
id spotlightValue = [mutableOptions valueForKey:@"spotlight"];
202-
if ([spotlightValue isKindOfClass:[NSString class]]) {
203-
NSLog(@"Using Spotlight on address: %@", spotlightValue);
204-
sentryOptions.enableSpotlight = true;
205-
sentryOptions.spotlightUrl = spotlightValue;
206-
} else if ([spotlightValue isKindOfClass:[NSNumber class]]) {
207-
sentryOptions.enableSpotlight = [spotlightValue boolValue];
208-
id defaultSpotlightUrl = [mutableOptions valueForKey:@"defaultSidecarUrl"];
209-
if (defaultSpotlightUrl != nil) {
210-
sentryOptions.spotlightUrl = defaultSpotlightUrl;
211-
}
212-
}
213-
}
214-
215-
// Enable the App start and Frames tracking measurements
216-
if ([mutableOptions valueForKey:@"enableAutoPerformanceTracing"] != nil) {
217-
BOOL enableAutoPerformanceTracing =
218-
[mutableOptions[@"enableAutoPerformanceTracing"] boolValue];
219-
PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode = enableAutoPerformanceTracing;
220-
#if TARGET_OS_IPHONE || TARGET_OS_MACCATALYST
221-
PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode = enableAutoPerformanceTracing;
222-
#endif
223-
}
224-
225-
// Failed requests can only be enabled in one SDK to avoid duplicates
226-
sentryOptions.enableCaptureFailedRequests = NO;
227-
228-
return sentryOptions;
229-
}
230-
231-
- (NSString *_Nullable)getURLFromDSN:(NSString *)dsn
232-
{
233-
NSURL *url = [NSURL URLWithString:dsn];
234-
if (!url) {
235-
return nil;
236-
}
237-
return [NSString stringWithFormat:@"%@://%@", url.scheme, url.host];
238-
}
239-
240-
- (void)setEventOriginTag:(SentryEvent *)event
241-
{
242-
if (event.sdk != nil) {
243-
NSString *sdkName = event.sdk[@"name"];
244-
245-
// If the event is from react native, it gets set
246-
// there and we do not handle it here.
247-
if ([sdkName isEqual:NATIVE_SDK_NAME]) {
248-
[self setEventEnvironmentTag:event origin:@"ios" environment:@"native"];
249-
}
250-
}
251-
}
252-
253-
- (void)setEventEnvironmentTag:(SentryEvent *)event
254-
origin:(NSString *)origin
255-
environment:(NSString *)environment
256-
{
257-
NSMutableDictionary *newTags = [NSMutableDictionary new];
258-
259-
if (nil != event.tags && [event.tags count] > 0) {
260-
[newTags addEntriesFromDictionary:event.tags];
261-
}
262-
if (nil != origin) {
263-
[newTags setValue:origin forKey:@"event.origin"];
264-
}
265-
if (nil != environment) {
266-
[newTags setValue:environment forKey:@"event.environment"];
267-
}
268-
269-
event.tags = newTags;
270-
}
271-
272107
RCT_EXPORT_METHOD(initNativeReactNavigationNewFrameTracking
273108
: (RCTPromiseResolveBlock)resolve rejecter
274109
: (RCTPromiseRejectBlock)reject)

packages/core/ios/RNSentryStart.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#import <Sentry/SentryDefines.h>
2+
#import <Sentry/SentryOptions.h>
3+
4+
@interface RNSentryStart : NSObject
5+
SENTRY_NO_INIT
6+
7+
+ (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)options
8+
error:(NSError *_Nonnull *_Nonnull)errorPointer;
9+
10+
/**
11+
* @experimental
12+
* Inits and configures Sentry for React Native applications. Make sure to
13+
* set a valid DSN.
14+
*
15+
* @discussion Call this method on the main thread. When calling it from a background thread, the
16+
* SDK starts on the main thread async.
17+
*/
18+
+ (void)startWithOptions:(SentryOptions *)options NS_SWIFT_NAME(start(options:));
19+
20+
@end

0 commit comments

Comments
 (0)