Skip to content

Commit 8ec2c16

Browse files
lbloderromtsn
andauthored
Fix wrong default environment in Session (getsentry#2610)
Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
1 parent db18794 commit 8ec2c16

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fix wrong default environment in Session ([#2610](https://github.com/getsentry/sentry-java/pull/2610))
8+
39
## 6.16.0
410

511
### Features

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class ManifestMetadataReaderTest {
164164
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
165165

166166
// Assert
167-
assertNull(fixture.options.environment)
167+
assertEquals("production", fixture.options.environment)
168168
}
169169

170170
@Test

sentry/src/main/java/io/sentry/MainEventProcessor.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
@ApiStatus.Internal
2424
public final class MainEventProcessor implements EventProcessor, Closeable {
2525

26-
/**
27-
* Default value for {@link SentryEvent#getEnvironment()} set when both event and {@link
28-
* SentryOptions} do not have the environment field set.
29-
*/
30-
private static final String DEFAULT_ENVIRONMENT = "production";
31-
3226
private final @NotNull SentryOptions options;
3327
private final @NotNull SentryThreadFactory sentryThreadFactory;
3428
private final @NotNull SentryExceptionFactory sentryExceptionFactory;
@@ -163,8 +157,7 @@ private void setRelease(final @NotNull SentryBaseEvent event) {
163157

164158
private void setEnvironment(final @NotNull SentryBaseEvent event) {
165159
if (event.getEnvironment() == null) {
166-
event.setEnvironment(
167-
options.getEnvironment() != null ? options.getEnvironment() : DEFAULT_ENVIRONMENT);
160+
event.setEnvironment(options.getEnvironment());
168161
}
169162
}
170163

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public class SentryOptions {
4444
/** Default Log level if not specified Default is DEBUG */
4545
static final SentryLevel DEFAULT_DIAGNOSTIC_LEVEL = SentryLevel.DEBUG;
4646

47+
/**
48+
* Default value for {@link SentryEvent#getEnvironment()} set when {@link SentryOptions} do not
49+
* have the environment field set.
50+
*/
51+
private static final String DEFAULT_ENVIRONMENT = "production";
52+
4753
/**
4854
* Are callbacks that run for every event. They can either return a new event which in most cases
4955
* means just adding data OR return null in case the event will be dropped and not sent.
@@ -771,10 +777,10 @@ public void setRelease(@Nullable String release) {
771777
/**
772778
* Returns the environment
773779
*
774-
* @return the environment or null if not set
780+
* @return the environment or 'production' if not set
775781
*/
776782
public @Nullable String getEnvironment() {
777-
return environment;
783+
return environment != null ? environment : DEFAULT_ENVIRONMENT;
778784
}
779785

780786
/**

sentry/src/test/java/io/sentry/SentryOptionsTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,20 @@ class SentryOptionsTest {
320320
assertTrue(options.scopeObservers.contains(observer))
321321
}
322322

323+
@Test
324+
fun `when environment is not set, falls back to default value`() {
325+
val options = SentryOptions()
326+
assertEquals("production", options.environment)
327+
}
328+
329+
@Test
330+
fun `when environment is set, correct value is returned`() {
331+
val options = SentryOptions().apply {
332+
environment = "debug"
333+
}
334+
assertEquals("debug", options.environment)
335+
}
336+
323337
@Test
324338
fun `copies options from another SentryOptions instance`() {
325339
val externalOptions = ExternalOptions()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy