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

ref: Hub passes the Scope #114

Merged
merged 17 commits into from
Oct 20, 2020
Merged

Conversation

marandaneto
Copy link
Contributor

@marandaneto marandaneto commented Oct 19, 2020

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

ref: Hub passes the Scope

💡 Motivation and Context

Client needs to have the Scope in order to prepare the event.
Also a few other improvements I've found on the way

💚 How did you test it?

tests

📝 Checklist

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

🔮 Next steps

@marandaneto marandaneto marked this pull request as draft October 19, 2020 13:01
@marandaneto marandaneto changed the title ref/hub pass scope ref: Hub passes the Scope Oct 19, 2020
@marandaneto marandaneto changed the base branch from main to feature/unified-api October 19, 2020 13:02
Comment on lines 3 to 7
import 'package:sentry/src/client.dart';
import 'package:sentry/src/hub.dart';
import 'package:sentry/src/protocol/sentry_id.dart';
import 'package:sentry/src/protocol/level.dart';
import 'package:sentry/src/protocol/event.dart';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IDE does the imports like this but feels weird, whats the proper way?

Copy link
Member

Choose a reason for hiding this comment

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

the linter should be pointing us to the right way (flutter analyze). I believe this is the way to go but I can't recall now

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 didnt complain, thats why

Copy link
Contributor

Choose a reason for hiding this comment

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

Normally in Dart, relative imports should be preferred https://fuchsia.dev/fuchsia-src/development/languages/dart/style#do_import_all_files_within_a_package_using_relative_paths
( but I know that the Flutter team doesn't follow all the Dart styleguide :) )
In IntelliJ, the autocompletion often shows both the relative and package: imports. I don't know if VSCode can be configured is this way.
We could also activate this lint https://dart-lang.github.io/linter/lints/prefer_relative_imports.html which seems to not be activated with pedantic to enforce the rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice I created a task for it

@@ -74,7 +75,7 @@ class Hub {
'captureEvent called with null parameter.',
);
} else {
final item = _stack.first;
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureEvent(event, scope: item.scope);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxlabz I noticed that all the methods are sync now because of await

await: You can use the await keyword to get the completed result of an asynchronous expression. The await keyword only works within an async function.

should we aim for sync calls or keep it async?

@bruno-garcia

Copy link
Member

Choose a reason for hiding this comment

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

While we send the envelope to the client/transport to be sent to the network directly, this should be async.
We could make it sync if we, inside the client, pass the envelope to an Isolate. And there we could use async to send it to the network or write to disk.

I'd propose we stick to async for now, user code already expects do await on capture methods, and allows us to interface with the native layer by purely writing an envelope to disk (which is async)

if you're not using async/await on the method body, just remove the keywords and return futureObj;

Copy link
Contributor

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 understand. They are not sync, they return a Future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rxlabz item.client.captureEvent returns a future, but you call this method using await
if you use the await keyboard, means you the future to be completed, so its a sync call, not async.
or I am not understanding the await keyword in Dart, which is also possible

Copy link
Contributor

@rxlabz rxlabz Oct 20, 2020

Choose a reason for hiding this comment

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

await is just a "syntactic sugar", it doesn't change the nature of the code. Maybe https://dart.dev/codelabs/async-await will be clearer than me.
But I noticed that this method is asynchronous when it calls item.client.captureEvent and synchronous if the hub is not enabled or if the event is null, we probably should change the signature to

FutureOr<SentryId> captureEvent(Event event) async {//...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not a big fan because of:

Note: the FutureOr type is interpreted as dynamic in non strong-mode.

but I got it I guess:
await item.client.captureEvent makes a sync call, but the signature of the method
hub.captureEvent is also async so it's fine.

let's keep as it is till we have a concrete implementation of the transport layer, so we'd know what looks better.

@marandaneto marandaneto requested a review from rxlabz October 19, 2020 15:38

/// The ID Sentry.io assigned to the submitted event for future reference.
final String _id;

String get id => _id;
// TODO: should we generate the new UUID here with an empty ctor?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if so, we'd need to import the uuid dependency and make the _id of its type

Copy link
Contributor

Choose a reason for hiding this comment

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

I maybe missed it, but I didn't found a method to generate a Uuid from String in the uuid package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a task for it

@@ -74,7 +75,7 @@ class Hub {
'captureEvent called with null parameter.',
);
} else {
final item = _stack.first;
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureEvent(event, scope: item.scope);
Copy link
Member

Choose a reason for hiding this comment

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

While we send the envelope to the client/transport to be sent to the network directly, this should be async.
We could make it sync if we, inside the client, pass the envelope to an Isolate. And there we could use async to send it to the network or write to disk.

I'd propose we stick to async for now, user code already expects do await on capture methods, and allows us to interface with the native layer by purely writing an envelope to disk (which is async)

if you're not using async/await on the method body, just remove the keywords and return futureObj;

Comment on lines 3 to 7
import 'package:sentry/src/client.dart';
import 'package:sentry/src/hub.dart';
import 'package:sentry/src/protocol/sentry_id.dart';
import 'package:sentry/src/protocol/level.dart';
import 'package:sentry/src/protocol/event.dart';
Copy link
Member

Choose a reason for hiding this comment

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

the linter should be pointing us to the right way (flutter analyze). I believe this is the way to go but I can't recall now

@@ -74,7 +75,7 @@ class Hub {
'captureEvent called with null parameter.',
);
} else {
final item = _stack.first;
final item = _peek();
if (item != null) {
try {
sentryId = await item.client.captureEvent(event, scope: item.scope);
Copy link
Contributor

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 understand. They are not sync, they return a Future


/// The ID Sentry.io assigned to the submitted event for future reference.
final String _id;

String get id => _id;
// TODO: should we generate the new UUID here with an empty ctor?
Copy link
Contributor

Choose a reason for hiding this comment

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

I maybe missed it, but I didn't found a method to generate a Uuid from String in the uuid package

@marandaneto marandaneto marked this pull request as ready for review October 20, 2020 11:28
Copy link
Contributor

@rxlabz rxlabz left a comment

Choose a reason for hiding this comment

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

LGTM

@marandaneto marandaneto merged commit 2b36bec into feature/unified-api Oct 20, 2020
@marandaneto marandaneto deleted the ref/hub-pass-scope branch October 20, 2020 14:18
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