Skip to content

Commit 9cab16b

Browse files
Enable Spotlight in Android and iOS SDKs (#4211)
* Passes spotlight initialisation option to the native SDKs * Adds changelog * Extracts getSentryAndroidOptions method and adds test * Handles spotlight url parameters in cocoa * Handles spotlight url parameters in java * Pass the RN JS defaultSidecarUrl to the platform layers when Spotlight is enabled --------- Co-authored-by: LucasZF <[email protected]>
1 parent 1faf8e3 commit 9cab16b

File tree

9 files changed

+296
-126
lines changed

9 files changed

+296
-126
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
- Skips ignoring require cycle logs for RN 0.70 or newer ([#4214](https://github.com/getsentry/sentry-react-native/pull/4214))
1414
- Enhanced accuracy of time-to-display spans. ([#4189](https://github.com/getsentry/sentry-react-native/pull/4189))
1515

16+
### Features
17+
18+
- Enables Spotlight in Android and iOS SDKs ([#4211](https://github.com/getsentry/sentry-react-native/pull/4211))
19+
1620
### Dependencies
1721

1822
- Bump JavaScript SDK from v8.34.0 to v8.35.0 ([#4196](https://github.com/getsentry/sentry-react-native/pull/4196))

packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryModuleImplTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package io.sentry.react
33
import android.content.pm.PackageInfo
44
import android.content.pm.PackageManager
55
import com.facebook.react.bridge.Arguments
6+
import com.facebook.react.bridge.JavaOnlyMap
67
import com.facebook.react.bridge.Promise
78
import com.facebook.react.bridge.ReactApplicationContext
89
import com.facebook.react.bridge.WritableMap
910
import io.sentry.ILogger
1011
import io.sentry.SentryLevel
12+
import io.sentry.android.core.SentryAndroidOptions
1113
import org.junit.After
1214
import org.junit.Assert.assertEquals
15+
import org.junit.Assert.assertFalse
1316
import org.junit.Before
1417
import org.junit.Test
1518
import org.junit.runner.RunWith
@@ -93,4 +96,33 @@ class RNSentryModuleImplTest {
9396
val capturedMap = writableMapCaptor.value
9497
assertEquals(false, capturedMap.getBoolean("has_fetched"))
9598
}
99+
100+
@Test
101+
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
102+
val options = JavaOnlyMap.of(
103+
"spotlight", true,
104+
"defaultSidecarUrl", "http://localhost:8969/teststream"
105+
)
106+
val actualOptions = SentryAndroidOptions()
107+
module.getSentryAndroidOptions(actualOptions, options, logger)
108+
assert(actualOptions.isEnableSpotlight)
109+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
110+
}
111+
112+
@Test
113+
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
114+
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
115+
val actualOptions = SentryAndroidOptions()
116+
module.getSentryAndroidOptions(actualOptions, options, logger)
117+
assert(actualOptions.isEnableSpotlight)
118+
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
119+
}
120+
121+
@Test
122+
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
123+
val options = JavaOnlyMap.of("spotlight", false)
124+
val actualOptions = SentryAndroidOptions()
125+
module.getSentryAndroidOptions(actualOptions, options, logger)
126+
assertFalse(actualOptions.isEnableSpotlight)
127+
}
96128
}

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.mm

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,86 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled
122122
XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, false, @"Did not disable Auto Performance Tracing");
123123
}
124124

125+
- (void)testCreateOptionsWithDictionarySpotlightEnabled
126+
{
127+
RNSentry * rnSentry = [[RNSentry alloc] init];
128+
NSError* error = nil;
129+
130+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
131+
@"dsn": @"https://[email protected]/123456",
132+
@"spotlight": @YES,
133+
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
134+
};
135+
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
136+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
137+
XCTAssertNil(error, @"Should not pass no error");
138+
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
139+
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
140+
}
141+
142+
- (void)testCreateOptionsWithDictionarySpotlightOne
143+
{
144+
RNSentry * rnSentry = [[RNSentry alloc] init];
145+
NSError* error = nil;
146+
147+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
148+
@"dsn": @"https://[email protected]/123456",
149+
@"spotlight": @1,
150+
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
151+
};
152+
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
153+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
154+
XCTAssertNil(error, @"Should not pass no error");
155+
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
156+
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
157+
}
158+
159+
- (void)testCreateOptionsWithDictionarySpotlightUrl
160+
{
161+
RNSentry * rnSentry = [[RNSentry alloc] init];
162+
NSError* error = nil;
163+
164+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
165+
@"dsn": @"https://[email protected]/123456",
166+
@"spotlight": @"http://localhost:8969/teststream",
167+
};
168+
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
169+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
170+
XCTAssertNil(error, @"Should not pass no error");
171+
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
172+
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
173+
}
174+
175+
- (void)testCreateOptionsWithDictionarySpotlightDisabled
176+
{
177+
RNSentry * rnSentry = [[RNSentry alloc] init];
178+
NSError* error = nil;
179+
180+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
181+
@"dsn": @"https://[email protected]/123456",
182+
@"spotlight": @NO,
183+
};
184+
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
185+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
186+
XCTAssertNil(error, @"Should not pass no error");
187+
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
188+
}
189+
190+
- (void)testCreateOptionsWithDictionarySpotlightZero
191+
{
192+
RNSentry * rnSentry = [[RNSentry alloc] init];
193+
NSError* error = nil;
194+
195+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
196+
@"dsn": @"https://[email protected]/123456",
197+
@"spotlight": @0,
198+
};
199+
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
200+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
201+
XCTAssertNil(error, @"Should not pass no error");
202+
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
203+
}
204+
125205
- (void)testPassesErrorOnWrongDsn
126206
{
127207
RNSentry * rnSentry = [[RNSentry alloc] init];

0 commit comments

Comments
 (0)