Skip to content

Commit

Permalink
refactor: rename native options (#2940)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind authored Dec 4, 2023
1 parent 351adea commit a2fa21f
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 144 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

### API breaking Changes

#### Changed APIs

- Rename iOS and MacCatalyst platform specific options from `Cocoa` to `Native` ([#2940](https://github.com/getsentry/sentry-dotnet/pull/2940))
- Rename iOS platform specific options `EnableCocoaSdkTracing` to `EnableTracing` ([#2940](https://github.com/getsentry/sentry-dotnet/pull/2940))
- Rename Android platform specific options from `Android` to `Native` ([#2940](https://github.com/getsentry/sentry-dotnet/pull/2940))
- Rename Android platform specific options `EnableAndroidSdkTracing` and `EnableAndroidSdkBeforeSend` to `EnableTracing` and `EnableBeforeSend` respectively ([#2940](https://github.com/getsentry/sentry-dotnet/pull/2940))

### Dependencies

- Bump Cocoa SDK from v8.17.0 to v8.17.1 ([#2936](https://github.com/getsentry/sentry-dotnet/pull/2936))
Expand Down
4 changes: 2 additions & 2 deletions samples/Sentry.Samples.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ protected override void OnCreate(Bundle? savedInstanceState)
{
o.Dsn = "https://eb18e953812b41c3aeb042e666fd3b5c@o447951.ingest.sentry.io/5428537";
o.SendDefaultPii = true; // adds the user's IP address automatically
o.Android.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only
o.Android.LogCatMaxLines = 1000; // Defaults to 1000
o.Native.LogCatIntegration = LogCatIntegrationType.Errors; // Get logcat logs for both handled and unhandled errors; default is unhandled only
o.Native.LogCatMaxLines = 1000; // Defaults to 1000
});

// Here's an example of adding custom scope information.
Expand Down
6 changes: 2 additions & 4 deletions src/Sentry/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ public void ApplyTo(SentryOptions options)
options.AutoSessionTracking = AutoSessionTracking ?? options.AutoSessionTracking;
options.UseAsyncFileIO = UseAsyncFileIO ?? options.UseAsyncFileIO;
options.JsonPreserveReferences = JsonPreserveReferences ?? options.JsonPreserveReferences;
#if ANDROID
Android.ApplyTo(options.Android);
#elif __IOS__
Cocoa.ApplyTo(options.Cocoa);
#if ANDROID || __IOS__
Native.ApplyTo(options.Native);
#endif
}
}
6 changes: 3 additions & 3 deletions src/Sentry/Platforms/Android/AndroidEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ internal class AndroidEventProcessor : ISentryEventProcessor, IDisposable
private readonly JavaSdk.IEventProcessor? _androidProcessor;
private readonly JavaSdk.Hint _hint = new();

public AndroidEventProcessor(SentryAndroidOptions androidOptions)
public AndroidEventProcessor(SentryAndroidOptions nativeOptions)
{
// Locate the Android SDK's default event processor by its class
// NOTE: This approach avoids hardcoding the class name (which could be obfuscated by proguard)
_androidProcessor = androidOptions.EventProcessors.OfType<JavaObject>()
_androidProcessor = nativeOptions.EventProcessors.OfType<JavaObject>()
.Where(o => o.Class == JavaClass.FromType(typeof(DefaultAndroidEventProcessor)))
.Cast<JavaSdk.IEventProcessor>()
.FirstOrDefault();

// TODO: This would be cleaner, but doesn't compile. Figure out why.
// _androidProcessor = androidOptions.EventProcessors
// _androidProcessor = nativeOptions.EventProcessors
// .OfType<DefaultAndroidEventProcessor>()
// .FirstOrDefault();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Sentry/Platforms/Android/BindableSentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Sentry;

internal partial class BindableSentryOptions
{
public AndroidOptions Android { get; } = new AndroidOptions();
public NativeOptions Native { get; } = new NativeOptions();

/// <summary>
/// Provides additional options for the Android platform.
/// </summary>
public class AndroidOptions
public class NativeOptions
{
public bool? AnrEnabled { get; set; }
public bool? AnrReportInDebug { get; set; }
Expand All @@ -33,12 +33,12 @@ public class AndroidOptions
public bool? PrintUncaughtStackTrace { get; set; }
public double? ProfilesSampleRate { get; set; }
public TimeSpan? ReadTimeout { get; set; }
public bool? EnableAndroidSdkTracing { get; set; }
public bool? EnableAndroidSdkBeforeSend { get; set; }
public bool? EnableTracing { get; set; }
public bool? EnableBeforeSend { get; set; }
public LogCatIntegrationType? LogCatIntegration { get; set; }
public int? LogCatMaxLines { get; set; }

public void ApplyTo(SentryOptions.AndroidOptions options)
public void ApplyTo(SentryOptions.NativeOptions options)
{
options.AnrEnabled = AnrEnabled ?? options.AnrEnabled;
options.AnrReportInDebug = AnrReportInDebug ?? options.AnrReportInDebug;
Expand All @@ -61,8 +61,8 @@ public void ApplyTo(SentryOptions.AndroidOptions options)
options.PrintUncaughtStackTrace = PrintUncaughtStackTrace ?? options.PrintUncaughtStackTrace;
options.ProfilesSampleRate = ProfilesSampleRate ?? options.ProfilesSampleRate;
options.ReadTimeout = ReadTimeout ?? options.ReadTimeout;
options.EnableAndroidSdkTracing = EnableAndroidSdkTracing ?? options.EnableAndroidSdkTracing;
options.EnableAndroidSdkBeforeSend = EnableAndroidSdkBeforeSend ?? options.EnableAndroidSdkBeforeSend;
options.EnableTracing = EnableTracing ?? options.EnableTracing;
options.EnableBeforeSend = EnableBeforeSend ?? options.EnableBeforeSend;
options.LogCatIntegration = LogCatIntegration ?? options.LogCatIntegration;
options.LogCatMaxLines = LogCatMaxLines ?? options.LogCatMaxLines;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Sentry/Platforms/Android/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ public partial class SentryOptions
/// <summary>
/// Exposes additional options for the Android platform.
/// </summary>
public AndroidOptions Android { get; }
public NativeOptions Native { get; }

/// <summary>
/// Provides additional options for the Android platform.
/// </summary>
public class AndroidOptions
public class NativeOptions
{
private readonly SentryOptions _options;

internal AndroidOptions(SentryOptions options)
internal NativeOptions(SentryOptions options)
{
_options = options;
}
Expand Down Expand Up @@ -255,7 +255,7 @@ public void AddInAppInclude(string prefix){
/// Gets or sets a value that indicates if tracing features are enabled on the embedded Android SDK.
/// The default value is <c>false</c> (disabled).
/// </summary>
public bool EnableAndroidSdkTracing { get; set; } = false;
public bool EnableTracing { get; set; } = false;

/// <summary>
/// Gets or sets a value that indicates if the <c>BeforeSend</c> callback set in <see cref="o:SetBeforeSend"/>
Expand All @@ -266,6 +266,6 @@ public void AddInAppInclude(string prefix){
/// implement all of the same features that may be present in the event graph. Some optional elements may
/// be stripped away during the round-tripping between the two SDKs. Use with caution.
/// </remarks>
public bool EnableAndroidSdkBeforeSend { get; set; } = false;
public bool EnableBeforeSend { get; set; } = false;
}
}
60 changes: 30 additions & 30 deletions src/Sentry/Platforms/Android/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ private static void InitSentryAndroidSdk(SentryOptions options)
AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;

// Define the configuration for the Android SDK
SentryAndroidOptions? androidOptions = null;
SentryAndroidOptions? nativeOptions = null;
var configuration = new OptionsConfigurationCallback(o =>
{
// Capture the android options reference on the outer scope
androidOptions = o;
nativeOptions = o;
// TODO: Should we set the DistinctId to match the one used by GlobalSessionManager?
//o.DistinctId = ?
Expand Down Expand Up @@ -116,7 +116,7 @@ private static void InitSentryAndroidSdk(SentryOptions options)
}
// These options we have behind feature flags
if (options is { IsPerformanceMonitoringEnabled: true, Android.EnableAndroidSdkTracing: true })
if (options is { IsPerformanceMonitoringEnabled: true, Native.EnableTracing: true })
{
o.EnableTracing = (JavaBoolean?)options.EnableTracing;
o.TracesSampleRate = (JavaDouble?)options.TracesSampleRate;
Expand All @@ -127,39 +127,39 @@ private static void InitSentryAndroidSdk(SentryOptions options)
}
}
if (options.Android.EnableAndroidSdkBeforeSend && options.BeforeSendInternal is { } beforeSend)
if (options.Native.EnableBeforeSend && options.BeforeSendInternal is { } beforeSend)
{
o.BeforeSend = new BeforeSendCallback(beforeSend, options, o);
}
// These options are from SentryAndroidOptions
o.AttachScreenshot = options.Android.AttachScreenshot;
o.AnrEnabled = options.Android.AnrEnabled;
o.AnrReportInDebug = options.Android.AnrReportInDebug;
o.AnrTimeoutIntervalMillis = (long)options.Android.AnrTimeoutInterval.TotalMilliseconds;
o.EnableActivityLifecycleBreadcrumbs = options.Android.EnableActivityLifecycleBreadcrumbs;
o.EnableAutoActivityLifecycleTracing = options.Android.EnableAutoActivityLifecycleTracing;
o.EnableActivityLifecycleTracingAutoFinish = options.Android.EnableActivityLifecycleTracingAutoFinish;
o.EnableAppComponentBreadcrumbs = options.Android.EnableAppComponentBreadcrumbs;
o.EnableAppLifecycleBreadcrumbs = options.Android.EnableAppLifecycleBreadcrumbs;
o.EnableRootCheck = options.Android.EnableRootCheck;
o.EnableSystemEventBreadcrumbs = options.Android.EnableSystemEventBreadcrumbs;
o.EnableUserInteractionBreadcrumbs = options.Android.EnableUserInteractionBreadcrumbs;
o.EnableUserInteractionTracing = options.Android.EnableUserInteractionTracing;
o.AttachScreenshot = options.Native.AttachScreenshot;
o.AnrEnabled = options.Native.AnrEnabled;
o.AnrReportInDebug = options.Native.AnrReportInDebug;
o.AnrTimeoutIntervalMillis = (long)options.Native.AnrTimeoutInterval.TotalMilliseconds;
o.EnableActivityLifecycleBreadcrumbs = options.Native.EnableActivityLifecycleBreadcrumbs;
o.EnableAutoActivityLifecycleTracing = options.Native.EnableAutoActivityLifecycleTracing;
o.EnableActivityLifecycleTracingAutoFinish = options.Native.EnableActivityLifecycleTracingAutoFinish;
o.EnableAppComponentBreadcrumbs = options.Native.EnableAppComponentBreadcrumbs;
o.EnableAppLifecycleBreadcrumbs = options.Native.EnableAppLifecycleBreadcrumbs;
o.EnableRootCheck = options.Native.EnableRootCheck;
o.EnableSystemEventBreadcrumbs = options.Native.EnableSystemEventBreadcrumbs;
o.EnableUserInteractionBreadcrumbs = options.Native.EnableUserInteractionBreadcrumbs;
o.EnableUserInteractionTracing = options.Native.EnableUserInteractionTracing;
// These options are in Java.SentryOptions but not ours
o.AttachThreads = options.Android.AttachThreads;
o.ConnectionTimeoutMillis = (int)options.Android.ConnectionTimeout.TotalMilliseconds;
o.EnableNdk = options.Android.EnableNdk;
o.EnableShutdownHook = options.Android.EnableShutdownHook;
o.EnableUncaughtExceptionHandler = options.Android.EnableUncaughtExceptionHandler;
o.ProfilesSampleRate = (JavaDouble?)options.Android.ProfilesSampleRate;
o.PrintUncaughtStackTrace = options.Android.PrintUncaughtStackTrace;
o.ReadTimeoutMillis = (int)options.Android.ReadTimeout.TotalMilliseconds;
o.AttachThreads = options.Native.AttachThreads;
o.ConnectionTimeoutMillis = (int)options.Native.ConnectionTimeout.TotalMilliseconds;
o.EnableNdk = options.Native.EnableNdk;
o.EnableShutdownHook = options.Native.EnableShutdownHook;
o.EnableUncaughtExceptionHandler = options.Native.EnableUncaughtExceptionHandler;
o.ProfilesSampleRate = (JavaDouble?)options.Native.ProfilesSampleRate;
o.PrintUncaughtStackTrace = options.Native.PrintUncaughtStackTrace;
o.ReadTimeoutMillis = (int)options.Native.ReadTimeout.TotalMilliseconds;
// In-App Excludes and Includes to be passed to the Android SDK
options.Android.InAppExcludes?.ForEach(o.AddInAppExclude);
options.Android.InAppIncludes?.ForEach(o.AddInAppInclude);
options.Native.InAppExcludes?.ForEach(o.AddInAppExclude);
options.Native.InAppIncludes?.ForEach(o.AddInAppInclude);
// These options are intentionally set and not exposed for modification
o.EnableExternalConfiguration = false;
Expand Down Expand Up @@ -187,10 +187,10 @@ private static void InitSentryAndroidSdk(SentryOptions options)
}

// Set options for the managed SDK that depend on the Android SDK. (The user will not be able to modify these.)
options.AddEventProcessor(new AndroidEventProcessor(androidOptions!));
if (options.Android.LogCatIntegration != LogCatIntegrationType.None)
options.AddEventProcessor(new AndroidEventProcessor(nativeOptions!));
if (options.Native.LogCatIntegration != LogCatIntegrationType.None)
{
options.AddEventProcessor(new LogCatAttachmentEventProcessor(options.DiagnosticLogger, options.Android.LogCatIntegration, options.Android.LogCatMaxLines));
options.AddEventProcessor(new LogCatAttachmentEventProcessor(options.DiagnosticLogger, options.Native.LogCatIntegration, options.Native.LogCatMaxLines));
}
options.CrashedLastRun = () => JavaSdk.Sentry.IsCrashedLastRun()?.BooleanValue() is true;
options.EnableScopeSync = true;
Expand Down
10 changes: 5 additions & 5 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 @@ -24,9 +24,9 @@ public class CocoaOptions
public bool? EnableSwizzling { get; set; }
public bool? EnableUIViewControllerTracing { get; set; }
public bool? EnableUserInteractionTracing { get; set; }
public bool? EnableCocoaSdkTracing { get; set; }
public bool? EnableTracing { 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 All @@ -42,7 +42,7 @@ public void ApplyTo(SentryOptions.CocoaOptions options)
options.EnableSwizzling = EnableSwizzling ?? options.EnableSwizzling;
options.EnableUIViewControllerTracing = EnableUIViewControllerTracing ?? options.EnableUIViewControllerTracing;
options.EnableUserInteractionTracing = EnableUserInteractionTracing ?? options.EnableUserInteractionTracing;
options.EnableCocoaSdkTracing = EnableCocoaSdkTracing ?? options.EnableCocoaSdkTracing;
options.EnableTracing = EnableTracing ?? options.EnableTracing;
}
}
}
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
8 changes: 4 additions & 4 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 Expand Up @@ -182,7 +182,7 @@ internal CocoaOptions(SentryOptions options)
/// Gets or sets a value that indicates if tracing features are enabled on the embedded Cocoa SDK.
/// The default value is <c>false</c> (disabled).
/// </summary>
public bool EnableCocoaSdkTracing { get; set; } = false;
public bool EnableTracing { get; set; } = false;

internal List<string>? InAppExcludes { get; private set; }
internal List<string>? InAppIncludes { get; private set; }
Expand Down
Loading

0 comments on commit a2fa21f

Please sign in to comment.