Skip to content

Commit b5de18d

Browse files
authored
Merge branch 'main' into feat/global-attributes-api
2 parents 1c603b0 + 815e034 commit b5de18d

File tree

8 files changed

+52
-0
lines changed

8 files changed

+52
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Automatically include scope attributes in logs and metrics ([#5120](https://github.com/getsentry/sentry-java/pull/5120))
99
- New APIs are `Sentry.setAttribute`, `Sentry.setAttributes`, `Sentry.removeAttribute`
1010
- Support collections and arrays in attribute type inference ([#5124](https://github.com/getsentry/sentry-java/pull/5124))
11+
- Add support for `SENTRY_SAMPLE_RATE` environment variable / `sample-rate` property ([#5112](https://github.com/getsentry/sentry-java/pull/5112))
1112
- Create `sentry-opentelemetry-otlp` and `sentry-opentelemetry-otlp-spring` modules for combining OpenTelemetry SDK OTLP export with Sentry SDK ([#5100](https://github.com/getsentry/sentry-java/pull/5100))
1213
- OpenTelemetry is configured to send spans to Sentry directly using an OTLP endpoint.
1314
- Sentry only uses trace and span ID from OpenTelemetry (via `OpenTelemetryOtlpEventProcessor`) but will not send spans through OpenTelemetry nor use OpenTelemetry `Context` for `Scopes` propagation.
@@ -31,6 +32,7 @@
3132
<meta-data android:name="io.sentry.screenshot.mask-all-text" android:value="true" />
3233
<meta-data android:name="io.sentry.screenshot.mask-all-images" android:value="true" />
3334
```
35+
- The `ManifestMetaDataReader` now read the `DIST` ([#5107](https://github.com/getsentry/sentry-java/pull/5107))
3436

3537
### Fixes
3638

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ final class ManifestMetadataReader {
4141
static final String NDK_SCOPE_SYNC_ENABLE = "io.sentry.ndk.scope-sync.enable";
4242
static final String NDK_SDK_NAME = "io.sentry.ndk.sdk-name";
4343
static final String RELEASE = "io.sentry.release";
44+
static final String DIST = "io.sentry.dist";
4445
static final String ENVIRONMENT = "io.sentry.environment";
4546
static final String SDK_NAME = "io.sentry.sdk.name";
4647
static final String SDK_VERSION = "io.sentry.sdk.version";
@@ -273,6 +274,8 @@ static void applyMetadata(
273274

274275
options.setRelease(readString(metadata, logger, RELEASE, options.getRelease()));
275276

277+
options.setDist(readString(metadata, logger, DIST, options.getDist()));
278+
276279
options.setEnvironment(readString(metadata, logger, ENVIRONMENT, options.getEnvironment()));
277280

278281
options.setSessionTrackingIntervalMillis(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,31 @@ class ManifestMetadataReaderTest {
187187
assertNull(fixture.options.release)
188188
}
189189

190+
@Test
191+
fun `applyMetadata reads dist to options`() {
192+
// Arrange
193+
val bundle = bundleOf(ManifestMetadataReader.DIST to "test-dist")
194+
val context = fixture.getContext(metaData = bundle)
195+
196+
// Act
197+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
198+
199+
// Assert
200+
assertEquals("test-dist", fixture.options.dist)
201+
}
202+
203+
@Test
204+
fun `applyMetadata reads dist and keep default value if not found`() {
205+
// Arrange
206+
val context = fixture.getContext()
207+
208+
// Act
209+
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
210+
211+
// Assert
212+
assertNull(fixture.options.dist)
213+
}
214+
190215
@Test
191216
fun `applyMetadata reads session tracking interval to options`() {
192217
// Arrange

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ public final class io/sentry/ExternalOptions {
509509
public fun getProguardUuid ()Ljava/lang/String;
510510
public fun getProxy ()Lio/sentry/SentryOptions$Proxy;
511511
public fun getRelease ()Ljava/lang/String;
512+
public fun getSampleRate ()Ljava/lang/Double;
512513
public fun getSendClientReports ()Ljava/lang/Boolean;
513514
public fun getServerName ()Ljava/lang/String;
514515
public fun getSpotlightConnectionUrl ()Ljava/lang/String;
@@ -557,6 +558,7 @@ public final class io/sentry/ExternalOptions {
557558
public fun setProguardUuid (Ljava/lang/String;)V
558559
public fun setProxy (Lio/sentry/SentryOptions$Proxy;)V
559560
public fun setRelease (Ljava/lang/String;)V
561+
public fun setSampleRate (Ljava/lang/Double;)V
560562
public fun setSendClientReports (Ljava/lang/Boolean;)V
561563
public fun setSendDefaultPii (Ljava/lang/Boolean;)V
562564
public fun setSendModules (Ljava/lang/Boolean;)V

sentry/src/main/java/io/sentry/ExternalOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public final class ExternalOptions {
2323
private @Nullable Boolean enableUncaughtExceptionHandler;
2424
private @Nullable Boolean debug;
2525
private @Nullable Boolean enableDeduplication;
26+
private @Nullable Double sampleRate;
2627
private @Nullable Double tracesSampleRate;
2728
private @Nullable Double profilesSampleRate;
2829
private @Nullable SentryOptions.RequestSize maxRequestBodySize;
@@ -77,6 +78,7 @@ public final class ExternalOptions {
7778
propertiesProvider.getBooleanProperty("uncaught.handler.enabled"));
7879
options.setPrintUncaughtStackTrace(
7980
propertiesProvider.getBooleanProperty("uncaught.handler.print-stacktrace"));
81+
options.setSampleRate(propertiesProvider.getDoubleProperty("sample-rate"));
8082
options.setTracesSampleRate(propertiesProvider.getDoubleProperty("traces-sample-rate"));
8183
options.setProfilesSampleRate(propertiesProvider.getDoubleProperty("profiles-sample-rate"));
8284
options.setDebug(propertiesProvider.getBooleanProperty("debug"));
@@ -295,6 +297,14 @@ public void setEnableDeduplication(final @Nullable Boolean enableDeduplication)
295297
this.enableDeduplication = enableDeduplication;
296298
}
297299

300+
public @Nullable Double getSampleRate() {
301+
return sampleRate;
302+
}
303+
304+
public void setSampleRate(final @Nullable Double sampleRate) {
305+
this.sampleRate = sampleRate;
306+
}
307+
298308
public @Nullable Double getTracesSampleRate() {
299309
return tracesSampleRate;
300310
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,9 @@ public void merge(final @NotNull ExternalOptions options) {
33783378
if (options.getPrintUncaughtStackTrace() != null) {
33793379
setPrintUncaughtStackTrace(options.getPrintUncaughtStackTrace());
33803380
}
3381+
if (options.getSampleRate() != null) {
3382+
setSampleRate(options.getSampleRate());
3383+
}
33813384
if (options.getTracesSampleRate() != null) {
33823385
setTracesSampleRate(options.getTracesSampleRate());
33833386
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ class ExternalOptionsTest {
101101
}
102102
}
103103

104+
@Test
105+
fun `creates options with sampleRate using external properties`() {
106+
withPropertiesFile("sample-rate=0.2") { assertEquals(0.2, it.sampleRate) }
107+
}
108+
104109
@Test
105110
fun `creates options with tracesSampleRate using external properties`() {
106111
withPropertiesFile("traces-sample-rate=0.2") { assertEquals(0.2, it.tracesSampleRate) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ class SentryOptionsTest {
376376
externalOptions.setTag("tag1", "value1")
377377
externalOptions.setTag("tag2", "value2")
378378
externalOptions.enableUncaughtExceptionHandler = false
379+
externalOptions.sampleRate = 0.3
379380
externalOptions.tracesSampleRate = 0.5
380381
externalOptions.profilesSampleRate = 0.5
381382
externalOptions.addInAppInclude("com.app")
@@ -433,6 +434,7 @@ class SentryOptionsTest {
433434
assertEquals(java.net.Proxy.Type.SOCKS, options.proxy!!.type)
434435
assertEquals(mapOf("tag1" to "value1", "tag2" to "value2"), options.tags)
435436
assertFalse(options.isEnableUncaughtExceptionHandler)
437+
assertEquals(0.3, options.sampleRate)
436438
assertEquals(0.5, options.tracesSampleRate)
437439
assertEquals(0.5, options.profilesSampleRate)
438440
assertEquals(listOf("com.app"), options.inAppIncludes)

0 commit comments

Comments
 (0)