-
-
Notifications
You must be signed in to change notification settings - Fork 375
refactor: Add attributable protocol for typed attribute values #7077
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
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7077 +/- ##
=============================================
+ Coverage 84.716% 84.794% +0.078%
=============================================
Files 459 461 +2
Lines 27494 27780 +286
Branches 12120 12317 +197
=============================================
+ Hits 23292 23556 +264
- Misses 3942 4183 +241
+ Partials 260 41 -219
... and 33 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 35c962f | 1207.61 ms | 1235.90 ms | 28.29 ms |
| 650d802 | 1231.86 ms | 1255.64 ms | 23.78 ms |
| 8ea5293 | 1242.70 ms | 1262.25 ms | 19.55 ms |
| e58d7bf | 1219.98 ms | 1242.39 ms | 22.41 ms |
| 4558de2 | 1225.29 ms | 1258.35 ms | 33.06 ms |
| 32f2329 | 1224.36 ms | 1257.33 ms | 32.98 ms |
| 0f410ad | 1193.34 ms | 1255.49 ms | 62.15 ms |
| 4be5cd8 | 1222.35 ms | 1251.43 ms | 29.07 ms |
| 018037b | 1209.31 ms | 1228.33 ms | 19.03 ms |
| 5aa3ce5 | 1222.78 ms | 1245.39 ms | 22.61 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 35c962f | 23.75 KiB | 854.77 KiB | 831.02 KiB |
| 650d802 | 23.74 KiB | 913.13 KiB | 889.39 KiB |
| 8ea5293 | 23.75 KiB | 852.24 KiB | 828.49 KiB |
| e58d7bf | 24.15 KiB | 1.01 MiB | 1014.91 KiB |
| 4558de2 | 24.14 KiB | 1.03 MiB | 1.00 MiB |
| 32f2329 | 23.75 KiB | 1.01 MiB | 1016.02 KiB |
| 0f410ad | 24.14 KiB | 1.01 MiB | 1014.82 KiB |
| 4be5cd8 | 23.75 KiB | 980.80 KiB | 957.06 KiB |
| 018037b | 23.75 KiB | 867.16 KiB | 843.41 KiB |
| 5aa3ce5 | 23.75 KiB | 904.54 KiB | 880.79 KiB |
Previous results on branch: philprime/attributable
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0862059 | 1209.10 ms | 1235.65 ms | 26.55 ms |
| cdbc520 | 1210.64 ms | 1248.77 ms | 38.13 ms |
| 76e0378 | 1220.62 ms | 1250.33 ms | 29.70 ms |
| c0e1291 | 1221.29 ms | 1240.65 ms | 19.36 ms |
| 447a784 | 1230.52 ms | 1256.10 ms | 25.58 ms |
| 4ef1623 | 1213.43 ms | 1240.73 ms | 27.30 ms |
| c0e1291 | 1227.94 ms | 1249.06 ms | 21.12 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 0862059 | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| cdbc520 | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| 76e0378 | 24.14 KiB | 1.04 MiB | 1.01 MiB |
| c0e1291 | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| 447a784 | 24.14 KiB | 1.04 MiB | 1.02 MiB |
| 4ef1623 | 24.14 KiB | 1.04 MiB | 1.01 MiB |
| c0e1291 | 24.14 KiB | 1.04 MiB | 1.02 MiB |
|
Array handling is incomplete, moved back to draft |
… corresponding unit tests
philipphofmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like that we're adding type safety to the attributes with this PR. I think we need some slight tweaking for the public logging API to better communicate which types our users can use, such as:
public func warn(_ message: SentryLogMessage, attributes: [String: SentryAttributeValuable] = [:])
…add corresponding unit test
philipphofmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with a few comments. Thanks.
philipphofmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks again.
…perty conversions Extract attributesDict once before applying all attribute modifications, then set it back once at the end. This reduces dictionary conversions from 14 (7 getters + 7 setters) to 2 (1 get + 1 set) when applying scope attributes to batcher items, improving performance especially under high-volume logging scenarios.
📜 Description
This PR introduces a protocol-based system for typed attribute values to improve type safety when working with structured logging attributes. The changes add:
SentryAttributeValuethat represents attribute values (string, boolean, integer, double, and their array variants)SentryAttributeValuablethat allows types to convert themselves toSentryAttributeValueString,Bool,Int,Double, andFloatto conform toSentryAttributeValuableThis change refactors the Objective-C compatible
SentryAttributeto use the Swift enumSentryAttributeValueas its backing type. It also updatesBatcherScopeto useSentryAttributeValuedirectly instead ofSentryAttributeobjects.This PR also introduces support for Array attribute types as defined in the documentation.
Changes in Public API:
The currently proposed changes contain new public API endpoints for the
SentryLoggerto accept[String: SentryAttributeValuable]instead of[String: Any]for improved type safety. I acknowledge this is a breaking change, therefore I am open to remove it until the next major version.If we keep it it could cause ambiguity issues because we have to method signatures both with the same parameters, only having different Dictionary types as the attributes.
The main use case are the new methods introduced by Metrics in #6957
💡 Motivation and Context
Previously, attributes were stored as
[String: Any]dictionaries, which provided no compile-time type safety. This made it easy to accidentally pass unsupported types or incorrect values, which are converted toStringas a fallback, sending unpredictable data. By introducing a protocol-based system withSentryAttributeValuable, we can:SentryAttributeobjects (using thExpressibleBy...protocol extensions)SentryAttributeclass still exists and can convert fromSentryAttributeValuefor Objective-C interop.I also need this change to implement #6957.
💚 How did you test it?
BatcherScopeTests,BatcherTests, andSentryLoggerTeststo use the new typed attribute system📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.