Skip to content

Commit

Permalink
automatically get username and full user name (#4674)
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight authored Jan 8, 2025
1 parent 439fc9f commit 5126088
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
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

0 comments on commit 5126088

Please sign in to comment.