Skip to content
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixes

- On iOS and macOS, native crashes now respect the Event Sample Rate (`SampleRate`). Unity passes it to the Cocoa SDK with both runtime and build-time initialization, so native crashes are no longer always sent. ([#2940](https://github.com/getsentry/sentry-unity/pull/2940))
- Values set in a `SentryCliOptionsConfiguration`, such as an auth token read from an environment variable, no longer get saved into `SentryCliOptions.asset` by the Sentry window after a build. The configuration now runs on a copy of the options. ([#2938](https://github.com/getsentry/sentry-unity/pull/2938))
- The configuration window's tooltips and help boxes and the option docs describe the SDK's defaults and requirements correctly: `Auto Set UserName` is disabled by default, `Attach Screenshots` also attaches screenshots to events on background threads, `Org Slug` is required unless the Auth Token is an organization token, `Scene Traces` has no Unity version requirement, and `IosWatchdogTerminationIntegrationEnabled` turns on reporting of watchdog terminations on iOS. ([#2933](https://github.com/getsentry/sentry-unity/pull/2933))
- The SDK no longer throws a `NullReferenceException` during startup on Android and iOS when it can't load its options, for example when the configuration lives in an OBB file that isn't available yet. ([#2931](https://github.com/getsentry/sentry-unity/pull/2931))
Expand Down
7 changes: 7 additions & 0 deletions src/Sentry.Unity.Editor.iOS/NativeOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;

namespace Sentry.Unity.Editor.iOS;
Expand Down Expand Up @@ -33,6 +34,7 @@ internal static string Generate(SentryUnityOptions options)
@""appHangTimeoutInterval"": @{options.AppHangTimeout.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture)},
@""enableCaptureFailedRequests"": @{ToObjCString(options.CaptureFailedRequests)},
@""failedRequestStatusCodes"" : @[{failedRequestStatusCodesArray}],
{GetSampleRateEntry(options.SampleRate)}
@""sendDefaultPii"" : @{ToObjCString(options.SendDefaultPii)},
@""attachScreenshot"" : @{ToObjCString(options.AttachScreenshot)},
@""release"" : @""{options.Release}"",
Expand Down Expand Up @@ -60,6 +62,11 @@ internal static string Generate(SentryUnityOptions options)
return nativeOptions;
}

// SampleRate is null at a rate of 1.0. Leaving the key out keeps sentry-cocoa's default, which is also 1.0.
private static string GetSampleRateEntry(float? sampleRate) => sampleRate.HasValue
? $"@\"sampleRate\" : @{sampleRate.Value.ToString(CultureInfo.InvariantCulture)},"
: string.Empty;

private static string ToObjCString(bool b) => b ? "YES" : "NO";

private static string ToNativeDiagnosticLevel(SentryLevel sentryLevel)
Expand Down
6 changes: 6 additions & 0 deletions src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public static bool Init(SentryUnityOptions options)
Logger?.LogDebug("Setting DiagnosticLevel: {0}", diagnosticLevel);
OptionsSetString(cOptions, "diagnosticLevel", diagnosticLevel);

if (options.SampleRate.HasValue)
{
Logger?.LogDebug("Setting SampleRate: {0}", options.SampleRate.Value);
OptionsSetDouble(cOptions, "sampleRate", options.SampleRate.Value);
}

Logger?.LogDebug("Setting SendDefaultPii: {0}", options.SendDefaultPii);
OptionsSetInt(cOptions, "sendDefaultPii", options.SendDefaultPii ? 1 : 0);

Expand Down
38 changes: 38 additions & 0 deletions test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using NUnit.Framework;

Expand Down Expand Up @@ -110,4 +111,41 @@ public void CreateOptionsFile_FilterBadGatewayDisabled_DoesNotAddFiltering()
var nativeOptions = File.ReadAllText(_testOptionsFilePath);
StringAssert.DoesNotContain("event.request.url containsString:@\"operate-sdk-telemetry.unity3d.com\"", nativeOptions);
}

[Test]
public void CreateOptionsFile_SampleRateSet_WritesSampleRate()
{
NativeOptions.CreateFile(_testOptionsFilePath, new SentryUnityOptions { SampleRate = 0.3f });

var nativeOptions = File.ReadAllText(_testOptionsFilePath);
StringAssert.Contains("@\"sampleRate\" : @0.3,", nativeOptions);
}

[Test]
public void CreateOptionsFile_SampleRateSetUnderCommaDecimalCulture_WritesInvariantSampleRate()
{
var originalCulture = CultureInfo.CurrentCulture;
try
{
CultureInfo.CurrentCulture = new CultureInfo("de-DE");

NativeOptions.CreateFile(_testOptionsFilePath, new SentryUnityOptions { SampleRate = 0.3f });
}
finally
{
CultureInfo.CurrentCulture = originalCulture;
}

var nativeOptions = File.ReadAllText(_testOptionsFilePath);
StringAssert.Contains("@\"sampleRate\" : @0.3,", nativeOptions);
}

[Test]
public void CreateOptionsFile_SampleRateNotSet_LeavesSampleRateOut()
{
NativeOptions.CreateFile(_testOptionsFilePath, new SentryUnityOptions { SampleRate = null });

var nativeOptions = File.ReadAllText(_testOptionsFilePath);
StringAssert.DoesNotContain("sampleRate", nativeOptions);
}
}
Loading