Skip to content

Commit

Permalink
fixed writing float as float to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes committed Oct 30, 2024
1 parent e1ada0b commit 4eb404b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
Expand Down Expand Up @@ -157,7 +158,8 @@ internal void ModifyManifest(string basePath)

if (_options.SampleRate.HasValue)
{
_logger.LogDebug("Setting SampleRate: {0}", _options.SampleRate);
// To keep the logs in line with what the SDK writes to the AndroidManifest we're formatting here too
_logger.LogDebug("Setting SampleRate: {0}", ((float)_options.SampleRate).ToString("F", CultureInfo.InvariantCulture));
androidManifest.SetSampleRate(_options.SampleRate.Value);
}

Expand Down Expand Up @@ -420,7 +422,8 @@ public void AddDisclaimerComment() =>
internal void SetDsn(string dsn) => SetMetaData($"{SentryPrefix}.dsn", dsn);

internal void SetSampleRate(float sampleRate) =>
SetMetaData($"{SentryPrefix}.sample-rate", sampleRate.ToString());
// Keeping the sample-rate as float: https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
SetMetaData($"{SentryPrefix}.sample-rate", sampleRate.ToString("F", CultureInfo.InvariantCulture));

internal void SetRelease(string release) => SetMetaData($"{SentryPrefix}.release", release);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,18 @@ public void ModifyManifest_DiagnosticLevel_TestCases(
}

[Test]
public void ModifyManifest_SampleRate_SetIfNotNull()
[TestCase(0.45f, "0.45")]
[TestCase(1, "1.00")]
public void ModifyManifest_SampleRate_SetIfNotNull(float sampleRate, string expectedSampleRate)
{
const float expected = 0.6f;
_fixture.SentryUnityOptions!.SampleRate = expected;
_fixture.SentryUnityOptions!.SampleRate = sampleRate;
var sut = _fixture.GetSut();
var manifest = WithAndroidManifest(basePath => sut.ModifyManifest(basePath));

_fixture.UnityTestLogger.AssertLogContains(SentryLevel.Debug, $"Setting SampleRate: {expected}");
_fixture.UnityTestLogger.AssertLogContains(SentryLevel.Debug, $"Setting SampleRate: {expectedSampleRate}");

Assert.True(manifest.Contains(
$"<meta-data android:name=\"io.sentry.sample-rate\" android:value=\"{expected}\" />"),
$"<meta-data android:name=\"io.sentry.sample-rate\" android:value=\"{expectedSampleRate}\" />"),
$"Expected 'io.sentry.sample-rate' in Manifest:\n{manifest}");
}

Expand Down

0 comments on commit 4eb404b

Please sign in to comment.