Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and configure options for the iOS SDK #1849

Merged
merged 28 commits into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c431648
ProcessInfo cleanup
mattjohnsonpint Aug 11, 2022
47613e8
Fix typos
mattjohnsonpint Aug 11, 2022
0013974
default tags
mattjohnsonpint Aug 11, 2022
8aaf552
Binding updates
mattjohnsonpint Aug 11, 2022
e12358c
More Cocoa Extensions
mattjohnsonpint Aug 11, 2022
a322d55
default usings
mattjohnsonpint Aug 11, 2022
2d6899d
Start event processor
mattjohnsonpint Aug 11, 2022
c7166b8
iOS options accessor
mattjohnsonpint Aug 11, 2022
3c9a02f
Enums
mattjohnsonpint Aug 11, 2022
825f24f
Tracing
mattjohnsonpint Aug 11, 2022
4b69cea
Start BeforeSend
mattjohnsonpint Aug 11, 2022
e3209f7
In-App Excludes and Includes
mattjohnsonpint Aug 11, 2022
448adb4
Remaining options
mattjohnsonpint Aug 11, 2022
a813440
A few more
mattjohnsonpint Aug 11, 2022
8c7c424
Fix sample
mattjohnsonpint Aug 12, 2022
5fee85c
Update comment about crash duplication
mattjohnsonpint Aug 12, 2022
0f72034
Update sample app
mattjohnsonpint Aug 12, 2022
1f188cd
Filter out SIGABRT
mattjohnsonpint Aug 12, 2022
63b6d5a
comments
mattjohnsonpint Aug 12, 2022
d3c5316
Remove duplicate property
mattjohnsonpint Aug 12, 2022
a9a0331
defaults, xmldocs, and comments
mattjohnsonpint Aug 12, 2022
38fba0c
remove deprecated property
mattjohnsonpint Aug 12, 2022
1afe13e
Update CHANGELOG.md
mattjohnsonpint Aug 12, 2022
ad1342d
Use consistent casing
mattjohnsonpint Aug 12, 2022
208fc69
Alias SentryCocoaSdk
mattjohnsonpint Aug 12, 2022
d1ac5e7
Improve SentryCocoaOptions initialization
mattjohnsonpint Aug 12, 2022
5d2cfc1
Cleanup delegate calls
mattjohnsonpint Aug 12, 2022
937acaa
.
mattjohnsonpint Aug 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Enable Scope Sync for iOS ([#1834](https://github.com/getsentry/sentry-dotnet/pull/1834))
- Add API for deliberately crashing an app ([#1842](https://github.com/getsentry/sentry-dotnet/pull/1842))
- Add Mac Catalyst target ([#1848](https://github.com/getsentry/sentry-dotnet/pull/1848))
- Add and configure options for the iOS SDK ([#1849](https://github.com/getsentry/sentry-dotnet/pull/1849))

### Fixes

Expand Down
27 changes: 18 additions & 9 deletions samples/Sentry.Samples.Maui/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ public partial class MainPage
{
private readonly ILogger<MainPage> _logger;

int count = 0;
private int _count = 0;

// NOTE: You can only inject an ILogger<T>, not a plain ILogger
public MainPage(ILogger<MainPage> logger)
{
_logger = logger;
InitializeComponent();
}

protected override void OnAppearing()
{
#if !ANDROID
JavaCrashBtn.IsVisible = false;
Expand All @@ -20,22 +26,25 @@ public MainPage(ILogger<MainPage> logger)
#if !(ANDROID || IOS || MACCATALYST)
NativeCrashBtn.IsVisible = false;
#endif
_logger = logger;
InitializeComponent();
base.OnAppearing();
}

private void OnCounterClicked(object sender, EventArgs e)
{
count++;
_count++;

if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
if (_count == 1)
{
CounterBtn.Text = $"Clicked {_count} time";
}
else
CounterBtn.Text = $"Clicked {count} times";
{
CounterBtn.Text = $"Clicked {_count} times";
}

SemanticScreenReader.Announce(CounterBtn.Text);

_logger.LogInformation("The button has been clicked {ClickCount} times", count);
_logger.LogInformation("The button has been clicked {ClickCount} times", _count);
}

private void OnUnhandledExceptionClicked(object sender, EventArgs e)
Expand All @@ -47,7 +56,7 @@ private void OnCapturedExceptionClicked(object sender, EventArgs e)
{
try
{
SentrySdk.CauseCrash(CrashType.Managed);
throw new ApplicationException("This exception was thrown and captured manually, without crashing the app.");
}
catch (Exception ex)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sentry/Internal/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ internal Task PreciseAppStartupTask
{
#if ANDROID || IOS || MACCATALYST
options.LogWarning("StartupTimeDetectionMode.Best is not available on this platform. Using 'Fast' mode.");
return;
#else
// StartupTime is set to UtcNow in this constructor.
// That's computationally cheap but not very precise.
Expand All @@ -99,7 +98,7 @@ internal Task PreciseAppStartupTask
}
}

#if !ANDROID
#if !(ANDROID || IOS || MACCATALYST)
private static DateTimeOffset GetStartupTime()
{
using var proc = Process.GetCurrentProcess();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Sentry.Android.Extensions;

internal static class SMiscExtensions
internal static class MiscExtensions
{
public static SentryId ToSentryId(this Java.Protocol.SentryId sentryId) => new(Guid.Parse(sentryId.ToString()));

Expand Down
49 changes: 25 additions & 24 deletions src/Sentry/Platforms/Android/SentryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class AndroidOptions
/// <remarks>
/// See https://docs.sentry.io/platforms/android/configuration/app-not-respond/
/// </remarks>
public bool AnrReportInDebug { get; set; }
public bool AnrReportInDebug { get; set; } = false;
SimonCropp marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets or sets the ANR (Application Not Responding) timeout interval.
Expand All @@ -53,7 +53,7 @@ public class AndroidOptions
/// This feature is provided by the Sentry Android SDK and thus only works for Java-based errors.
/// See https://docs.sentry.io/platforms/android/enriching-events/screenshots/
/// </remarks>
public bool AttachScreenshot { get; set; }
public bool AttachScreenshot { get; set; } = false;

/// <summary>
/// Gets or sets a value that indicates if automatic breadcrumbs for <c>Activity</c> lifecycle events are
Expand Down Expand Up @@ -129,7 +129,7 @@ public class AndroidOptions
/// <remarks>
/// See https://docs.sentry.io/platforms/android/performance/instrumentation/automatic-instrumentation/#user-interaction-instrumentation
/// </remarks>
public bool EnableUserInteractionTracing { get; set; }
public bool EnableUserInteractionTracing { get; set; } = false;

/// <summary>
/// Gets or sets the interval for profiling traces, when enabled with <see cref="ProfilingEnabled"/>.
Expand All @@ -144,22 +144,22 @@ public class AndroidOptions
/// Gets or sets a value that indicates if all the threads are automatically attached to all logged events.
/// The default value is <c>false</c> (disabled).
/// </summary>
public bool AttachThreads { get; set; }
public bool AttachThreads { get; set; } = false;

/// <summary>
/// Gets or sets the connection timeout on the HTTP connection used by Java when sending data to Sentry.
/// The default value is 5 seconds.
/// </summary>
public TimeSpan ConnectionTimeout { get; set; } = TimeSpan.FromSeconds(5);

// TODO: Should we have this Distribution property on SentryOptions (with Release and Environment)?
/// <summary>
/// Gets or sets the distribution.
/// Gets or sets the distribution of the application.
/// </summary>
/// <remarks>
/// See https://docs.sentry.io/platforms/java/guides/spring/configuration/#distribution
/// See "dist" in https://develop.sentry.dev/sdk/event-payloads/#optional-attributes
/// </remarks>
public string? Distribution { get; set; }
// TODO: Should we have this property on the main SentryOptions (with Release and Environment)?
public string? Distribution { get; set; } = null;

/// <summary>
/// Gets or sets a value that indicates if the NDK (Android Native Development Kit) is enabled.
Expand All @@ -186,14 +186,14 @@ public class AndroidOptions
/// Gets or sets a value that indicates if uncaught Java errors will have their stack traces
/// printed to the standard error stream. The default value is <c>false</c> (disabled).
/// </summary>
public bool PrintUncaughtStackTrace { get; set; }
public bool PrintUncaughtStackTrace { get; set; } = false;

/// <summary>
/// Gets or sets if profiling is enabled for transactions.
/// The default value is <c>false</c> (disabled).
/// See also <see cref="ProfilingTracesInterval"/>.
/// </summary>
public bool ProfilingEnabled { get; set; }
public bool ProfilingEnabled { get; set; } = false;

/// <summary>
/// Gets or sets the read timeout on the HTTP connection used by Java when sending data to Sentry.
Expand All @@ -204,8 +204,8 @@ public class AndroidOptions

// ---------- Other ----------

internal string[]? InAppExclude { get; set; }
internal string[]? InAppInclude { get; set; }
internal List<string>? InAppExcludes { get; private set; }
internal List<string>? InAppIncludes { get; private set; }

/// <summary>
/// Add prefix to exclude from 'InApp' stacktrace list by the Android SDK.
Expand All @@ -218,10 +218,11 @@ public class AndroidOptions
/// <example>
/// 'java.util.', 'org.apache.logging.log4j.'
/// </example>
public void AddInAppExclude(string prefix) =>
InAppExclude = InAppExclude != null
? InAppExclude.Concat(new[] { prefix }).ToArray()
: new[] { prefix };
public void AddInAppExclude(string prefix)
{
InAppExcludes ??= new List<string>();
InAppExcludes.Add(prefix);
}

/// <summary>
/// Add prefix to include as in 'InApp' stacktrace by the Android SDK.
Expand All @@ -234,26 +235,26 @@ public class AndroidOptions
/// <example>
/// 'java.util.customcode.', 'io.sentry.samples.'
/// </example>
public void AddInAppInclude(string prefix) =>
InAppInclude = InAppInclude != null
? InAppInclude.Concat(new[] { prefix }).ToArray()
: new[] { prefix };
public void AddInAppInclude(string prefix){
InAppIncludes ??= new List<string>();
InAppIncludes.Add(prefix);
}

/// <summary>
/// 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; }
public bool EnableAndroidSdkTracing { get; set; } = false;

/// <summary>
/// Gets or sets a value that indicates if the <see cref="BeforeSend"/> callback will be invoked for
/// events that originate from the embedded Android SDK. The default value is <c>false</c> (disabled).
/// </summary>
/// <remarks>
/// This is an experimental feature and is imperefct, as the .NET SDK and the embedded Android SDK don't
/// This is an experimental feature and is imperfect, as the .NET SDK and the embedded Android SDK don't
/// implement all of the same features that may be present in the event graph. Some optional elements may
/// be stripped away during the roundtripping between the two SDKs. Use with caution.
/// be stripped away during the round-tripping between the two SDKs. Use with caution.
/// </remarks>
public bool EnableAndroidSdkBeforeSend { get; set; }
public bool EnableAndroidSdkBeforeSend { get; set; } = false;
}
}
11 changes: 4 additions & 7 deletions src/Sentry/Platforms/Android/SentrySdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ private static void InitSentryAndroidSdk(SentryOptions options)
o.CacheDirPath = Path.Combine(cacheDirectoryPath, "android");
}

var javaTags = o.Tags;
foreach (var tag in options.DefaultTags)
{
javaTags.Add(tag);
}
// NOTE: Tags in options.DefaultTags should not be passed down, because we already call SetTag on each
// one when sending events, which is relayed through the scope observer.

if (options.HttpProxy is System.Net.WebProxy proxy)
{
Expand Down Expand Up @@ -160,8 +157,8 @@ private static void InitSentryAndroidSdk(SentryOptions options)
o.ReadTimeoutMillis = (int)options.Android.ReadTimeout.TotalMilliseconds;

// In-App Excludes and Includes to be passed to the Android SDK
options.Android.InAppExclude?.ToList().ForEach(x => o.AddInAppExclude(x));
options.Android.InAppInclude?.ToList().ForEach(x => o.AddInAppInclude(x));
options.Android.InAppExcludes?.ForEach(x => o.AddInAppExclude(x));
options.Android.InAppIncludes?.ForEach(x => o.AddInAppInclude(x));

// These options are intentionally set and not exposed for modification
o.EnableExternalConfiguration = false;
Expand Down
12 changes: 6 additions & 6 deletions src/Sentry/Platforms/iOS/Bindings/ApiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface Constants
// @interface PrivateSentrySDKOnly : NSObject
[BaseType (typeof(NSObject))]
[Internal]
interface PrivateSentrySDKOnly
interface PrivateSentrySdkOnly
{
// +(void)storeEnvelope:(SentryEnvelope * _Nonnull)envelope;
[Static]
Expand Down Expand Up @@ -117,12 +117,12 @@ interface PrivateSentrySDKOnly
// @property (assign, nonatomic, class) BOOL appStartMeasurementHybridSDKMode;
[Static]
[Export ("appStartMeasurementHybridSDKMode")]
bool AppStartMeasurementHybridSDKMode { get; set; }
bool AppStartMeasurementHybridSdkMode { get; set; }

// @property (assign, nonatomic, class) BOOL framesTrackingMeasurementHybridSDKMode;
[Static]
[Export ("framesTrackingMeasurementHybridSDKMode")]
bool FramesTrackingMeasurementHybridSDKMode { get; set; }
bool FramesTrackingMeasurementHybridSdkMode { get; set; }

// @property (readonly, assign, nonatomic, class) BOOL isFramesTrackingRunning;
[Static]
Expand Down Expand Up @@ -827,7 +827,7 @@ interface SentryOptions

// @property (copy, nonatomic) SentryBeforeSendEventCallback _Nullable beforeSend;
[NullAllowed, Export ("beforeSend", ArgumentSemantic.Copy)]
Func<SentryEvent, SentryEvent> BeforeSend { get; set; }
Func<SentryEvent?, SentryEvent> BeforeSend { get; set; }

// @property (copy, nonatomic) SentryBeforeBreadcrumbCallback _Nullable beforeBreadcrumb;
[NullAllowed, Export ("beforeBreadcrumb", ArgumentSemantic.Copy)]
Expand Down Expand Up @@ -916,7 +916,7 @@ interface SentryOptions

// @property (nonatomic) SentryTracesSamplerCallback _Nullable tracesSampler;
[NullAllowed, Export ("tracesSampler", ArgumentSemantic.Assign)]
Func<SentrySamplingContext, NSNumber> TracesSampler { get; set; }
Func<SentrySamplingContext, NSNumber?> TracesSampler { get; set; }

// @property (readonly, assign, nonatomic) BOOL isTracingEnabled;
[Export ("isTracingEnabled")]
Expand Down Expand Up @@ -1392,7 +1392,7 @@ interface SentryNSError : SentrySerializable
[BaseType (typeof(NSObject))]
[DisableDefaultCtor]
[Internal]
interface SentrySDK
interface SentrySdk
{
// @property (readonly, nonatomic, class) id<SentrySpan> _Nullable span;
[Static]
Expand Down