Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a1b0cb6
Initial commit for exposing iOS native before send & crashed last run
aritchie Feb 11, 2025
1a8474e
Initial feature set is working
aritchie Feb 11, 2025
c36be94
Format code
getsentry-bot Feb 11, 2025
cd074d4
Update CHANGELOG.md
aritchie Feb 11, 2025
17790c7
Merge branch '2102-ios_beforesend_oncrashedlastrun' of https://github…
aritchie Feb 11, 2025
70a677d
Merge signal abort code before user based BeforeSend
aritchie Feb 12, 2025
4a6462c
Move native BeforeSend & OnCrashedLastRun events to SentryOptions - O…
aritchie Feb 14, 2025
91145ab
Always run NativeOptions.BeforeSend so sig aborts can be filtered
aritchie Feb 14, 2025
fd48026
Update SentrySdk.cs
aritchie Feb 14, 2025
1b3dfdd
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 18, 2025
c29a785
Update CHANGELOG.md
aritchie Feb 18, 2025
50a5554
Format code
getsentry-bot Feb 18, 2025
63e3f55
WIP - removing serialization mechanics as they cause a native crash d…
aritchie Feb 18, 2025
5c06eb5
Transferring transformed sentryevent back to original native event in…
aritchie Feb 21, 2025
18a1079
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 21, 2025
000b324
Remove unnecessary hacks
aritchie Feb 21, 2025
bdfe3a9
Format code
getsentry-bot Feb 21, 2025
bf4d33d
Add missing bindable option for native iOS sentryoptions
aritchie Feb 21, 2025
52f0699
Update SentrySdk.cs
aritchie Feb 24, 2025
dab118e
Update SentrySdk.cs
aritchie Feb 24, 2025
1f721b8
Update CHANGELOG.md
aritchie Feb 24, 2025
4830f8e
Update CHANGELOG.md
aritchie Feb 24, 2025
b8b08cc
Unit tests mapping checks to/from native iOS
aritchie Feb 24, 2025
a46bd43
Format code
getsentry-bot Feb 24, 2025
5dca9e2
Update NativeSerializationTests.cs
aritchie Feb 24, 2025
00cbc04
Revert "Add missing bindable option for native iOS sentryoptions"
aritchie Feb 24, 2025
d2776e1
Remove iOS native event suppress configuration
aritchie Feb 24, 2025
5e8134a
Update CHANGELOG.md
aritchie Feb 24, 2025
d8ac6ea
Rename tests according to review
aritchie Feb 25, 2025
63326ec
add timestamp for deserialize test
aritchie Feb 25, 2025
d1feffc
Account for fractions of seconds
aritchie Feb 26, 2025
6c10867
Merge branch 'main' into 2102-ios_beforesend_oncrashedlastrun
aritchie Feb 26, 2025
ede88c1
Platforms should not change
aritchie Feb 26, 2025
bbf9da4
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
65534f0
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
35113e1
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
4c6d7a2
Update CocoaExtensionsTests.cs
aritchie Feb 26, 2025
e80ce73
Safety SentryLevel in both directions
aritchie Mar 3, 2025
e97bc47
Update EnumExtensions.cs
aritchie Mar 3, 2025
61665c5
Format code
getsentry-bot Mar 3, 2025
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: 10 additions & 1 deletion src/Sentry/Platforms/Cocoa/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ internal static class EnumExtensions
{
// These align, so we can just cast
public static SentryLevel ToSentryLevel(this CocoaSdk.SentryLevel level) => (SentryLevel)level;
public static CocoaSdk.SentryLevel ToCocoaSentryLevel(this SentryLevel level) => (CocoaSdk.SentryLevel)level;

public static CocoaSdk.SentryLevel ToCocoaSentryLevel(this SentryLevel level) => level switch
{
SentryLevel.Debug => CocoaSdk.SentryLevel.Debug,
SentryLevel.Info => CocoaSdk.SentryLevel.Info,
SentryLevel.Warning => CocoaSdk.SentryLevel.Warning,
SentryLevel.Error => CocoaSdk.SentryLevel.Error,
SentryLevel.Fatal => CocoaSdk.SentryLevel.Fatal,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
};

public static BreadcrumbLevel ToBreadcrumbLevel(this CocoaSdk.SentryLevel level) =>
level switch
Expand Down
22 changes: 20 additions & 2 deletions src/Sentry/SentryEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger)
/// </summary>
public static SentryEvent FromJson(JsonElement json) => FromJson(json, null);

private static SentryLevel? SafeLevelFromJson(JsonElement json)
{
var levelString = json.GetPropertyOrNull("level")?.GetString();
if (levelString == null)
return null;

// Native SentryLevel.None does not exist in dotnet
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we know what the behaviour of SentryLevel.None is? Does it mean nothing gets logged? Is that was setting the level = null does?

return levelString.ToLowerInvariant() switch
{
"debug" => SentryLevel.Debug,
"info" => SentryLevel.Info,
"warning" => SentryLevel.Warning,
"fatal" => SentryLevel.Fatal,
"error" => SentryLevel.Error,
_ => null
Copy link
Collaborator

Choose a reason for hiding this comment

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

I take it this is intentional (we don't want to throw an exception but we can't conveniently log the irregularity anywhere)?

};
}

internal static SentryEvent FromJson(JsonElement json, Exception? exception)
{
var modules = json.GetPropertyOrNull("modules")?.GetStringDictionaryOrNull();
Expand All @@ -299,7 +317,7 @@ internal static SentryEvent FromJson(JsonElement json, Exception? exception)
var distribution = json.GetPropertyOrNull("dist")?.GetString();
var exceptionValues = json.GetPropertyOrNull("exception")?.GetPropertyOrNull("values")?.EnumerateArray().Select(SentryException.FromJson).ToList().Pipe(v => new SentryValues<SentryException>(v));
var threadValues = json.GetPropertyOrNull("threads")?.GetPropertyOrNull("values")?.EnumerateArray().Select(SentryThread.FromJson).ToList().Pipe(v => new SentryValues<SentryThread>(v));
var level = json.GetPropertyOrNull("level")?.GetString()?.ParseEnum<SentryLevel>();

var transaction = json.GetPropertyOrNull("transaction")?.GetString();
var request = json.GetPropertyOrNull("request")?.Pipe(SentryRequest.FromJson);
var contexts = json.GetPropertyOrNull("contexts")?.Pipe(SentryContexts.FromJson);
Expand All @@ -310,7 +328,7 @@ internal static SentryEvent FromJson(JsonElement json, Exception? exception)
var breadcrumbs = json.GetPropertyOrNull("breadcrumbs")?.EnumerateArray().Select(Breadcrumb.FromJson).ToList();
var extra = json.GetPropertyOrNull("extra")?.GetDictionaryOrNull();
var tags = json.GetPropertyOrNull("tags")?.GetStringDictionaryOrNull();

var level = SafeLevelFromJson(json);
var debugMeta = json.GetPropertyOrNull("debug_meta")?.Pipe(DebugMeta.FromJson);

return new SentryEvent(exception, timestamp, eventId)
Expand Down
3 changes: 2 additions & 1 deletion test/Sentry.Tests/Platforms/iOS/CocoaExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Foundation;
using Sentry.Cocoa.Extensions;
using Xunit;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void ToSentryEvent_ConvertToManaged()

private static void AssertEqual(SentryEvent managed, CocoaSdk.SentryEvent native)
{
native.ServerName.Should().Be(managed.ServerName);
native.ServerName.Should().Be(managed.ServerName, "Server Name");
native.Dist.Should().Be(managed.Distribution, "Distribution");
native.Logger.Should().Be(managed.Logger, "Logger");
native.ReleaseName.Should().Be(managed.Release, "Release");
Expand Down