Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-run-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
HOMEBREW_NO_INSTALL_CLEANUP: 1
SENTRY_DSN: ${{ secrets.SENTRY_TEST_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_TEST_UNITY_VERSION: ${{ inputs.unity-version }}

steps:
- name: Checkout
Expand Down
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

- The Event Sample Rate in the Sentry window now accepts values from 0.01 to 1.0. A rate of 0 made the SDK fail to initialize and builds fail to load the options. ([#2929](https://github.com/getsentry/sentry-unity/pull/2929))

## 4.12.0

### Behavioral Changes
Expand Down
11 changes: 8 additions & 3 deletions src/Sentry.Unity.Editor/ConfigurationWindow/CoreTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Sentry.Unity.Editor.ConfigurationWindow;

internal static class CoreTab
{
// The .NET SDK's SampleRate throws for 0 and documents 0.01 as its minimum.
internal const float MinSampleRate = 0.01f;

internal static float ClampSampleRate(float sampleRate) => Mathf.Clamp(sampleRate, MinSampleRate, 1.0f);

internal static void Display(ScriptableSentryUnityOptions options)
{
{
Expand All @@ -21,12 +26,12 @@ internal static void Display(ScriptableSentryUnityOptions options)

var sampleRate = EditorGUILayout.FloatField(
new GUIContent("Event Sample Rate", "Indicates the percentage of events that are " +
"captured. Setting this to 0.1 captures 10% of events. " +
"Setting this to 1.0 captures all events." +
"captured, from 0.01 (1%) to 1.0. Setting this to 0.1 " +
"captures 10% of events. Setting this to 1.0 captures all events." +
"\nThis affects only errors and logs, not performance " +
"(transactions) data. See TraceSampleRate for that."),
options.SampleRate);
options.SampleRate = Mathf.Clamp01(sampleRate);
options.SampleRate = ClampSampleRate(sampleRate);

options.CaptureInEditor = EditorGUILayout.Toggle(
new GUIContent("Capture In Editor", "Capture errors while running in the Editor."),
Expand Down
4 changes: 4 additions & 0 deletions test/IntegrationTest/Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ Describe "Unity $($env:SENTRY_TEST_PLATFORM) Integration Tests" {
Set-ItResult -Skipped -Because "line numbers come from the IL2CPP mappings, which a Mono player does not produce"
return
}
if ($script:Platform -eq "Android" -and $script:TestSetup.UnityVersion -like "2021.3*") {
Set-ItResult -Skipped -Because "on the Android 2021.3 x86_64 emulator, IL2CPP intermittently reports no stack frames for the thrown exception, so the event carries only the throwing frame without a native address"
return
}

$frame = $runEvent.exception.values[0].stacktrace.frames |
Where-Object { $_.module -eq "IntegrationTester" -and $_.function -eq "ThrowException" } |
Expand Down
31 changes: 31 additions & 0 deletions test/Sentry.Unity.Editor.Tests/CoreTabTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NUnit.Framework;
using Sentry.Unity.Editor.ConfigurationWindow;

namespace Sentry.Unity.Editor.Tests;

public class CoreTabTests
{
[Test]
[TestCase(-1f, 0.01f)]
[TestCase(0f, 0.01f)]
[TestCase(0.005f, 0.01f)]
[TestCase(0.01f, 0.01f)]
[TestCase(0.5f, 0.5f)]
[TestCase(1f, 1f)]
[TestCase(2f, 1f)]
public void ClampSampleRate_KeepsValueWithinSupportedRange(float sampleRate, float expected)
{
Assert.AreEqual(expected, CoreTab.ClampSampleRate(sampleRate));
}

[Test]
public void ClampSampleRate_Zero_IsAcceptedByToSentryUnityOptions()
{
var scriptableOptions = UnityEngine.ScriptableObject.CreateInstance<ScriptableSentryUnityOptions>();
scriptableOptions.SampleRate = CoreTab.ClampSampleRate(0f);

var options = scriptableOptions.ToSentryUnityOptions(isBuilding: true);

Assert.AreEqual(CoreTab.MinSampleRate, options.SampleRate);
}
}
Loading