Skip to content

Commit d2fd58f

Browse files
committed
Set current activity in defaults
1 parent 43b26db commit d2fd58f

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class RNSentryStartTest {
4040
"http://localhost:8969/teststream",
4141
)
4242
val actualOptions = SentryAndroidOptions()
43-
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
43+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, logger)
4444
assert(actualOptions.isEnableSpotlight)
4545
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
4646
}
@@ -49,7 +49,7 @@ class RNSentryStartTest {
4949
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() {
5050
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream")
5151
val actualOptions = SentryAndroidOptions()
52-
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
52+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, logger)
5353
assert(actualOptions.isEnableSpotlight)
5454
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl)
5555
}
@@ -58,14 +58,14 @@ class RNSentryStartTest {
5858
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() {
5959
val options = JavaOnlyMap.of("spotlight", false)
6060
val actualOptions = SentryAndroidOptions()
61-
RNSentryStart.getSentryAndroidOptions(actualOptions, options, activity, logger)
61+
RNSentryStart.getSentryAndroidOptions(actualOptions, options, logger)
6262
assertFalse(actualOptions.isEnableSpotlight)
6363
}
6464

6565
@Test
6666
fun `the JavascriptException is added to the ignoredExceptionsForType list on with react defaults`() {
6767
val actualOptions = SentryAndroidOptions()
68-
RNSentryStart.updateWithReactDefaults(actualOptions)
68+
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
6969
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
7070
}
7171

@@ -79,7 +79,7 @@ class RNSentryStartTest {
7979
"devServerUrl",
8080
"http://localhost:8081",
8181
)
82-
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
82+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)
8383

8484
val breadcrumb =
8585
Breadcrumb().apply {
@@ -103,7 +103,7 @@ class RNSentryStartTest {
103103
"devServerUrl",
104104
mockDevServerUrl,
105105
)
106-
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
106+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)
107107

108108
val breadcrumb =
109109
Breadcrumb().apply {
@@ -126,7 +126,7 @@ class RNSentryStartTest {
126126
"devServerUrl",
127127
"http://localhost:8081",
128128
)
129-
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
129+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)
130130

131131
val breadcrumb =
132132
Breadcrumb().apply {
@@ -142,7 +142,7 @@ class RNSentryStartTest {
142142
@Test
143143
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() {
144144
val options = SentryAndroidOptions()
145-
RNSentryStart.getSentryAndroidOptions(options, JavaOnlyMap(), activity, logger)
145+
RNSentryStart.getSentryAndroidOptions(options, JavaOnlyMap(), logger)
146146

147147
val breadcrumb =
148148
Breadcrumb().apply {
@@ -159,7 +159,7 @@ class RNSentryStartTest {
159159
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() {
160160
val options = SentryAndroidOptions()
161161
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567")
162-
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
162+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)
163163

164164
val breadcrumb =
165165
Breadcrumb().apply {
@@ -176,7 +176,7 @@ class RNSentryStartTest {
176176
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() {
177177
val options = SentryAndroidOptions()
178178
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081")
179-
RNSentryStart.getSentryAndroidOptions(options, rnOptions, activity, logger)
179+
RNSentryStart.getSentryAndroidOptions(options, rnOptions, logger)
180180

181181
val breadcrumb =
182182
Breadcrumb().apply {

packages/core/android/src/main/java/io/sentry/react/RNSentryStart.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ private RNSentryStart() {
3838
static void startWithConfiguration(
3939
@NotNull final Context context,
4040
@NotNull Sentry.OptionsConfiguration<SentryAndroidOptions> configuration) {
41+
Sentry.OptionsConfiguration<SentryAndroidOptions> defaults =
42+
options -> updateWithReactDefaults(options, null);
4143
RNSentryCompositeOptionsConfiguration compositeConfiguration =
4244
new RNSentryCompositeOptionsConfiguration(
43-
RNSentryStart::updateWithReactDefaults,
44-
configuration,
45-
RNSentryStart::updateWithReactFinals);
45+
defaults, configuration, RNSentryStart::updateWithReactFinals);
4646
SentryAndroid.init(context, compositeConfiguration);
4747
}
4848

@@ -51,14 +51,13 @@ static void startWithOptions(
5151
@NotNull final ReadableMap rnOptions,
5252
@NotNull Sentry.OptionsConfiguration<SentryAndroidOptions> configuration,
5353
@NotNull ILogger logger) {
54+
Sentry.OptionsConfiguration<SentryAndroidOptions> defaults =
55+
options -> updateWithReactDefaults(options, null);
5456
Sentry.OptionsConfiguration<SentryAndroidOptions> rnConfigurationOptions =
55-
options -> getSentryAndroidOptions(options, rnOptions, null, logger);
57+
options -> getSentryAndroidOptions(options, rnOptions, logger);
5658
RNSentryCompositeOptionsConfiguration compositeConfiguration =
5759
new RNSentryCompositeOptionsConfiguration(
58-
RNSentryStart::updateWithReactDefaults,
59-
rnConfigurationOptions,
60-
configuration,
61-
RNSentryStart::updateWithReactFinals);
60+
defaults, rnConfigurationOptions, configuration, RNSentryStart::updateWithReactFinals);
6261
SentryAndroid.init(context, compositeConfiguration);
6362
}
6463

@@ -67,21 +66,20 @@ static void startWithOptions(
6766
@NotNull final ReadableMap rnOptions,
6867
@Nullable Activity currentActivity,
6968
@NotNull ILogger logger) {
69+
Sentry.OptionsConfiguration<SentryAndroidOptions> defaults =
70+
options -> updateWithReactDefaults(options, currentActivity);
7071
Sentry.OptionsConfiguration<SentryAndroidOptions> rnConfigurationOptions =
71-
options -> getSentryAndroidOptions(options, rnOptions, currentActivity, logger);
72+
options -> getSentryAndroidOptions(options, rnOptions, logger);
7273
RNSentryCompositeOptionsConfiguration compositeConfiguration =
7374
new RNSentryCompositeOptionsConfiguration(
74-
RNSentryStart::updateWithReactDefaults,
75-
rnConfigurationOptions,
76-
RNSentryStart::updateWithReactFinals);
75+
defaults, rnConfigurationOptions, RNSentryStart::updateWithReactFinals);
7776
SentryAndroid.init(context, compositeConfiguration);
7877
}
7978

8079
static void getSentryAndroidOptions(
8180
@NotNull SentryAndroidOptions options,
8281
@NotNull ReadableMap rnOptions,
83-
@Nullable Activity currentActivity,
84-
ILogger logger) {
82+
@NotNull ILogger logger) {
8583
if (rnOptions.hasKey("debug") && rnOptions.getBoolean("debug")) {
8684
options.setDebug(true);
8785
}
@@ -193,24 +191,23 @@ static void getSentryAndroidOptions(
193191
}
194192
logger.log(
195193
SentryLevel.INFO, String.format("Native Integrations '%s'", options.getIntegrations()));
196-
197-
setCurrentActivity(currentActivity);
198194
}
199195

200196
/**
201197
* This function updates the options with RNSentry defaults. These default can be overwritten by
202198
* users during manual native initialization.
203199
*/
204-
static void updateWithReactDefaults(@NotNull SentryAndroidOptions options) {
200+
static void updateWithReactDefaults(
201+
@NotNull SentryAndroidOptions options, @Nullable Activity currentActivity) {
205202
@Nullable SdkVersion sdkVersion = options.getSdkVersion();
206203
if (sdkVersion == null) {
207204
sdkVersion = new SdkVersion(RNSentryVersion.ANDROID_SDK_NAME, BuildConfig.VERSION_NAME);
208205
} else {
209206
sdkVersion.setName(RNSentryVersion.ANDROID_SDK_NAME);
210207
}
211208
sdkVersion.addPackage(
212-
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
213-
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION);
209+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
210+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION);
214211

215212
options.setSentryClientName(sdkVersion.getName() + "/" + sdkVersion.getVersion());
216213
options.setNativeSdkName(RNSentryVersion.NATIVE_SDK_NAME);
@@ -224,6 +221,8 @@ static void updateWithReactDefaults(@NotNull SentryAndroidOptions options) {
224221
// React native internally throws a JavascriptException.
225222
// we want to ignore it on the native side to avoid sending it twice.
226223
options.addIgnoredExceptionForType(JavascriptException.class);
224+
225+
setCurrentActivity(currentActivity);
227226
}
228227

229228
/**

0 commit comments

Comments
 (0)