Skip to content

Commit

Permalink
Enable Spotlight in Android and iOS SDKs (#4211)
Browse files Browse the repository at this point in the history
* 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 <lucas-zimerman1@hotmail.com>
  • Loading branch information
antonis and lucas-zimerman authored Oct 31, 2024
1 parent 1faf8e3 commit 9cab16b
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 126 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
- Skips ignoring require cycle logs for RN 0.70 or newer ([#4214](https://github.com/getsentry/sentry-react-native/pull/4214))
- Enhanced accuracy of time-to-display spans. ([#4189](https://github.com/getsentry/sentry-react-native/pull/4189))

### Features

- Enables Spotlight in Android and iOS SDKs ([#4211](https://github.com/getsentry/sentry-react-native/pull/4211))

### Dependencies

- Bump JavaScript SDK from v8.34.0 to v8.35.0 ([#4196](https://github.com/getsentry/sentry-react-native/pull/4196))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package io.sentry.react
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.JavaOnlyMap
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import io.sentry.ILogger
import io.sentry.SentryLevel
import io.sentry.android.core.SentryAndroidOptions
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down Expand Up @@ -93,4 +96,33 @@ class RNSentryModuleImplTest {
val capturedMap = writableMapCaptor.value
assertEquals(false, capturedMap.getBoolean("has_fetched"))
}

@Test
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() {
val options = JavaOnlyMap.of(
"spotlight", true,
"defaultSidecarUrl", "http://localhost:8969/teststream"
)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assert(actualOptions.isEnableSpotlight)
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
}

@Test
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
val options = JavaOnlyMap.of("spotlight", false)
val actualOptions = SentryAndroidOptions()
module.getSentryAndroidOptions(actualOptions, options, logger)
assertFalse(actualOptions.isEnableSpotlight)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,86 @@ - (void)testCreateOptionsWithDictionaryAutoPerformanceTracingDisabled
XCTAssertEqual(actualOptions.enableAutoPerformanceTracing, false, @"Did not disable Auto Performance Tracing");
}

- (void)testCreateOptionsWithDictionarySpotlightEnabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://abcd@efgh.ingest.sentry.io/123456",
@"spotlight": @YES,
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightOne
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://abcd@efgh.ingest.sentry.io/123456",
@"spotlight": @1,
@"defaultSidecarUrl": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightUrl
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://abcd@efgh.ingest.sentry.io/123456",
@"spotlight": @"http://localhost:8969/teststream",
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertTrue(actualOptions.enableSpotlight , @"Did not enable spotlight");
XCTAssertEqual(actualOptions.spotlightUrl , @"http://localhost:8969/teststream");
}

- (void)testCreateOptionsWithDictionarySpotlightDisabled
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://abcd@efgh.ingest.sentry.io/123456",
@"spotlight": @NO,
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
}

- (void)testCreateOptionsWithDictionarySpotlightZero
{
RNSentry * rnSentry = [[RNSentry alloc] init];
NSError* error = nil;

NSDictionary *_Nonnull mockedReactNativeDictionary = @{
@"dsn": @"https://abcd@efgh.ingest.sentry.io/123456",
@"spotlight": @0,
};
SentryOptions* actualOptions = [rnSentry createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
XCTAssertNil(error, @"Should not pass no error");
XCTAssertFalse(actualOptions.enableSpotlight, @"Did not disable spotlight");
}

- (void)testPassesErrorOnWrongDsn
{
RNSentry * rnSentry = [[RNSentry alloc] init];
Expand Down
Loading

0 comments on commit 9cab16b

Please sign in to comment.