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

Feat : add a Hub class #113

Merged
merged 27 commits into from
Oct 19, 2020
Merged

Feat : add a Hub class #113

merged 27 commits into from
Oct 19, 2020

Conversation

rxlabz
Copy link
Contributor

@rxlabz rxlabz commented Oct 15, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

💡 Motivation and Context

💚 How did you test it?

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • All tests passing
  • No breaking changes

🔮 Next steps

@rxlabz rxlabz changed the base branch from main to feature/unified-api October 15, 2020 15:11
@rxlabz
Copy link
Contributor Author

rxlabz commented Oct 15, 2020

@marandaneto @bruno-garcia Hi, I started this PR, early feedbacks are welcome :)

Comment on lines 100 to 101
dynamic throwable,
dynamic stackTrace,
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we using dynamic? should we not use the types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no type union in Dart, and both Error and Exception are throwable, and not related. In fact you can throw anything in Dart ( but null which throws NullThrownError ).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, well making it dynamic works but if it could be literally anything, how we would know which fields to read the info out of the exception, stack trace, messages and so on, we'd need to think this thru, if its the case, we could offer overloads like
captureException(exception type)
captureError(error type)
capture??(any?)

I am just thinking out loud here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no common interface for Dart Errors

if (exception != null) {
      json['exception'] = [
        <String, dynamic>{
          'type': '${exception.runtimeType}',
          'value': '$exception',
        }
      ];
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

I see but an Error has a stack trace field https://api.dart.dev/stable/2.10.2/dart-core/Error/stackTrace.html

Copy link
Contributor

Choose a reason for hiding this comment

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

stackTrace could be read in SentryClient from the throwable if its an error and not taken as params in the Sentry static class/Hub

Copy link
Contributor Author

@rxlabz rxlabz Oct 19, 2020

Choose a reason for hiding this comment

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

I found the reason why Dart exceptions have no stacktrace : https://groups.google.com/a/dartlang.org/g/misc/c/O1OKnYTUcoo/m/ipIE1jqHD9sJ
I think the current implementation allows to send both :

  • an exception and it's stacktrace if the user catch it and want to send it,
  • and an error with the stacktrace automatically serialized
    Is it ok for you @marandaneto ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, sounds good, but then stacktrace should not be mandatory right?
also, if the error has a stacktrace and the user still passed a stacktrace, which one wins? we need to think about that, but it doesn't need to be in this PR then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only the throwable is a required argument :

Future<SentryId> captureException(
    dynamic throwable, {
    dynamic stackTrace,
  })

for the if a stacktrace is passed with an error, it will override the error.stacktrace

Copy link
Contributor

@marandaneto marandaneto Oct 19, 2020

Choose a reason for hiding this comment

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

perfect, we'd need to mention this in the docs later.

- feedbacks : remove the IHub interface
- client.captureEvent define event as a required param
- pass the scope to client.captureEvent(...)
Comment on lines 142 to 164
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Scope &&
runtimeType == other.runtimeType &&
_level == other.level &&
_transaction == other.transaction &&
_user == other.user &&
IterableEquality().equals(_fingerprint, other.fingerprint) &&
IterableEquality().equals(_breadcrumbs, other.breadcrumbs) &&
MapEquality().equals(_tags, other.tags) &&
MapEquality().equals(_extra, other.extra);

@override
int get hashCode =>
_level.hashCode ^
_transaction.hashCode ^
_user.hashCode ^
_fingerprint.hashCode ^
_breadcrumbs.hashCode ^
_tags.hashCode ^
_extra.hashCode ^
_options.hashCode;
Copy link
Contributor

Choose a reason for hiding this comment

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

mm why do we need 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.

to test scopes equality in tests.

Copy link
Member

Choose a reason for hiding this comment

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

Could we move this code to the tests instead? I'd avoid having this here if we don't need to maintain as production code (like putting scopes in as Map keys)

Copy link
Contributor Author

@rxlabz rxlabz Oct 16, 2020

Choose a reason for hiding this comment

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

I'm not sure I can without changing this kind of tests :

test('should capture event', () {
      hub.captureEvent(fakeEvent);
      verify(
        client.captureEvent(fakeEvent, scope: Scope(options), stackFrameFilter: null),
      ).called(1);
    });

If we don't override the ==operator the test will fail as it will only compare scope reference.
To remove the need of this override, I could change the test to :

test('should capture event', () {
      hub.captureEvent(fakeEvent);
      verify(
        client.captureEvent(fakeEvent,scope: anyNamed('scope'), stackFrameFilter: null),
      ).called(1);
    });

but it less precise. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Based on the name of the tests, we're not really asserting anything about the scope, is that right? We just test that an event was captured?

For a test that requires validating equality of the argument, is there a arg validator that takes a callback?
like:

arg.is(s => s.a == expected.a) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the "dartiest" way ! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but needs Dart >=2.6 :(

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd also prefer to keep this type of code needed only for tests, on the test packages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ moved in the test side, as a simple method for now
We should decide if we update the SDK constraints to use extensions and other "modern dart" features :)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

I know it's a draft but I left a couple notes, I hope it helps

Comment on lines 142 to 164
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Scope &&
runtimeType == other.runtimeType &&
_level == other.level &&
_transaction == other.transaction &&
_user == other.user &&
IterableEquality().equals(_fingerprint, other.fingerprint) &&
IterableEquality().equals(_breadcrumbs, other.breadcrumbs) &&
MapEquality().equals(_tags, other.tags) &&
MapEquality().equals(_extra, other.extra);

@override
int get hashCode =>
_level.hashCode ^
_transaction.hashCode ^
_user.hashCode ^
_fingerprint.hashCode ^
_breadcrumbs.hashCode ^
_tags.hashCode ^
_extra.hashCode ^
_options.hashCode;
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this code to the tests instead? I'd avoid having this here if we don't need to maintain as production code (like putting scopes in as Map keys)

- override SentryId.toString
- typos
- add a scope comparaison method in tests
- move pkg:collection to dev_depencies
- changelog
- add template and params named params to captureMessage
- update the Message class constructor
@rxlabz rxlabz marked this pull request as ready for review October 19, 2020 10:40
@marandaneto marandaneto merged commit d577e35 into feature/unified-api Oct 19, 2020
@marandaneto marandaneto deleted the feat/hub branch October 19, 2020 11:19
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