Skip to content

Set User name and geo in native plugins #1393

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
merged 5 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Features

- Set User `name` and `geo` in native plugins ([#1393](https://github.com/getsentry/sentry-dart/pull/1393))

## 7.4.2

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import io.sentry.protocol.DebugImage
import io.sentry.protocol.SdkVersion
import io.sentry.protocol.SentryId
import io.sentry.protocol.User
import io.sentry.protocol.Geo
import java.io.File
import java.lang.ref.WeakReference
import java.util.Locale
Expand Down Expand Up @@ -296,12 +297,14 @@ class SentryFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
(user["username"] as? String)?.let { userInstance.username = it }
(user["ip_address"] as? String)?.let { userInstance.ipAddress = it }
(user["segment"] as? String)?.let { userInstance.segment = it }

// Not mapped on Android yet, added to the unknown databag that gets serialized correctly anyway
// Should be solved by https://github.com/getsentry/team-mobile/issues/59
// or https://github.com/getsentry/team-mobile/issues/56
(user["name"] as? String)?.let { unknown["name"] = it }
(user["geo"] as? Map<String, Any?>)?.let { unknown["geo"] = it }
(user["name"] as? String)?.let { userInstance.name = it }
(user["geo"] as? Map<String, Any?>)?.let {
val geo = Geo()
geo.city = it["city"] as? String
geo.countryCode = it["country_code"] as? String
geo.region = it["region"] as? String
userInstance.geo = geo
}

(user["extras"] as? Map<String, Any?>)?.let { extras ->
for ((key, value) in extras.entries) {
Expand Down
15 changes: 11 additions & 4 deletions flutter/ios/Classes/SentryFlutterPluginApple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
}
}

// swiftlint:disable:next cyclomatic_complexity
private func setUser(user: [String: Any?]?, result: @escaping FlutterResult) {
if let user = user {
let userInstance = User()
Expand Down Expand Up @@ -563,10 +564,16 @@ public class SentryFlutterPluginApple: NSObject, FlutterPlugin {
userInstance.data = data
}
}

// missing name and geo
// Should be solved by https://github.com/getsentry/team-mobile/issues/59
// or https://github.com/getsentry/team-mobile/issues/56
if let name = user["name"] as? String {
userInstance.name = name
}
if let geoData = user["geo"] as? [String: Any] {
let geo = Geo()
geo.city = geoData["city"] as? String
geo.countryCode = geoData["country_code"] as? String
geo.region = geoData["region"] as? String
userInstance.geo = geo
}

SentrySDK.setUser(userInstance)
} else {
Expand Down