Skip to content

Commit

Permalink
Use env from SentryOptions if none persisted in ANRv2 (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn authored Jun 30, 2023
1 parent 675fc87 commit c03a05e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Add manifest `AutoInit` to integrations list ([#2795](https://github.com/getsentry/sentry-java/pull/2795))
- 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))

### Fixes

- Set `environment` from `SentryOptions` if none persisted in ANRv2 ([#2809](https://github.com/getsentry/sentry-java/pull/2809))

### Dependencies

- Bump Native SDK from v0.6.3 to v0.6.4 ([#2796](https://github.com/getsentry/sentry-java/pull/2796))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.sentry.SentryEvent;
import io.sentry.SentryExceptionFactory;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.SentryStackTraceFactory;
import io.sentry.SpanContext;
import io.sentry.android.core.internal.util.CpuInfoUtils;
Expand Down Expand Up @@ -69,12 +68,6 @@
@WorkerThread
public final class AnrV2EventProcessor implements BackfillingEventProcessor {

/**
* Default value for {@link SentryEvent#getEnvironment()} set when both event and {@link
* SentryOptions} do not have the environment field set.
*/
static final String DEFAULT_ENVIRONMENT = "production";

private final @NotNull Context context;

private final @NotNull SentryAndroidOptions options;
Expand Down Expand Up @@ -337,7 +330,7 @@ private void setEnvironment(final @NotNull SentryBaseEvent event) {
if (event.getEnvironment() == null) {
final String environment =
PersistingOptionsObserver.read(options, ENVIRONMENT_FILENAME, String.class);
event.setEnvironment(environment != null ? environment : DEFAULT_ENVIRONMENT);
event.setEnvironment(environment != null ? environment : options.getEnvironment());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class AnrV2EventProcessorTest {
populateOptionsCache: Boolean = false
): AnrV2EventProcessor {
options.cacheDirPath = dir.newFolder().absolutePath
options.environment = "release"
whenever(buildInfo.sdkInfoVersion).thenReturn(currentSdk)
whenever(buildInfo.isEmulator).thenReturn(true)

Expand Down Expand Up @@ -337,12 +338,12 @@ class AnrV2EventProcessorTest {
}

@Test
fun `if environment is not persisted, uses default`() {
fun `if environment is not persisted, uses environment from options`() {
val hint = HintUtils.createWithTypeCheckHint(BackfillableHint())

val processed = processEvent(hint)

assertEquals(AnrV2EventProcessor.DEFAULT_ENVIRONMENT, processed.environment)
assertEquals("release", processed.environment)
}

@Test
Expand Down

0 comments on commit c03a05e

Please sign in to comment.