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

Add new function to set user within Sentry #119

Merged
merged 3 commits into from
Dec 16, 2024
Merged

Conversation

fpena
Copy link
Contributor

@fpena fpena commented Dec 13, 2024

Description

This PR adds a new public function to set a user object within Sentry.

@fpena fpena marked this pull request as ready for review December 13, 2024 18:01
@fpena fpena requested a review from nbrooke December 13, 2024 18:01
Copy link
Contributor

@brendanlensink brendanlensink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might make more sense to bundle this user id within the SentryConfig class, since it seems to only be used for Sentry, does that make sense?

@fpena
Copy link
Contributor Author

fpena commented Dec 16, 2024

I think it might make more sense to bundle this user id within the SentryConfig class, since it seems to only be used for Sentry, does that make sense?

Thanks for the feedback @brendanlensink.

The reason I didn't do it like that is because setting a user (whether if we're passing a valid string or nil) is something you might want to run at least twice in an app. For example, after logging in and after logging out.

SentryConfig is a struct that gets passed when the Steamclog is initialized and happens only once.

Let me know if my thinking makes sense!

@@ -10,6 +10,14 @@ import Foundation
import Sentry
import XCGLogger

public struct SteamcLogUser {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple overlapping things I don't like about this:

  • Don't love prefixing classes with the name of the module, if this is gonna exist it should just be called "User" or "UserInfo" or something.
  • A structure just to hold the one string to call one API and that is never stored seems like overkill. Seems like we could just have the API be setUser(userId: String?). I can sort of see the argument for having a container type IF there were a bunch of extra properties in there we were using, but just having one string to ID the user seems fine for the foreseeable future, and it's easy to add a container type later (and just have the single string API become a convenience wrapper) if we do ever want to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nbrooke feedback addressed.

@nbrooke nbrooke removed their assignment Dec 16, 2024
@nbrooke
Copy link
Member

nbrooke commented Dec 16, 2024

Setting the user being a separate API rather than part of the config does make sense to me, for the reasons @fpena mentions. Even though it is Sentry specific now, it probably shouldn't be. Like in a case were were are using a different log destination that could support it (like Rollbar, which likely has an equivalent thing) the user should ALSO be passed through to that. Like ideally this should be something like:

public func setUser(userId: String?) {
    for destination in allDestinations {
        destination.setUser(userId: userId)
    } 
}

With setUser on the SentryDestination then having the current implementation.

I don't think there's really a good way to do that right now (because the protocols for log destinations are just inherited from XCGLogger), so it's probably not worth addressing just to get this working for right now, but maybe we should file a bug to generalize this at some point.

@brendanlensink
Copy link
Contributor

Follow-up ticket filed here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants