-
-
Notifications
You must be signed in to change notification settings - Fork 358
refactor(android,ios): Use native SDK deserializers for User and Breadcrumb #6261
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
Changes from all commits
6e6a716
39a406a
dacf009
dbec145
fddf6f8
73f4db2
3c1fc9d
d8dfaa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,6 @@ | |
| import io.sentry.android.core.performance.AppStartMetrics; | ||
| import io.sentry.profilemeasurements.ProfileMeasurement; | ||
| import io.sentry.profilemeasurements.ProfileMeasurementValue; | ||
| import io.sentry.protocol.Geo; | ||
| import io.sentry.protocol.SdkVersion; | ||
| import io.sentry.protocol.SentryId; | ||
| import io.sentry.protocol.User; | ||
|
|
@@ -62,6 +61,7 @@ | |
| import io.sentry.util.FileUtils; | ||
| import io.sentry.util.JsonSerializationUtils; | ||
| import io.sentry.util.LoadClass; | ||
| import io.sentry.util.MapObjectReader; | ||
| import io.sentry.vendor.Base64; | ||
| import java.io.BufferedInputStream; | ||
| import java.io.BufferedReader; | ||
|
|
@@ -575,68 +575,43 @@ public void setUser(final ReadableMap userKeys, final ReadableMap userDataKeys) | |
| if (userKeys == null && userDataKeys == null) { | ||
| scope.setUser(null); | ||
| } else { | ||
| User userInstance = new User(); | ||
|
|
||
| if (userKeys != null) { | ||
| if (userKeys.hasKey("email")) { | ||
| userInstance.setEmail(userKeys.getString("email")); | ||
| } | ||
|
|
||
| if (userKeys.hasKey("id")) { | ||
| userInstance.setId(userKeys.getString("id")); | ||
| } | ||
|
|
||
| if (userKeys.hasKey("username")) { | ||
| userInstance.setUsername(userKeys.getString("username")); | ||
| } | ||
|
|
||
| if (userKeys.hasKey("ip_address")) { | ||
| userInstance.setIpAddress(userKeys.getString("ip_address")); | ||
| } | ||
|
|
||
| if (userKeys.hasKey("geo")) { | ||
| ReadableMap geoMap = userKeys.getMap("geo"); | ||
| if (geoMap != null) { | ||
| Geo geoData = new Geo(); | ||
| if (geoMap.hasKey("city")) { | ||
| geoData.setCity(geoMap.getString("city")); | ||
| } | ||
| if (geoMap.hasKey("country_code")) { | ||
| geoData.setCountryCode(geoMap.getString("country_code")); | ||
| try { | ||
| final MapObjectReader reader = | ||
| new MapObjectReader( | ||
| userKeys != null | ||
| ? RNSentryBreadcrumb.toDeepHashMap(userKeys) | ||
| : new HashMap<>()); | ||
| final User userInstance = new User.Deserializer().deserialize(reader, logger); | ||
|
|
||
| if (userDataKeys != null) { | ||
| Map<String, String> userDataMap = new HashMap<>(); | ||
| ReadableMapKeySetIterator it = userDataKeys.keySetIterator(); | ||
| while (it.hasNextKey()) { | ||
| String key = it.nextKey(); | ||
| String value = userDataKeys.getString(key); | ||
|
|
||
| // other is ConcurrentHashMap and can't have null values | ||
| if (value != null) { | ||
| userDataMap.put(key, value); | ||
| } | ||
| if (geoMap.hasKey("region")) { | ||
| geoData.setRegion(geoMap.getString("region")); | ||
| } | ||
| userInstance.setGeo(geoData); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (userDataKeys != null) { | ||
| Map<String, String> userDataMap = new HashMap<>(); | ||
| ReadableMapKeySetIterator it = userDataKeys.keySetIterator(); | ||
| while (it.hasNextKey()) { | ||
| String key = it.nextKey(); | ||
| String value = userDataKeys.getString(key); | ||
|
|
||
| // other is ConcurrentHashMap and can't have null values | ||
| if (value != null) { | ||
| userDataMap.put(key, value); | ||
| } | ||
| userInstance.setData(userDataMap); | ||
| } | ||
|
|
||
|
antonis marked this conversation as resolved.
|
||
| userInstance.setData(userDataMap); | ||
| scope.setUser(userInstance); | ||
| } catch (Exception e) { | ||
| logger.log(SentryLevel.ERROR, "Failed to deserialize user from map.", e); | ||
| scope.setUser(null); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. userData error clears scope userMedium Severity The new Reviewed by Cursor Bugbot for commit d8dfaa8. Configure here. |
||
| } | ||
|
|
||
| scope.setUser(userInstance); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public void addBreadcrumb(final ReadableMap breadcrumb) { | ||
| Sentry.configureScope( | ||
| scope -> { | ||
| scope.addBreadcrumb(RNSentryBreadcrumb.fromMap(breadcrumb)); | ||
| scope.addBreadcrumb(RNSentryBreadcrumb.fromMap(breadcrumb, logger)); | ||
|
|
||
| final @Nullable String screen = RNSentryBreadcrumb.getCurrentScreenFrom(breadcrumb); | ||
| if (screen != null) { | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.