Skip to content

Commit

Permalink
Accept manifest integer values when requiring floating values (#3823)
Browse files Browse the repository at this point in the history
* ManifestMetadataReader now accepts integers other than floats
  • Loading branch information
stefanosiano authored Oct 28, 2024
1 parent 92ab1d9 commit 283c6cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Accept manifest integer values when requiring floating values ([#3823](https://github.com/getsentry/sentry-java/pull/3823))

## 7.16.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private static boolean readBool(
private static @NotNull Double readDouble(
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
// manifest meta-data only reads float
final Double value = ((Float) metadata.getFloat(key, -1)).doubleValue();
final Double value = ((Number) metadata.getFloat(key, metadata.getInt(key, -1))).doubleValue();
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1515,4 +1515,29 @@ class ManifestMetadataReaderTest {
assertTrue(fixture.options.experimental.sessionReplay.maskViewClasses.contains(SentryReplayOptions.IMAGE_VIEW_CLASS_NAME))
assertTrue(fixture.options.experimental.sessionReplay.maskViewClasses.contains(SentryReplayOptions.TEXT_VIEW_CLASS_NAME))
}

@Test
fun `applyMetadata reads integers even when expecting floats`() {
// Arrange
val expectedSampleRate: Int = 1

val bundle = bundleOf(
ManifestMetadataReader.SAMPLE_RATE to expectedSampleRate,
ManifestMetadataReader.TRACES_SAMPLE_RATE to expectedSampleRate,
ManifestMetadataReader.PROFILES_SAMPLE_RATE to expectedSampleRate,
ManifestMetadataReader.REPLAYS_SESSION_SAMPLE_RATE to expectedSampleRate,
ManifestMetadataReader.REPLAYS_ERROR_SAMPLE_RATE to expectedSampleRate
)
val context = fixture.getContext(metaData = bundle)

// Act
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

// Assert
assertEquals(expectedSampleRate.toDouble(), fixture.options.sampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.tracesSampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.profilesSampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.sessionSampleRate)
assertEquals(expectedSampleRate.toDouble(), fixture.options.experimental.sessionReplay.onErrorSampleRate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<!-- <meta-data android:name="io.sentry.traces.sample-rate" android:value="0.8" /> -->

<!-- how to enable profiling when starting transactions -->
<meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1.0" />
<meta-data android:name="io.sentry.traces.profiling.sample-rate" android:value="1" />

<!-- how to enable app start profiling -->
<meta-data android:name="io.sentry.traces.profiling.enable-app-start" android:value="true" />
Expand Down Expand Up @@ -165,7 +165,7 @@

<meta-data android:name="io.sentry.enable-metrics" android:value="true" />

<meta-data android:name="io.sentry.session-replay.session-sample-rate" android:value="1.0" />
<meta-data android:name="io.sentry.session-replay.session-sample-rate" android:value="1" />
<meta-data android:name="io.sentry.session-replay.mask-all-text" android:value="true" />
</application>
</manifest>

0 comments on commit 283c6cc

Please sign in to comment.