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

refactor: rename platform specific code from iOS to Cocoa #2929

Merged
merged 2 commits into from
Dec 1, 2023
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
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

#### Removed APIs

- SentrySinkExtensions.ConfigureSentrySerilogOptions is now internal. If you were using this method, please use one of the `SentrySinkExtensions.Sentry` extension methods instead. ([#2902](https://github.com/getsentry/sentry-dotnet/pull/2902))

### Fixes

- Fixed Sentry SDK has not been initialised when using ASP.NET Core, Serilog and OpenTelemetry ([#2911](https://github.com/getsentry/sentry-dotnet/pull/2911))
- SentrySinkExtensions.ConfigureSentrySerilogOptions is now internal. If you were using this method, please use one of the `SentrySinkExtensions.Sentry` extension methods instead. ([#2902](https://github.com/getsentry/sentry-dotnet/pull/2902))

#### Changed APIs

- `AssemblyExtensions` have been made public again. ([#2917](https://github.com/getsentry/sentry-dotnet/pull/2917))
- Rename iOS and MacCatalyst platform specific options from `iOS` to `Cocoa` ([#2929](https://github.com/getsentry/sentry-dotnet/pull/2929))

### Fixes

- Fixed Sentry SDK has not been initialised when using ASP.NET Core, Serilog and OpenTelemetry ([#2911](https://github.com/getsentry/sentry-dotnet/pull/2911))

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Although the files in `/src/Sentry/Platforms/` are part of the `Sentry` project,
```xml
<!-- Platform-specific props included here -->
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<Import Project="Platforms\iOS\Sentry.iOS.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
<Import Project="Platforms\Cocoa\Sentry.Cocoa.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
```

These `*.props` files are used to add platform-specific files, such as references to the binding projects for each native SDK (which provide .NET wrappers around native Android or Cocoa functions).
Expand Down
4 changes: 4 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'ios' And '$(TargetPlatformIdentifier)' != 'maccatalyst'">
<!-- Exclude our platform-specific code: -->
<Compile Remove="**\*.Cocoa.cs" />
<Compile Remove="**\Cocoa\**\*.cs" />
<!-- Maui device test projects have these too: -->
<Compile Remove="**\*.iOS.cs" />
<Compile Remove="**\iOS\**\*.cs" />
Comment on lines 26 to 27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get those. Do you mean the Maui tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Bindings.Cocoa/PrivateApiDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sentry.CocoaSdk;

// SentryScope.ApplyToEvent was made private in 8.x, but we use it in our IosEventProcessor class.
// SentryScope.ApplyToEvent was made private in 8.x, but we use it in our CocoaEventProcessor class.
// TODO: Find a better way than using the private API.
partial interface SentryScope
{
Expand Down
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__
iOS.ApplyTo(options.iOS);
Cocoa.ApplyTo(options.Cocoa);
#endif
}
}
2 changes: 1 addition & 1 deletion src/Sentry/Internal/DebugStackTrace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private IEnumerable<SentryStackFrame> CreateFrames(StackTrace stackTrace, bool i
// TODO there will be support for NativeAOT in the future.
_nativeDebugImages ??= new();
#elif __IOS__ || MACCATALYST
_nativeDebugImages ??= Sentry.iOS.C.LoadDebugImages(_options.DiagnosticLogger);
_nativeDebugImages ??= Sentry.Cocoa.C.LoadDebugImages(_options.DiagnosticLogger);
#else
_nativeDebugImages ??= Sentry.Native.C.LoadDebugImages(_options.DiagnosticLogger);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ namespace Sentry;

internal partial class BindableSentryOptions
{
public IosOptions iOS { get; } = new IosOptions();
public CocoaOptions Cocoa { get; } = new CocoaOptions();

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

public void ApplyTo(SentryOptions.IosOptions options)
public void ApplyTo(SentryOptions.CocoaOptions options)
{
options.AttachScreenshot = AttachScreenshot ?? options.AttachScreenshot;
options.AppHangTimeoutInterval = AppHangTimeoutInterval ?? options.AppHangTimeoutInterval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Sentry.Internal.Extensions;
using Sentry.Protocol;

namespace Sentry.iOS;
namespace Sentry.Cocoa;

internal static class C
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Sentry.Extensibility;
using Sentry.iOS.Extensions;
using Sentry.Cocoa.Extensions;

namespace Sentry.iOS;
namespace Sentry.Cocoa;

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

public IosEventProcessor(SentryCocoaOptions options)
public CocoaEventProcessor(SentryCocoaOptions options)
{
_options = options;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using Sentry.iOS.Extensions;
using Sentry.Cocoa.Extensions;
using Sentry.Extensibility;
using Sentry.Internal.Extensions;

namespace Sentry.iOS;
namespace Sentry.Cocoa;

internal sealed class IosScopeObserver : IScopeObserver
internal sealed class CocoaScopeObserver : IScopeObserver
{
private readonly SentryOptions _options;
private readonly IScopeObserver? _innerObserver;

public IosScopeObserver(SentryOptions options)
public CocoaScopeObserver(SentryOptions options)
{
_options = options;

// Chain any previous observer, but guard against circular reference.
var observer = options.ScopeObserver;
_innerObserver = observer is IosScopeObserver ? null : observer;
_innerObserver = observer is CocoaScopeObserver ? null : observer;
}

public void AddBreadcrumb(Breadcrumb breadcrumb)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sentry.Extensibility;

namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class BreadcrumbExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sentry.Extensibility;

namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class CocoaExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class EnumExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class MiscExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sentry.iOS.Facades;
using Sentry.Cocoa.Facades;

namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class SamplingContextExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// using Sentry.Extensibility;
// using Sentry.Protocol.Envelopes;
//
// namespace Sentry.iOS.Extensions;
// namespace Sentry.Cocoa.Extensions;
//
// internal static class SentryEventExtensions
// {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sentry.Extensibility;

namespace Sentry.iOS.Extensions;
namespace Sentry.Cocoa.Extensions;

internal static class UserExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Sentry.iOS.Extensions;
using Sentry.Cocoa.Extensions;

namespace Sentry.iOS.Facades;
namespace Sentry.Cocoa.Facades;

internal class TransactionContextFacade : ITransactionContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ namespace Sentry;
public partial class SentryOptions
{
/// <summary>
/// Exposes additional options for the iOS platform.
/// Exposes additional options for iOS and MacCatalyst.
/// </summary>
// ReSharper disable once InconsistentNaming
public IosOptions iOS { get; }
public CocoaOptions Cocoa { get; }

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

internal IosOptions(SentryOptions options)
internal CocoaOptions(SentryOptions options)
{
_options = options;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Sentry.iOS;
using Sentry.iOS.Extensions;
using Sentry.Cocoa;
using Sentry.Cocoa.Extensions;

// ReSharper disable once CheckNamespace
namespace Sentry;
Expand Down Expand Up @@ -71,7 +71,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)
}

// These options we have behind feature flags
if (options is {IsPerformanceMonitoringEnabled: true, iOS.EnableCocoaSdkTracing: true})
if (options is {IsPerformanceMonitoringEnabled: true, Cocoa.EnableCocoaSdkTracing: true})
{
if (options.EnableTracing != null)
{
Expand All @@ -96,7 +96,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)

// TODO: Finish SentryEventExtensions to enable these

// if (options.iOS.EnableCocoaSdkBeforeSend && options.BeforeSend is { } beforeSend)
// if (options.Cocoa.EnableCocoaSdkBeforeSend && options.BeforeSend is { } beforeSend)
// {
// cocoaOptions.BeforeSend = evt =>
// {
Expand All @@ -109,7 +109,7 @@ private static void InitSentryCocoaSdk(SentryOptions options)
// };
// }

// if (options.iOS.OnCrashedLastRun is { } onCrashedLastRun)
// if (options.Cocoa.OnCrashedLastRun is { } onCrashedLastRun)
// {
// cocoaOptions.OnCrashedLastRun = evt =>
// {
Expand All @@ -119,29 +119,29 @@ private static void InitSentryCocoaSdk(SentryOptions options)
// }

// These options are from Cocoa's SentryOptions
cocoaOptions.AttachScreenshot = options.iOS.AttachScreenshot;
cocoaOptions.AppHangTimeoutInterval = options.iOS.AppHangTimeoutInterval.TotalSeconds;
cocoaOptions.IdleTimeout = options.iOS.IdleTimeout.TotalSeconds;
cocoaOptions.AttachScreenshot = options.Cocoa.AttachScreenshot;
cocoaOptions.AppHangTimeoutInterval = options.Cocoa.AppHangTimeoutInterval.TotalSeconds;
cocoaOptions.IdleTimeout = options.Cocoa.IdleTimeout.TotalSeconds;
cocoaOptions.Dist = options.Distribution;
cocoaOptions.EnableAppHangTracking = options.iOS.EnableAppHangTracking;
cocoaOptions.EnableAutoBreadcrumbTracking = options.iOS.EnableAutoBreadcrumbTracking;
cocoaOptions.EnableAutoPerformanceTracing = options.iOS.EnableAutoPerformanceTracing;
cocoaOptions.EnableCoreDataTracing = options.iOS.EnableCoreDataTracing;
cocoaOptions.EnableFileIOTracing = options.iOS.EnableFileIOTracing;
cocoaOptions.EnableNetworkBreadcrumbs = options.iOS.EnableNetworkBreadcrumbs;
cocoaOptions.EnableNetworkTracking = options.iOS.EnableNetworkTracking;
cocoaOptions.EnableWatchdogTerminationTracking = options.iOS.EnableWatchdogTerminationTracking;
cocoaOptions.EnableSwizzling = options.iOS.EnableSwizzling;
cocoaOptions.EnableUIViewControllerTracing = options.iOS.EnableUIViewControllerTracing;
cocoaOptions.EnableUserInteractionTracing = options.iOS.EnableUserInteractionTracing;
cocoaOptions.UrlSessionDelegate = options.iOS.UrlSessionDelegate;
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;

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

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

// These options are intentionally not expose or modified
// cocoaOptions.Enabled
Expand Down Expand Up @@ -183,10 +183,10 @@ private static void InitSentryCocoaSdk(SentryOptions options)
SentryCocoaSdk.StartWithOptions(cocoaOptions);

// Set options for the managed SDK that depend on the Cocoa SDK. (The user will not be able to modify these.)
options.AddEventProcessor(new IosEventProcessor(cocoaOptions));
options.AddEventProcessor(new CocoaEventProcessor(cocoaOptions));
options.CrashedLastRun = () => SentryCocoaSdk.CrashedLastRun;
options.EnableScopeSync = true;
options.ScopeObserver = new IosScopeObserver(options);
options.ScopeObserver = new CocoaScopeObserver(options);

// TODO: Pause/Resume
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<!-- Platform-specific props included here -->
<Import Project="Platforms\Android\Sentry.Android.props" Condition="'$(TargetPlatformIdentifier)' == 'android'" />
<Import Project="Platforms\iOS\Sentry.iOS.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
<Import Project="Platforms\Cocoa\Sentry.Cocoa.props" Condition="'$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst'" />
<Import Project="Platforms\Native\Sentry.Native.targets"
Condition="'$(TargetPlatformIdentifier)' != 'android' and '$(TargetPlatformIdentifier)' != 'ios' and '$(TargetPlatformIdentifier)' != 'maccatalyst'"/>

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__
iOS = new IosOptions(this);
Cocoa = new CocoaOptions(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.IosOptions)) // Exclude the Mobile sub-property
&& !(p.PropertyType == typeof(SentryOptions.CocoaOptions)) // Exclude the Mobile sub-property
#endif
);
}
Expand Down
12 changes: 6 additions & 6 deletions test/Sentry.Tests/Platforms/iOS/BindableSentryOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# if __IOS__
using Microsoft.Extensions.Configuration;

namespace Sentry.Tests.Platforms.iOS;
namespace Sentry.Tests.Platforms.Cocoa;

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

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

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

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