Skip to content

Commit c03a05e

Browse files
authored
Use env from SentryOptions if none persisted in ANRv2 (#2809)
1 parent 675fc87 commit c03a05e

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- Add manifest `AutoInit` to integrations list ([#2795](https://github.com/getsentry/sentry-java/pull/2795))
88
- Tracing headers (`sentry-trace` and `baggage`) are now attached and passed through even if performance is disabled ([#2788](https://github.com/getsentry/sentry-java/pull/2788))
99

10+
### Fixes
11+
12+
- Set `environment` from `SentryOptions` if none persisted in ANRv2 ([#2809](https://github.com/getsentry/sentry-java/pull/2809))
13+
1014
### Dependencies
1115

1216
- Bump Native SDK from v0.6.3 to v0.6.4 ([#2796](https://github.com/getsentry/sentry-java/pull/2796))

sentry-android-core/src/main/java/io/sentry/android/core/AnrV2EventProcessor.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import io.sentry.SentryEvent;
3131
import io.sentry.SentryExceptionFactory;
3232
import io.sentry.SentryLevel;
33-
import io.sentry.SentryOptions;
3433
import io.sentry.SentryStackTraceFactory;
3534
import io.sentry.SpanContext;
3635
import io.sentry.android.core.internal.util.CpuInfoUtils;
@@ -69,12 +68,6 @@
6968
@WorkerThread
7069
public final class AnrV2EventProcessor implements BackfillingEventProcessor {
7170

72-
/**
73-
* Default value for {@link SentryEvent#getEnvironment()} set when both event and {@link
74-
* SentryOptions} do not have the environment field set.
75-
*/
76-
static final String DEFAULT_ENVIRONMENT = "production";
77-
7871
private final @NotNull Context context;
7972

8073
private final @NotNull SentryAndroidOptions options;
@@ -337,7 +330,7 @@ private void setEnvironment(final @NotNull SentryBaseEvent event) {
337330
if (event.getEnvironment() == null) {
338331
final String environment =
339332
PersistingOptionsObserver.read(options, ENVIRONMENT_FILENAME, String.class);
340-
event.setEnvironment(environment != null ? environment : DEFAULT_ENVIRONMENT);
333+
event.setEnvironment(environment != null ? environment : options.getEnvironment());
341334
}
342335
}
343336

sentry-android-core/src/test/java/io/sentry/android/core/AnrV2EventProcessorTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class AnrV2EventProcessorTest {
8989
populateOptionsCache: Boolean = false
9090
): AnrV2EventProcessor {
9191
options.cacheDirPath = dir.newFolder().absolutePath
92+
options.environment = "release"
9293
whenever(buildInfo.sdkInfoVersion).thenReturn(currentSdk)
9394
whenever(buildInfo.isEmulator).thenReturn(true)
9495

@@ -337,12 +338,12 @@ class AnrV2EventProcessorTest {
337338
}
338339

339340
@Test
340-
fun `if environment is not persisted, uses default`() {
341+
fun `if environment is not persisted, uses environment from options`() {
341342
val hint = HintUtils.createWithTypeCheckHint(BackfillableHint())
342343

343344
val processed = processEvent(hint)
344345

345-
assertEquals(AnrV2EventProcessor.DEFAULT_ENVIRONMENT, processed.environment)
346+
assertEquals("release", processed.environment)
346347
}
347348

348349
@Test

0 commit comments

Comments
 (0)