-
-
Notifications
You must be signed in to change notification settings - Fork 226
#4018 - Safety calls to/from Android Native Serialization #4022
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
Merged
jamescrosswell
merged 22 commits into
main
from
4018-jsonelementhaswrongtype_android_breadcrumb
Mar 4, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
22ef584
#4018 - Safety calls to json serialization between native & dotnet an…
aritchie b32b142
Update CHANGELOG.md
aritchie fe5b3c0
Fix tests
aritchie b6071ec
Update JsonExtensionsTests.cs
aritchie d25e185
Update SentryEventExtensions.cs
aritchie f4df4c6
Update SentryEventExtensions.cs
aritchie a4f45e6
Format code
getsentry-bot 3087f0d
Removing flaky exception compare for now
aritchie e536677
More test fixes
aritchie cd911ad
Format code
getsentry-bot 9734ba2
Restore SentryUser
aritchie 87a235a
Fix serialization
aritchie af339e2
Merge branch '4018-jsonelementhaswrongtype_android_breadcrumb' of htt…
aritchie 8f2c6ae
Update SentrySdk.cs
aritchie 5199b74
Update src/Sentry/Platforms/Android/SentrySdk.cs
aritchie 09a9d54
Update "hack" with appropriate values
aritchie 482c3d0
Update SentrySdk.cs
aritchie 192cbc1
Update SentrySdk.cs
aritchie 1aeeee3
Update SentryEventExtensions.cs
aritchie 2983af0
Add samples for SetBeforeSend
aritchie 17f44d4
Merge branch 'main' into 4018-jsonelementhaswrongtype_android_breadcrumb
aritchie 9d3bc2a
Add sample
aritchie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
test/Sentry.Tests/Platforms/Android/JsonExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using FluentAssertions; | ||
| using Sentry.Android.Extensions; | ||
| using Xunit; | ||
|
|
||
| namespace Sentry.Tests.Platforms.Android; | ||
|
|
||
| public class JsonExtensionsTests | ||
|
|
||
| { | ||
| [Fact] | ||
| public void ToJavaSentryEvent_Success() | ||
|
|
||
| { | ||
| var evt = new SentryEvent(new Exception("Test Exception")); | ||
|
|
||
| evt.Level = SentryLevel.Debug; | ||
| evt.ServerName = "test server name"; | ||
| evt.Distribution = "test distribution"; | ||
| evt.Logger = "test logger"; | ||
| evt.Release = "test release"; | ||
| evt.Environment = "test environment"; | ||
| evt.TransactionName = "test transaction name"; | ||
| evt.Message = new SentryMessage | ||
| { | ||
| Params = ["Test"] | ||
| }; | ||
|
|
||
| evt.SetTag("TestTagKey", "TestTagValue"); | ||
| evt.AddBreadcrumb(new Breadcrumb("test breadcrumb", "test type")); | ||
| evt.SetExtra("TestExtraKey", "TestExtraValue"); | ||
| evt.User = new SentryUser | ||
| { | ||
| Id = "user id", | ||
| Username = "test", | ||
| Email = "[email protected]", | ||
| IpAddress = "127.0.0.1" | ||
| }; | ||
|
|
||
| var native = evt.ToJavaSentryEvent(new SentryOptions(), new JavaSdk.SentryOptions()); | ||
|
|
||
| AssertEqual(evt, native); | ||
| } | ||
|
|
||
|
|
||
| [Fact] | ||
| public void ToSentryEvent_ConvertToManaged() | ||
| { | ||
| var native = new JavaSdk.SentryEvent(); | ||
|
|
||
| native.Throwable = new Exception("Test Exception").ToThrowable(); | ||
| native.Timestamp = DateTimeOffset.UtcNow.ToJavaDate(); | ||
| native.Level = JavaSdk.SentryLevel.Debug; | ||
| native.ServerName = "native server name"; | ||
| native.Dist = "native dist"; | ||
| native.Logger = "native logger"; | ||
| native.Release = "native release"; | ||
| native.Environment = "native env"; | ||
| native.Transaction = "native transaction"; | ||
| native.Message = new JavaSdk.Protocol.Message | ||
| { | ||
| Params = ["Test"] | ||
| }; | ||
| native.SetTag("TestTagKey", "TestTagValue"); | ||
| native.SetExtra("TestExtraKey", "TestExtraValue"); | ||
| native.Breadcrumbs = | ||
| [ | ||
| new JavaSdk.Breadcrumb | ||
| { | ||
| Category = "category", | ||
| Level = JavaSdk.SentryLevel.Debug | ||
| } | ||
| ]; | ||
|
|
||
| native.User = new JavaSdk.Protocol.User | ||
| { | ||
| Id = "user id", | ||
| Username = "test", | ||
| Email = "[email protected]", | ||
| IpAddress = "127.0.0.1" | ||
| }; | ||
|
|
||
| var managed = native.ToSentryEvent(new JavaSdk.SentryOptions()); | ||
|
|
||
| AssertEqual(managed, native); | ||
| } | ||
|
|
||
|
|
||
| private static void AssertEqual(SentryEvent managed, JavaSdk.SentryEvent native) | ||
| { | ||
| native.ServerName.Should().Be(managed.ServerName, "Server Name"); | ||
| native.Dist.Should().Be(managed.Distribution, "Distribution"); | ||
| native.Logger.Should().Be(managed.Logger, "Logger"); | ||
| native.Release.Should().Be(managed.Release, "Release"); | ||
| native.Environment.Should().Be(managed.Environment, "Environment"); | ||
| native.Transaction.Should().Be(managed.TransactionName!, "Transaction"); | ||
| native.Level!.ToString().ToUpper().Should().Be(managed.Level!.ToString()!.ToUpper(), "Level"); | ||
| // native.Throwable.Message.Should().Be(managed.Exception!.Message, "Message should match"); | ||
|
|
||
| // extras | ||
| native.Extras.Should().NotBeNull("No extras found"); | ||
| native.Extras!.Count.Should().Be(1, "Extras should have 1 item"); | ||
| native.Extras!.Keys!.First().Should().Be(managed.Extra.Keys.First(), "Extras key should match"); | ||
| native.Extras!.Values!.First().ToString().Should().Be(managed.Extra.Values.First().ToString(), "Extra value should match"); | ||
|
|
||
| // tags | ||
| native.Tags.Should().NotBeNull("No tags found"); | ||
| native.Tags!.Count.Should().Be(1, "Tags should have 1 item"); | ||
| native.Tags!.Keys!.First().Should().Be(managed.Tags.Keys.First()); | ||
| native.Tags!.Values!.First().Should().Be(managed.Tags.Values.First()); | ||
|
|
||
| // breadcrumbs | ||
| native.Breadcrumbs.Should().NotBeNull("No breadcrumbs found"); | ||
| var nb = native.Breadcrumbs!.First(); | ||
| var mb = managed.Breadcrumbs!.First(); | ||
| nb.Message.Should().Be(mb.Message, "Breadcrumb message"); | ||
| nb.Type.Should().Be(mb.Type, "Breadcrumb type"); | ||
|
|
||
| // user | ||
| native.User!.Id.Should().Be(managed.User.Id, "UserId should match"); | ||
| native.User.Email.Should().Be(managed.User.Email, "Email should match"); | ||
| native.User.Username.Should().Be(managed.User.Username, "Username should match"); | ||
| native.User.IpAddress.Should().Be(managed.User.IpAddress, "IpAddress should match"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.