Skip to content

Commit 99864ad

Browse files
authored
Set User name and geo in native plugins (#1393)
1 parent d69dd86 commit 99864ad

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Set User `name` and `geo` in native plugins ([#1393](https://github.com/getsentry/sentry-dart/pull/1393))
8+
59
### Fixes
610

711
- Do not report only async gap frames for logging calls ([#1398](https://github.com/getsentry/sentry-dart/pull/1398))

flutter/android/src/main/kotlin/io/sentry/flutter/SentryFlutterPlugin.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import io.sentry.protocol.DebugImage
2626
import io.sentry.protocol.SdkVersion
2727
import io.sentry.protocol.SentryId
2828
import io.sentry.protocol.User
29+
import io.sentry.protocol.Geo
2930
import java.io.File
3031
import java.lang.ref.WeakReference
3132
import java.util.Locale
@@ -296,12 +297,14 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
296297
(user["username"] as? String)?.let { userInstance.username = it }
297298
(user["ip_address"] as? String)?.let { userInstance.ipAddress = it }
298299
(user["segment"] as? String)?.let { userInstance.segment = it }
299-
300-
// Not mapped on Android yet, added to the unknown databag that gets serialized correctly anyway
301-
// Should be solved by https://github.com/getsentry/team-mobile/issues/59
302-
// or https://github.com/getsentry/team-mobile/issues/56
303-
(user["name"] as? String)?.let { unknown["name"] = it }
304-
(user["geo"] as? Map<String, Any?>)?.let { unknown["geo"] = it }
300+
(user["name"] as? String)?.let { userInstance.name = it }
301+
(user["geo"] as? Map<String, Any?>)?.let {
302+
val geo = Geo()
303+
geo.city = it["city"] as? String
304+
geo.countryCode = it["country_code"] as? String
305+
geo.region = it["region"] as? String
306+
userInstance.geo = geo
307+
}
305308

306309
(user["extras"] as? Map<String, Any?>)?.let { extras ->
307310
for ((key, value) in extras.entries) {

flutter/ios/Classes/SentryFlutterPluginApple.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
534534
}
535535
}
536536

537+
// swiftlint:disable:next cyclomatic_complexity
537538
private func setUser(user: [String: Any?]?, result: @escaping FlutterResult) {
538539
if let user = user {
539540
let userInstance = User()
@@ -563,10 +564,16 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
563564
userInstance.data = data
564565
}
565566
}
566-
567-
// missing name and geo
568-
// Should be solved by https://github.com/getsentry/team-mobile/issues/59
569-
// or https://github.com/getsentry/team-mobile/issues/56
567+
if let name = user["name"] as? String {
568+
userInstance.name = name
569+
}
570+
if let geoData = user["geo"] as? [String: Any] {
571+
let geo = Geo()
572+
geo.city = geoData["city"] as? String
573+
geo.countryCode = geoData["country_code"] as? String
574+
geo.region = geoData["region"] as? String
575+
userInstance.geo = geo
576+
}
570577

571578
SentrySDK.setUser(userInstance)
572579
} else {

0 commit comments

Comments
 (0)