Skip to content

Commit a1ab76a

Browse files
Merge f92edd9 into 3ccfbf5
2 parents 3ccfbf5 + f92edd9 commit a1ab76a

File tree

13 files changed

+380
-45
lines changed

13 files changed

+380
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
- Rename `navigation.processing` span to more expressive `Navigation dispatch to screen A mounted/navigation cancelled` ([#4423](https://github.com/getsentry/sentry-react-native/pull/4423))
1919
- Add RN SDK package to `sdk.packages` for Cocoa ([#4381](https://github.com/getsentry/sentry-react-native/pull/4381))
20+
- Add experimental version of `startWithConfigureOptions` for Apple platforms ([#4444](https://github.com/getsentry/sentry-react-native/pull/4444))
2021

2122
### Internal
2223

packages/core/RNSentry.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Pod::Spec.new do |s|
3333
s.preserve_paths = '*.js'
3434

3535
s.source_files = 'ios/**/*.{h,m,mm}'
36-
s.public_header_files = 'ios/RNSentry.h'
36+
s.public_header_files = 'ios/RNSentry.h', 'ios/RNSentrySDK.h'
3737

3838
s.compiler_flags = other_cflags
3939

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 336084382C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift */; };
1212
3380C6C42CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3380C6C32CE25ECA0018B9B6 /* RNSentryReplayPostInitTests.swift */; };
1313
33958C692BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */; };
14+
339C6C3C2D3EB25100CA72ED /* RNSentryStartTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 339C6C3B2D3EB23B00CA72ED /* RNSentryStartTests.swift */; };
1415
33AFDFED2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */; };
1516
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */; };
1617
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 33F58ACF2977037D008F60EA /* RNSentryTests.mm */; };
@@ -27,6 +28,7 @@
2728
332D334A2CDCC8EB00547D76 /* RNSentryCocoaTesterTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNSentryCocoaTesterTests-Bridging-Header.h"; sourceTree = "<group>"; };
2829
333B58A82D35BA93000F8D04 /* RNSentryStart.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryStart.h; path = ../ios/RNSentryStart.h; sourceTree = SOURCE_ROOT; };
2930
333B58A92D35BB2D000F8D04 /* RNSentryStart+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "RNSentryStart+Test.h"; path = "RNSentryCocoaTesterTests/RNSentryStart+Test.h"; sourceTree = SOURCE_ROOT; };
31+
333B58AF2D36A7FD000F8D04 /* RNSentrySDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentrySDK.h; path = ../ios/RNSentrySDK.h; sourceTree = SOURCE_ROOT; };
3032
336084382C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RNSentryReplayBreadcrumbConverterTests.swift; sourceTree = "<group>"; };
3133
3360843A2C32E3A8008CC412 /* RNSentryReplayBreadcrumbConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryReplayBreadcrumbConverter.h; path = ../ios/RNSentryReplayBreadcrumbConverter.h; sourceTree = "<group>"; };
3234
3360843C2C340C76008CC412 /* RNSentryBreadcrumbTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryBreadcrumbTests.swift; sourceTree = "<group>"; };
@@ -37,6 +39,8 @@
3739
338739072A7D7D2800950DDD /* RNSentryReplay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryReplay.h; path = ../ios/RNSentryReplay.h; sourceTree = "<group>"; };
3840
33958C672BFCEF5A00AD1FB6 /* RNSentryOnDrawReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSentryOnDrawReporter.h; path = ../ios/RNSentryOnDrawReporter.h; sourceTree = "<group>"; };
3941
33958C682BFCF12600AD1FB6 /* RNSentryOnDrawReporterTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryOnDrawReporterTests.m; sourceTree = "<group>"; };
42+
339C6C3B2D3EB23B00CA72ED /* RNSentryStartTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNSentryStartTests.swift; sourceTree = "<group>"; };
43+
339C6C3D2D3FA04D00CA72ED /* RNSentryVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSentryVersion.h; path = ../ios/RNSentryVersion.h; sourceTree = SOURCE_ROOT; };
4044
33AFDFEC2B8D14B300AAB120 /* RNSentryFramesTrackerListenerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryFramesTrackerListenerTests.m; sourceTree = "<group>"; };
4145
33AFDFEE2B8D14C200AAB120 /* RNSentryFramesTrackerListenerTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSentryFramesTrackerListenerTests.h; sourceTree = "<group>"; };
4246
33AFDFF02B8D15E500AAB120 /* RNSentryDependencyContainerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSentryDependencyContainerTests.m; sourceTree = "<group>"; };
@@ -90,6 +94,7 @@
9094
3360899029524164007C7730 /* RNSentryCocoaTesterTests */ = {
9195
isa = PBXGroup;
9296
children = (
97+
339C6C3B2D3EB23B00CA72ED /* RNSentryStartTests.swift */,
9398
332D334A2CDCC8EB00547D76 /* RNSentryCocoaTesterTests-Bridging-Header.h */,
9499
332D33492CDCC8E100547D76 /* RNSentryTests.h */,
95100
336084382C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift */,
@@ -118,6 +123,8 @@
118123
33AFE0122B8F319000AAB120 /* RNSentry */ = {
119124
isa = PBXGroup;
120125
children = (
126+
339C6C3D2D3FA04D00CA72ED /* RNSentryVersion.h */,
127+
333B58AF2D36A7FD000F8D04 /* RNSentrySDK.h */,
121128
333B58A92D35BB2D000F8D04 /* RNSentryStart+Test.h */,
122129
333B58A82D35BA93000F8D04 /* RNSentryStart.h */,
123130
3380C6C02CDEC56B0018B9B6 /* Replay */,
@@ -243,6 +250,7 @@
243250
files = (
244251
AEFB00422CC90C4B00EC8A9A /* RNSentryBreadcrumbTests.swift in Sources */,
245252
332D33472CDBDBB600547D76 /* RNSentryReplayOptionsTests.swift in Sources */,
253+
339C6C3C2D3EB25100CA72ED /* RNSentryStartTests.swift in Sources */,
246254
33AFDFF12B8D15E500AAB120 /* RNSentryDependencyContainerTests.m in Sources */,
247255
336084392C32E382008CC412 /* RNSentryReplayBreadcrumbConverterTests.swift in Sources */,
248256
33F58AD02977037D008F60EA /* RNSentryTests.mm in Sources */,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
#import "RNSentryReplayBreadcrumbConverter.h"
88
#import "RNSentryReplayMask.h"
99
#import "RNSentryReplayUnmask.h"
10+
#import "RNSentrySDK.h"
11+
#import "RNSentryStart.h"
12+
#import "RNSentryVersion.h"
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
import XCTest
2+
3+
final class RNSentryStartTests: XCTestCase {
4+
5+
func testStartDoesNotThrowWithoutConfigure() {
6+
RNSentrySDK.start(configureOptions: nil)
7+
}
8+
9+
func assertReactDefaults(_ actualOptions: Options?) {
10+
XCTAssertFalse(actualOptions!.enableCaptureFailedRequests)
11+
XCTAssertNil(actualOptions!.tracesSampleRate)
12+
XCTAssertNil(actualOptions!.tracesSampler)
13+
XCTAssertFalse(actualOptions!.enableTracing)
14+
}
15+
16+
func testStartSetsReactDeafults() {
17+
var actualOptions: Options?
18+
19+
RNSentrySDK.start { options in
20+
actualOptions = options
21+
}
22+
23+
XCTAssertNotNil(actualOptions, "start have not provided default options or have not executed configure callback")
24+
assertReactDefaults(actualOptions)
25+
}
26+
27+
func testAutoStartSetsReactDefaults() throws {
28+
try startFromRN(options: [
29+
"dsn": "https://[email protected]/123456"
30+
])
31+
32+
let actualOptions = PrivateSentrySDKOnly.options
33+
assertReactDefaults(actualOptions)
34+
}
35+
36+
func testStartEnablesHybridTracing() throws {
37+
let testCases: [() throws -> Void] = [
38+
{
39+
RNSentrySDK.start { options in
40+
options.dsn = "https://[email protected]/123456"
41+
}
42+
},
43+
{
44+
try self.startFromRN(options: [
45+
"dsn": "https://[email protected]/123456"
46+
])
47+
},
48+
{
49+
RNSentrySDK.start { options in
50+
options.dsn = "https://[email protected]/123456"
51+
options.enableAutoPerformanceTracing = true
52+
}
53+
},
54+
{
55+
try self.startFromRN(options: [
56+
"dsn": "https://[email protected]/123456",
57+
"enableAutoPerformanceTracing": true
58+
])
59+
}
60+
]
61+
62+
// Test each implementation
63+
for startMethod in testCases {
64+
try startMethod()
65+
66+
let actualOptions = PrivateSentrySDKOnly.options
67+
68+
XCTAssertTrue(PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode)
69+
XCTAssertTrue(PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode)
70+
}
71+
}
72+
73+
func testStartDisablesHybridTracing() throws {
74+
let testCases: [() throws -> Void] = [
75+
{
76+
RNSentrySDK.start { options in
77+
options.dsn = "https://[email protected]/123456"
78+
options.enableAutoPerformanceTracing = false
79+
}
80+
},
81+
{
82+
try self.startFromRN(options: [
83+
"dsn": "https://[email protected]/123456",
84+
"enableAutoPerformanceTracing": false
85+
])
86+
}
87+
]
88+
89+
for startMethod in testCases {
90+
try startMethod()
91+
92+
let actualOptions = PrivateSentrySDKOnly.options
93+
94+
XCTAssertFalse(PrivateSentrySDKOnly.appStartMeasurementHybridSDKMode)
95+
XCTAssertFalse(PrivateSentrySDKOnly.framesTrackingMeasurementHybridSDKMode)
96+
}
97+
}
98+
99+
func testStartIgnoresUnhandledJsExceptions() throws {
100+
let testCases: [() throws -> Void] = [
101+
{
102+
RNSentrySDK.start { options in
103+
options.dsn = "https://[email protected]/123456"
104+
}
105+
},
106+
{
107+
try self.startFromRN(options: [
108+
"dsn": "https://[email protected]/123456"
109+
])
110+
}
111+
]
112+
113+
for startMethod in testCases {
114+
try startMethod()
115+
116+
let actualOptions = PrivateSentrySDKOnly.options
117+
118+
let actualEvent = actualOptions.beforeSend!(createUnhandledJsExceptionEvent())
119+
120+
XCTAssertNil(actualEvent)
121+
}
122+
}
123+
124+
func testStartSetsNativeEventOrigin() throws {
125+
let testCases: [() throws -> Void] = [
126+
{
127+
RNSentrySDK.start { options in
128+
options.dsn = "https://[email protected]/123456"
129+
}
130+
},
131+
{
132+
try self.startFromRN(options: [
133+
"dsn": "https://[email protected]/123456"
134+
])
135+
}
136+
]
137+
138+
for startMethod in testCases {
139+
try startMethod()
140+
141+
let actualOptions = PrivateSentrySDKOnly.options
142+
143+
let actualEvent = actualOptions.beforeSend!(createNativeEvent())
144+
145+
XCTAssertNotNil(actualEvent)
146+
XCTAssertNotNil(actualEvent!.tags)
147+
XCTAssertEqual(actualEvent!.tags!["event.origin"], "ios")
148+
XCTAssertEqual(actualEvent!.tags!["event.environment"], "native")
149+
}
150+
}
151+
152+
func testStartDoesNotOverwriteUserBeforeSend() {
153+
var executed = false
154+
155+
RNSentrySDK.start { options in
156+
options.dsn = "https://[email protected]/123456"
157+
options.beforeSend = { event in
158+
executed = true
159+
return event
160+
}
161+
}
162+
163+
PrivateSentrySDKOnly.options.beforeSend!(genericEvent())
164+
165+
XCTAssertTrue(executed)
166+
}
167+
168+
func testStartSetsHybridSdkName() throws {
169+
let testCases: [() throws -> Void] = [
170+
{
171+
RNSentrySDK.start { options in
172+
options.dsn = "https://[email protected]/123456"
173+
}
174+
},
175+
{
176+
try self.startFromRN(options: [
177+
"dsn": "https://[email protected]/123456"
178+
])
179+
}
180+
]
181+
182+
for startMethod in testCases {
183+
try startMethod()
184+
185+
let actualEvent = captuteTestEvent()
186+
187+
XCTAssertNotNil(actualEvent)
188+
XCTAssertNotNil(actualEvent!.sdk)
189+
XCTAssertEqual(actualEvent!.sdk!["name"] as! String, NATIVE_SDK_NAME)
190+
191+
let packages = actualEvent!.sdk!["packages"] as! [[String: String]]
192+
let reactPackage = packages.first { $0["name"] == REACT_NATIVE_SDK_PACKAGE_NAME }
193+
194+
XCTAssertNotNil(reactPackage)
195+
XCTAssertEqual(reactPackage!["name"], REACT_NATIVE_SDK_PACKAGE_NAME)
196+
XCTAssertEqual(reactPackage!["version"], REACT_NATIVE_SDK_PACKAGE_VERSION)
197+
}
198+
}
199+
200+
func startFromRN(options: [String: Any]) throws {
201+
var error: NSError?
202+
RNSentryStart.start(options: options, error: &error)
203+
204+
if let error = error {
205+
throw error
206+
}
207+
}
208+
209+
func createUnhandledJsExceptionEvent() -> Event {
210+
let event = Event()
211+
event.exceptions = []
212+
event.exceptions!.append(Exception(value: "Test", type: "Unhandled JS Exception: undefined is not a function"))
213+
return event
214+
}
215+
216+
func createNativeEvent() -> Event {
217+
let event = Event()
218+
event.sdk = [
219+
"name": NATIVE_SDK_NAME,
220+
"version": "1.2.3"
221+
]
222+
return event
223+
}
224+
225+
func genericEvent() -> Event {
226+
return Event()
227+
}
228+
229+
func captuteTestEvent() -> Event? {
230+
var actualEvent: Event?
231+
232+
// This is the closest to the sent event we can get using the actual Sentry start method
233+
let originalBeforeSend = PrivateSentrySDKOnly.options.beforeSend
234+
PrivateSentrySDKOnly.options.beforeSend = { event in
235+
if let originalBeforeSend = originalBeforeSend {
236+
let processedEvent = originalBeforeSend(event)
237+
actualEvent = processedEvent
238+
return processedEvent
239+
}
240+
actualEvent = event
241+
return event
242+
}
243+
244+
SentrySDK.capture(message: "Test")
245+
246+
return actualEvent
247+
}
248+
}

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#import "RNSentryStart+Test.h"
33
#import <OCMock/OCMock.h>
44
#import <RNSentry/RNSentry.h>
5+
#import <Sentry/PrivateSentrySDKOnly.h>
56
#import <Sentry/SentryDebugImageProvider+HybridSDKs.h>
67
#import <UIKit/UIKit.h>
78
#import <XCTest/XCTest.h>
@@ -12,7 +13,7 @@ @interface RNSentryInitNativeSdkTests : XCTestCase
1213

1314
@implementation RNSentryInitNativeSdkTests
1415

15-
- (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties
16+
- (void)testStartWithDictionaryRemovesPerformanceProperties
1617
{
1718
NSError *error = nil;
1819

@@ -25,9 +26,8 @@ - (void)testCreateOptionsWithDictionaryRemovesPerformanceProperties
2526
, @"enableTracing" : @YES,
2627
}
2728
;
28-
SentryOptions *actualOptions =
29-
[RNSentryStart createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
30-
29+
[RNSentryStart startWithOptions:mockedReactNativeDictionary error:&error];
30+
SentryOptions *actualOptions = PrivateSentrySDKOnly.options;
3131
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
3232
XCTAssertNil(error, @"Should not pass no error");
3333
XCTAssertNotNil(
@@ -45,8 +45,8 @@ - (void)testCaptureFailedRequestsIsDisabled
4545
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
4646
@"dsn" : @"https://[email protected]/123456",
4747
};
48-
SentryOptions *actualOptions =
49-
[RNSentryStart createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
48+
[RNSentryStart startWithOptions:mockedReactNativeDictionary error:&error];
49+
SentryOptions *actualOptions = PrivateSentrySDKOnly.options;
5050

5151
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
5252
XCTAssertNil(error, @"Should not pass no error");

packages/core/ios/RNSentry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#import <Sentry/SentryDebugImageProvider.h>
1212
#import <Sentry/SentryOptions.h>
1313

14+
// This import exposes public RNSentrySDK start
15+
#import "RNSentrySDK.h"
16+
1417
typedef int (*SymbolicateCallbackType)(const void *, Dl_info *);
1518

1619
@interface

packages/core/ios/RNSentry.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,11 @@ - (instancetype)init
9494
: (RCTPromiseRejectBlock)reject)
9595
{
9696
NSError *error = nil;
97-
SentryOptions *sentryOptions = [RNSentryStart createOptionsWithDictionary:options error:&error];
97+
[RNSentryStart startWithOptions:options error:&error];
9898
if (error != nil) {
9999
reject(@"SentryReactNative", error.localizedDescription, error);
100100
return;
101101
}
102-
103-
[RNSentryStart startWithOptions:sentryOptions];
104102
resolve(@YES);
105103
}
106104

0 commit comments

Comments
 (0)