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

feat: Deserializing Events #4724

Merged
merged 34 commits into from
Feb 10, 2025
Merged

feat: Deserializing Events #4724

merged 34 commits into from
Feb 10, 2025

Conversation

philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Jan 16, 2025

📜 Description

Add Decodable implementations via Swift extensions to deserialize SentryEvents.

This is the feature branch PR for deserializing SentryEvents. We're going to open multiple PRs to this one, so we have smaller PRs for quicker reviews.

To minimize the scope the goal is not to use Encodable and keep the existing serialization logic.

💡 Motivation and Context

We need this for app hangs #4261.

💚 How did you test it?

📝 Checklist

You have to check all boxes before merging:

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Add Decodable implementations via Swift extensions to deserialize
SentryEvents.
Copy link

github-actions bot commented Jan 16, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 53e8709

@philprime
Copy link
Contributor

In case you want to implement a custom encoder for converting to the dictionary, I did implement a custom encoder before in Postie, to parse custom property wrappers/annotations into a structure to send URL requests.

Even though that use case is quite more complicated than just encoding to a dictionary, it might be helpful for reference:

https://github.com/kula-app/Postie/blob/main/Sources/Postie/Encoder/RequestEncoder.swift

Copy link

github-actions bot commented Jan 16, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1227.84 ms 1234.98 ms 7.14 ms
Size 22.31 KiB 815.00 KiB 792.68 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
8f397a7 1252.37 ms 1274.80 ms 22.43 ms
f3b8999 1231.37 ms 1240.04 ms 8.67 ms
1b09e3f 1227.24 ms 1242.19 ms 14.95 ms
dc0db9e 1246.06 ms 1260.46 ms 14.40 ms
533859f 1211.33 ms 1228.76 ms 17.43 ms
4f31f66 1213.96 ms 1236.76 ms 22.80 ms
9faf217 1268.86 ms 1274.82 ms 5.96 ms
464117d 1240.46 ms 1252.91 ms 12.45 ms
3912b16 1230.54 ms 1249.65 ms 19.11 ms
d8eb419 1221.91 ms 1253.62 ms 31.71 ms

App size

Revision Plain With Sentry Diff
8f397a7 20.76 KiB 420.55 KiB 399.79 KiB
f3b8999 22.31 KiB 771.06 KiB 748.74 KiB
1b09e3f 21.58 KiB 614.93 KiB 593.34 KiB
dc0db9e 20.76 KiB 419.62 KiB 398.86 KiB
533859f 22.85 KiB 408.84 KiB 385.99 KiB
4f31f66 21.58 KiB 682.39 KiB 660.81 KiB
9faf217 20.76 KiB 419.70 KiB 398.94 KiB
464117d 21.58 KiB 705.40 KiB 683.82 KiB
3912b16 21.58 KiB 625.82 KiB 604.24 KiB
d8eb419 22.85 KiB 408.87 KiB 386.02 KiB

Previous results on branch: feat/deserializing-events

Startup times

Revision Plain With Sentry Diff
85beb63 1224.20 ms 1242.88 ms 18.67 ms
8dae1f6 1212.60 ms 1226.52 ms 13.93 ms
8a562cc 1228.57 ms 1245.18 ms 16.60 ms
4cb0e69 1235.57 ms 1250.81 ms 15.24 ms
47d76c2 1228.86 ms 1244.53 ms 15.67 ms
378d4bd 1216.53 ms 1241.19 ms 24.66 ms
74e111a 1229.31 ms 1244.63 ms 15.33 ms
242b57f 1236.13 ms 1252.17 ms 16.04 ms
4dc265c 1221.31 ms 1238.55 ms 17.24 ms
1c434f9 1231.10 ms 1243.85 ms 12.75 ms

App size

Revision Plain With Sentry Diff
85beb63 22.31 KiB 815.12 KiB 792.80 KiB
8dae1f6 22.31 KiB 772.51 KiB 750.20 KiB
8a562cc 22.31 KiB 773.33 KiB 751.02 KiB
4cb0e69 22.31 KiB 815.11 KiB 792.80 KiB
47d76c2 22.31 KiB 815.33 KiB 793.01 KiB
378d4bd 22.31 KiB 784.05 KiB 761.73 KiB
74e111a 22.31 KiB 800.12 KiB 777.80 KiB
242b57f 22.31 KiB 801.48 KiB 779.17 KiB
4dc265c 22.31 KiB 798.21 KiB 775.90 KiB
1c434f9 22.31 KiB 815.74 KiB 793.43 KiB

@philipphofmann
Copy link
Member Author

In case you want to implement a custom encoder for converting to the dictionary

Thanks for pointing that out. I would rather spend the time converting all the serialization to Decoable, because that's what we should do on the long run, IMO.

@philprime, does the overall approach look good to you?

@philprime
Copy link
Contributor

Looks good to me.

@philipphofmann
Copy link
Member Author

philipphofmann commented Jan 16, 2025

FYI, @philprime, I ditched the Encodable because we have some tests validating the data for envelopes that break when using Encodable. Switching the whole serialization to Encodable will make fixing the tests easier. I want to keep the scope small for now.

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 99.64974% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.507%. Comparing base (c66aad1) to head (53e8709).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...s/Swift/Protocol/Codable/DecodeArbitraryData.swift 93.814% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #4724       +/-   ##
=============================================
+ Coverage   91.396%   91.507%   +0.110%     
=============================================
  Files          627       648       +21     
  Lines        74573     76252     +1679     
  Branches     26810     26822       +12     
=============================================
+ Hits         68157     69776     +1619     
- Misses        6317      6382       +65     
+ Partials        99        94        -5     
Files with missing lines Coverage Δ
Sources/Sentry/SentryEvent.m 99.270% <ø> (ø)
Sources/Sentry/SentryGeo.m 95.000% <100.000%> (+1.000%) ⬆️
Sources/Sentry/SentryLevelHelper.m 100.000% <100.000%> (ø)
...ft/Protocol/Codable/NSNumberDecodableWrapper.swift 100.000% <100.000%> (ø)
...ift/Protocol/Codable/SentryBreadcrumbCodable.swift 100.000% <100.000%> (ø)
Sources/Swift/Protocol/Codable/SentryCodable.swift 100.000% <100.000%> (ø)
...wift/Protocol/Codable/SentryDebugMetaCodable.swift 100.000% <100.000%> (ø)
...es/Swift/Protocol/Codable/SentryEventCodable.swift 100.000% <100.000%> (ø)
...wift/Protocol/Codable/SentryExceptionCodable.swift 100.000% <100.000%> (ø)
...es/Swift/Protocol/Codable/SentryFrameCodable.swift 100.000% <100.000%> (ø)
... and 29 more

... and 21 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c66aad1...53e8709. Read the comment docs.

Add Decodable/Deserializing of SentryFrame, including logic for decoding NSNumbers.
Add Decodable/Deserializing of SentryMessage.
Add Decodable/Deserializing of SentryDebugMeta.
Add Decodable/Deserializing of SentryThread.
Add Decodable/Deserializing of SentryException.
Add a custom date encoding strategy, which supports time intervals since
1970 and ISO 8601 formatted strings.
@philipphofmann philipphofmann marked this pull request as ready for review February 7, 2025 10:08
Copy link
Contributor

@philprime philprime left a comment

Choose a reason for hiding this comment

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

LGTM, left one comment for double-check

Sources/Sentry/SentryGeo.m Show resolved Hide resolved
@philipphofmann philipphofmann merged commit 7054aa2 into main Feb 10, 2025
47 of 48 checks passed
@philipphofmann philipphofmann deleted the feat/deserializing-events branch February 10, 2025 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants