Skip to content

Commit

Permalink
rename cocoa options to Native
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Dec 3, 2023
1 parent 13c3ee9 commit b952cb0
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void ApplyTo(SentryOptions options)
#if ANDROID
Android.ApplyTo(options.Android);
#elif __IOS__
Cocoa.ApplyTo(options.Cocoa);
Native.ApplyTo(options.Native);
#endif
}
}
6 changes: 3 additions & 3 deletions src/Sentry/Platforms/Cocoa/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ namespace Sentry;

internal partial class BindableSentryOptions
{
public CocoaOptions Cocoa { get; } = new CocoaOptions();
public NativeOptions Native { get; } = new NativeOptions();

/// <summary>
/// Provides additional options for the Android platform.
/// </summary>
public class CocoaOptions
public class NativeOptions
{
public bool? AttachScreenshot { get; set; }
public TimeSpan? AppHangTimeoutInterval { get; set; }
Expand All @@ -26,7 +26,7 @@ public class CocoaOptions
public bool? EnableUserInteractionTracing { get; set; }
public bool? EnableCocoaSdkTracing { get; set; }

public void ApplyTo(SentryOptions.CocoaOptions options)
public void ApplyTo(SentryOptions.NativeOptions options)
{
options.AttachScreenshot = AttachScreenshot ?? options.AttachScreenshot;
options.AppHangTimeoutInterval = AppHangTimeoutInterval ?? options.AppHangTimeoutInterval;
Expand Down
7 changes: 0 additions & 7 deletions src/Sentry/Platforms/Cocoa/CocoaEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ namespace Sentry.Cocoa;

internal class CocoaEventProcessor : ISentryEventProcessor, IDisposable
{
private readonly SentryCocoaOptions _options;

public CocoaEventProcessor(SentryCocoaOptions options)
{
_options = options;
}

public SentryEvent Process(SentryEvent @event)
{
// Get a temp event from the Cocoa SDK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// * updating the objects on either side.
// */
//
// public static SentryEvent ToSentryEvent(this CocoaSdk.SentryEvent sentryEvent, SentryCocoaOptions cocoaOptions)
// public static SentryEvent ToSentryEvent(this CocoaSdk.SentryEvent sentryEvent, SentryCocoaSdkOptions nativeOptions)
// {
// using var stream = sentryEvent.ToJsonStream()!;
// //stream.Seek(0, SeekOrigin.Begin); ??
Expand All @@ -28,7 +28,7 @@
// return SentryEvent.FromJson(json.RootElement, exception);
// }
//
// public static CocoaSdk.SentryEvent ToCocoaSentryEvent(this SentryEvent sentryEvent, SentryOptions options, SentryCocoaOptions cocoaOptions)
// public static CocoaSdk.SentryEvent ToCocoaSentryEvent(this SentryEvent sentryEvent, SentryOptions options, SentryCocoaSdkOptions nativeOptions)
// {
// var envelope = Envelope.FromEvent(sentryEvent);
//
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Platforms/Cocoa/Sentry.Cocoa.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<Using Include="Foundation" />
<Using Include="Sentry.CocoaSdk.SentryOptions" Alias="SentryCocoaOptions" />
<Using Include="Sentry.CocoaSdk.SentryOptions" Alias="SentryCocoaSdkOptions" />
<Using Include="Sentry.CocoaSdk.SentrySDK" Alias="SentryCocoaSdk" />
<Using Include="Sentry.CocoaSdk.PrivateSentrySDKOnly" Alias="SentryCocoaHybridSdk" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Sentry/Platforms/Cocoa/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ public partial class SentryOptions
/// Exposes additional options for iOS and MacCatalyst.
/// </summary>
// ReSharper disable once InconsistentNaming
public CocoaOptions Cocoa { get; }
public NativeOptions Native { get; }

/// <summary>
/// Provides additional options for iOS and MacCatalyst.
/// </summary>
public class CocoaOptions
public class NativeOptions
{
private readonly SentryOptions _options;

internal CocoaOptions(SentryOptions options)
internal NativeOptions(SentryOptions options)
{
_options = options;
}
Expand Down
118 changes: 59 additions & 59 deletions src/Sentry/Platforms/Cocoa/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ private static void InitSentryCocoaSdk(SentryOptions options)
options.Distribution ??= GetDefaultDistributionString();

// Set options for the Cocoa SDK
var cocoaOptions = new SentryCocoaOptions();
var nativeOptions = new SentryCocoaSdkOptions();

// These options are copied over from our SentryOptions
cocoaOptions.AttachStacktrace = options.AttachStacktrace;
cocoaOptions.Debug = options.Debug;
cocoaOptions.DiagnosticLevel = options.DiagnosticLevel.ToCocoaSentryLevel();
cocoaOptions.Dsn = options.Dsn;
cocoaOptions.EnableAutoSessionTracking = options.AutoSessionTracking;
cocoaOptions.EnableCaptureFailedRequests = options.CaptureFailedRequests;
cocoaOptions.FailedRequestStatusCodes = GetFailedRequestStatusCodes(options.FailedRequestStatusCodes);
cocoaOptions.MaxAttachmentSize = (nuint) options.MaxAttachmentSize;
cocoaOptions.MaxBreadcrumbs = (nuint) options.MaxBreadcrumbs;
cocoaOptions.MaxCacheItems = (nuint) options.MaxCacheItems;
cocoaOptions.ReleaseName = options.Release;
cocoaOptions.SampleRate = options.SampleRate;
cocoaOptions.SendClientReports = options.SendClientReports;
cocoaOptions.SendDefaultPii = options.SendDefaultPii;
cocoaOptions.SessionTrackingIntervalMillis = (nuint) options.AutoSessionTrackingInterval.TotalMilliseconds;
nativeOptions.AttachStacktrace = options.AttachStacktrace;
nativeOptions.Debug = options.Debug;
nativeOptions.DiagnosticLevel = options.DiagnosticLevel.ToCocoaSentryLevel();
nativeOptions.Dsn = options.Dsn;
nativeOptions.EnableAutoSessionTracking = options.AutoSessionTracking;
nativeOptions.EnableCaptureFailedRequests = options.CaptureFailedRequests;
nativeOptions.FailedRequestStatusCodes = GetFailedRequestStatusCodes(options.FailedRequestStatusCodes);
nativeOptions.MaxAttachmentSize = (nuint) options.MaxAttachmentSize;
nativeOptions.MaxBreadcrumbs = (nuint) options.MaxBreadcrumbs;
nativeOptions.MaxCacheItems = (nuint) options.MaxCacheItems;
nativeOptions.ReleaseName = options.Release;
nativeOptions.SampleRate = options.SampleRate;
nativeOptions.SendClientReports = options.SendClientReports;
nativeOptions.SendDefaultPii = options.SendDefaultPii;
nativeOptions.SessionTrackingIntervalMillis = (nuint) options.AutoSessionTrackingInterval.TotalMilliseconds;

if (options.Environment is { } environment)
{
cocoaOptions.Environment = environment;
nativeOptions.Environment = environment;
}

// These options are not available in the Sentry Cocoa SDK
// cocoaOptions.? = options.InitCacheFlushTimeout;
// cocoaOptions.? = options.MaxQueueItems;
// cocoaOptions.? = options.ShutdownTimeout;
// nativeOptions.? = options.InitCacheFlushTimeout;
// nativeOptions.? = options.MaxQueueItems;
// nativeOptions.? = options.ShutdownTimeout;

// NOTE: options.CacheDirectoryPath - No option for this in Sentry Cocoa, but caching is still enabled
// https://github.com/getsentry/sentry-cocoa/issues/1051
Expand All @@ -56,7 +56,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)

if (options.BeforeBreadcrumbInternal is { } beforeBreadcrumb)
{
cocoaOptions.BeforeBreadcrumb = b =>
nativeOptions.BeforeBreadcrumb = b =>
{
// Note: The Cocoa SDK doesn't yet support hints.
// See https://github.com/getsentry/sentry-cocoa/issues/2325
Expand All @@ -71,18 +71,18 @@ private static void InitSentryCocoaSdk(SentryOptions options)
}

// These options we have behind feature flags
if (options is {IsPerformanceMonitoringEnabled: true, Cocoa.EnableCocoaSdkTracing: true})
if (options is {IsPerformanceMonitoringEnabled: true, Native.EnableCocoaSdkTracing: true})
{
if (options.EnableTracing != null)
{
cocoaOptions.EnableTracing = options.EnableTracing.Value;
nativeOptions.EnableTracing = options.EnableTracing.Value;
}

cocoaOptions.TracesSampleRate = options.TracesSampleRate;
nativeOptions.TracesSampleRate = options.TracesSampleRate;

if (options.TracesSampler is { } tracesSampler)
{
cocoaOptions.TracesSampler = cocoaContext =>
nativeOptions.TracesSampler = cocoaContext =>
{
var context = cocoaContext.ToTransactionSamplingContext();
var result = tracesSampler(context);
Expand All @@ -96,59 +96,59 @@ private static void InitSentryCocoaSdk(SentryOptions options)

// TODO: Finish SentryEventExtensions to enable these

// if (options.Cocoa.EnableCocoaSdkBeforeSend && options.BeforeSend is { } beforeSend)
// if (options.Native.EnableCocoaSdkBeforeSend && options.BeforeSend is { } beforeSend)
// {
// cocoaOptions.BeforeSend = evt =>
// nativeOptions.BeforeSend = evt =>
// {
// var sentryEvent = evt.ToSentryEvent(cocoaOptions);
// var result = beforeSend(sentryEvent)?.ToCocoaSentryEvent(options, cocoaOptions);
// var sentryEvent = evt.ToSentryEvent(nativeOptions);
// var result = beforeSend(sentryEvent)?.ToCocoaSentryEvent(options, nativeOptions);
//
// // Note: Nullable result is allowed but delegate is generated incorrectly
// // See https://github.com/xamarin/xamarin-macios/issues/15299#issuecomment-1201863294
// return result!;
// };
// }

// if (options.Cocoa.OnCrashedLastRun is { } onCrashedLastRun)
// if (options.Native.OnCrashedLastRun is { } onCrashedLastRun)
// {
// cocoaOptions.OnCrashedLastRun = evt =>
// nativeOptions.OnCrashedLastRun = evt =>
// {
// var sentryEvent = evt.ToSentryEvent(cocoaOptions);
// var sentryEvent = evt.ToSentryEvent(nativeOptions);
// onCrashedLastRun(sentryEvent);
// };
// }

// These options are from Cocoa's SentryOptions
cocoaOptions.AttachScreenshot = options.Cocoa.AttachScreenshot;
cocoaOptions.AppHangTimeoutInterval = options.Cocoa.AppHangTimeoutInterval.TotalSeconds;
cocoaOptions.IdleTimeout = options.Cocoa.IdleTimeout.TotalSeconds;
cocoaOptions.Dist = options.Distribution;
cocoaOptions.EnableAppHangTracking = options.Cocoa.EnableAppHangTracking;
cocoaOptions.EnableAutoBreadcrumbTracking = options.Cocoa.EnableAutoBreadcrumbTracking;
cocoaOptions.EnableAutoPerformanceTracing = options.Cocoa.EnableAutoPerformanceTracing;
cocoaOptions.EnableCoreDataTracing = options.Cocoa.EnableCoreDataTracing;
cocoaOptions.EnableFileIOTracing = options.Cocoa.EnableFileIOTracing;
cocoaOptions.EnableNetworkBreadcrumbs = options.Cocoa.EnableNetworkBreadcrumbs;
cocoaOptions.EnableNetworkTracking = options.Cocoa.EnableNetworkTracking;
cocoaOptions.EnableWatchdogTerminationTracking = options.Cocoa.EnableWatchdogTerminationTracking;
cocoaOptions.EnableSwizzling = options.Cocoa.EnableSwizzling;
cocoaOptions.EnableUIViewControllerTracing = options.Cocoa.EnableUIViewControllerTracing;
cocoaOptions.EnableUserInteractionTracing = options.Cocoa.EnableUserInteractionTracing;
cocoaOptions.UrlSessionDelegate = options.Cocoa.UrlSessionDelegate;
nativeOptions.AttachScreenshot = options.Native.AttachScreenshot;
nativeOptions.AppHangTimeoutInterval = options.Native.AppHangTimeoutInterval.TotalSeconds;
nativeOptions.IdleTimeout = options.Native.IdleTimeout.TotalSeconds;
nativeOptions.Dist = options.Distribution;
nativeOptions.EnableAppHangTracking = options.Native.EnableAppHangTracking;
nativeOptions.EnableAutoBreadcrumbTracking = options.Native.EnableAutoBreadcrumbTracking;
nativeOptions.EnableAutoPerformanceTracing = options.Native.EnableAutoPerformanceTracing;
nativeOptions.EnableCoreDataTracing = options.Native.EnableCoreDataTracing;
nativeOptions.EnableFileIOTracing = options.Native.EnableFileIOTracing;
nativeOptions.EnableNetworkBreadcrumbs = options.Native.EnableNetworkBreadcrumbs;
nativeOptions.EnableNetworkTracking = options.Native.EnableNetworkTracking;
nativeOptions.EnableWatchdogTerminationTracking = options.Native.EnableWatchdogTerminationTracking;
nativeOptions.EnableSwizzling = options.Native.EnableSwizzling;
nativeOptions.EnableUIViewControllerTracing = options.Native.EnableUIViewControllerTracing;
nativeOptions.EnableUserInteractionTracing = options.Native.EnableUserInteractionTracing;
nativeOptions.UrlSessionDelegate = options.Native.UrlSessionDelegate;

// StitchAsyncCode removed from Cocoa SDK in 8.6.0 with https://github.com/getsentry/sentry-cocoa/pull/2973
// cocoaOptions.StitchAsyncCode = options.Cocoa.StitchAsyncCode;
// nativeOptions.StitchAsyncCode = options.Native.StitchAsyncCode;

// In-App Excludes and Includes to be passed to the Cocoa SDK
options.Cocoa.InAppExcludes?.ForEach(x => cocoaOptions.AddInAppExclude(x));
options.Cocoa.InAppIncludes?.ForEach(x => cocoaOptions.AddInAppInclude(x));
options.Native.InAppExcludes?.ForEach(x => nativeOptions.AddInAppExclude(x));
options.Native.InAppIncludes?.ForEach(x => nativeOptions.AddInAppInclude(x));

// These options are intentionally not expose or modified
// cocoaOptions.Enabled
// cocoaOptions.SdkInfo
// cocoaOptions.Integrations
// cocoaOptions.DefaultIntegrations
// cocoaOptions.EnableProfiling (deprecated)
// nativeOptions.Enabled
// nativeOptions.SdkInfo
// nativeOptions.Integrations
// nativeOptions.DefaultIntegrations
// nativeOptions.EnableProfiling (deprecated)

// When we have an unhandled managed exception, we send that to Sentry twice - once managed and once native.
// The managed exception is what a .NET developer would expect, and it is sent by the Sentry.NET SDK
Expand All @@ -157,7 +157,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)
// Thankfully, we can see Xamarin's unhandled exception handler on the stack trace, so we can filter them out.
// Here is the function that calls abort(), which we will use as a filter:
// https://github.com/xamarin/xamarin-macios/blob/c55fbdfef95028ba03d0f7a35aebca03bd76f852/runtime/runtime.m#L1114-L1122
cocoaOptions.BeforeSend = evt =>
nativeOptions.BeforeSend = evt =>
{
// There should only be one exception on the event in this case
if (evt.Exceptions?.Length == 1)
Expand All @@ -180,10 +180,10 @@ private static void InitSentryCocoaSdk(SentryOptions options)
SentryCocoaHybridSdk.SetSdkName("sentry.cocoa.dotnet");

// Now initialize the Cocoa SDK
SentryCocoaSdk.StartWithOptions(cocoaOptions);
SentryCocoaSdk.StartWithOptions(nativeOptions);

// Set options for the managed SDK that depend on the Cocoa SDK. (The user will not be able to modify these.)
options.AddEventProcessor(new CocoaEventProcessor(cocoaOptions));
options.AddEventProcessor(new CocoaEventProcessor());
options.CrashedLastRun = () => SentryCocoaSdk.CrashedLastRun;
options.EnableScopeSync = true;
options.ScopeObserver = new CocoaScopeObserver(options);
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ public SentryOptions()
AssemblyReader = name => reader.Value?.TryReadAssembly(name);

#elif __IOS__
Cocoa = new CocoaOptions(this);
Native = new NativeOptions(this);
#endif

InAppExclude = new() {
Expand Down
2 changes: 1 addition & 1 deletion test/Sentry.Testing/BindableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private static IEnumerable<PropertyInfo> GetBindableProperties(IEnumerable<strin
#if ANDROID
&& !(p.PropertyType == typeof(SentryOptions.AndroidOptions)) // Exclude the Mobile sub-property
#elif __IOS__
&& !(p.PropertyType == typeof(SentryOptions.CocoaOptions)) // Exclude the Mobile sub-property
&& !(p.PropertyType == typeof(SentryOptions.NativeOptions)) // Exclude the Mobile sub-property
#endif
);
}
Expand Down
10 changes: 5 additions & 5 deletions test/Sentry.Tests/Platforms/iOS/BindableSentryOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@

namespace Sentry.Tests.Platforms.Cocoa;

public class BindableSentryOptionsTests : BindableTests<SentryOptions.CocoaOptions>
public class BindableSentryOptionsTests : BindableTests<SentryOptions.NativeOptions>
{
public BindableSentryOptionsTests()
: base(nameof(SentryOptions.CocoaOptions.UrlSessionDelegate))
: base(nameof(SentryOptions.NativeOptions.UrlSessionDelegate))
{
}

[Fact]
public void BindableProperties_MatchOptionsProperties()
{
var actual = GetPropertyNames<BindableSentryOptions.CocoaOptions>();
var actual = GetPropertyNames<BindableSentryOptions.NativeOptions>();
AssertContainsAllOptionsProperties(actual);
}

[Fact]
public void ApplyTo_SetsOptionsFromConfig()
{
// Arrange
var actual = new SentryOptions.CocoaOptions(new SentryOptions());
var bindable = new BindableSentryOptions.CocoaOptions();
var actual = new SentryOptions.NativeOptions(new SentryOptions());
var bindable = new BindableSentryOptions.NativeOptions();

// Act
Fixture.Config.Bind(bindable);
Expand Down

0 comments on commit b952cb0

Please sign in to comment.