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

automatically get username and full user name #4674

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@
value = ""
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "--io.sentry.user.name"
value = ""
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction
Expand Down
22 changes: 18 additions & 4 deletions Samples/iOS-Swift/iOS-Swift/SentrySDKWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ struct SentrySDKWrapper {

let user = User(userId: "1")
user.email = self.env["--io.sentry.user.email"] ?? "[email protected]"
// first check if the username has been overridden in the scheme for testing purposes; then try to use the system username so each person gets an automatic way to easily filter things on the dashboard; then fall back on a hardcoded value if none of these are present
let username = self.env["--io.sentry.user.username"] ?? (self.env["SIMULATOR_HOST_HOME"] as? NSString)?
.lastPathComponent ?? "cocoadev"
user.username = username
user.name = self.env["--io.sentry.user.name"] ?? "cocoa developer"
user.name = userFullName
scope.setUser(user)

if let path = Bundle.main.path(forResource: "Tongariro", ofType: "jpg") {
Expand All @@ -105,6 +102,23 @@ struct SentrySDKWrapper {
}
return scope
}

var userFullName: String {
let name = self.env["--io.sentry.user.name"] ?? NSFullUserName()
guard !name.isEmpty else {
return "cocoa developer"
}
return name
}

var username: String {
let username = self.env["--io.sentry.user.username"] ?? NSUserName()
guard !username.isEmpty else {
return (self.env["SIMULATOR_HOST_HOME"] as? NSString)?
.lastPathComponent ?? "cocoadev"
}
return username
}
}

// MARK: User feedback configuration
Expand Down
Loading