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

Support user context #17

Merged
merged 11 commits into from
May 15, 2018
Merged

Conversation

dustin-graham
Copy link
Contributor

allow the client app to specify a user context for logging events and exceptions to sentry.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@dustin-graham
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@dustin-graham
Copy link
Contributor Author

@yjbanov it's failing on the GZIP warning. in local testing with my own app I found that when I upgraded this package to use gzip instead, it failed at runtime in Flutter because it couldn't be found. seems like a Dart version mismatch maybe, but that's why it's failing Travis right now.

@dustin-graham
Copy link
Contributor Author

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I most have nitpicks. Design-wise, I'm only curious about making userContext mutable.

lib/sentry.dart Outdated
@visibleForTesting
User _userContext;

set userContext(User val) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We require dartdocs for all public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/sentry.dart Outdated
@@ -143,6 +143,13 @@ class SentryClient {
/// Attached to the event payload.
final String projectId;

@visibleForTesting
User _userContext;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why opt for a mutable field rather than a final one, like all others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/sentry.dart Outdated
@@ -330,6 +342,8 @@ class Event {
/// they must be JSON-serializable.
final Map<String, dynamic> extra;

final User userContext;
Copy link
Contributor

Choose a reason for hiding this comment

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

dartdocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/sentry.dart Outdated
/// "email": "[email protected]",
/// "ip_address": "127.0.0.1",
/// "subscription": "basic"
///}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit1: add one space after the ///
nit2: code snippets in dartdocs must be wrapped in triple-backticks, just like on GitHub.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/sentry.dart Outdated
final String username;
final String email;
final String ipAddress;
final String subscription;
Copy link
Contributor

Choose a reason for hiding this comment

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

dartdocs for all public fields. Ideally, link to the docs on sentry.io.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lib/sentry.dart Outdated
final String ipAddress;
final String subscription;

const User(this.id, this.username, this.email, this.ipAddress, this.subscription);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Add dartdocs
  • Use named constructor parameters, like the Event class
  • I imagine some of these parameters must be non-null. If so, let's add assertions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

none of them are non-null. The docs say that you must have at least an ID OR an IP Address set. but that is up to the client app to enforce which they want. adding an assert to inform the developer during debug that there might be an issue.

lib/sentry.dart Outdated

const User(this.id, this.username, this.email, this.ipAddress, this.subscription);

Map<String, String> toJson() {
Copy link
Contributor

Choose a reason for hiding this comment

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

dartdocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@dustin-graham
Copy link
Contributor Author

@yjbanov Thanks for the review. I'll push an update tomorrow with those fixes. About the mutable userContext. For my application some of the data for the User is not known until later on at runtime after the user has logged in and done some other things. Allowing the client application to change the user context at any time allows for this flexibility without having to go make a new SentryClient. In one of my commits I had it the other way, where the user passes in the userContext as part of the initial Event environment, but I quickly found that that didn't work for me as the data for the context is only known after login and perhaps further initialization. I did leave in the ability to override the base userContext when sending individual events in case this needs to be overridden for some reason. I could also see removing the userContext from the SentryClient entirely and just make adding in user data an exercise for the user each time they log. But this would likely be burdensome on the client.

@yjbanov
Copy link
Contributor

yjbanov commented May 15, 2018

Ok, I think it makes sense. I suppose in some apps you can switch users dynamically too. So let's keep it mutable. Why don't we just make it a mutable field then? The Dart style guide discourages setters without getters.

@yjbanov
Copy link
Contributor

yjbanov commented May 15, 2018

Please ping this PR again when you have the changes finalized and I'll look into the GZIP issue. Recently the Dart standard libraries deprecated ALL_CAPS constant names in favor of camelCase.

@dustin-graham
Copy link
Contributor Author

@yjbanov I believe I have addressed all the feedback and Travis is now passing.

'sentry_timestamp=${fakeClock.now().millisecondsSinceEpoch}, '
'sentry_timestamp=${fakeClock
.now()
.millisecondsSinceEpoch}, '
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, did dartfmt do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it did. it appears that the travis rule runs dartfmt and fails if there is anything changed after running it. so after I ran dartfmt locally and uploaded it now passes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should file a bug.

@yjbanov
Copy link
Contributor

yjbanov commented May 15, 2018

lgtm

Can I merge this? I'll also do a release.

@dustin-graham
Copy link
Contributor Author

@yjbanov yes, let's merge and release! thank you.

@yjbanov yjbanov merged commit 78ef3f7 into getsentry:master May 15, 2018
@yjbanov
Copy link
Contributor

yjbanov commented May 15, 2018

Thank you!

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