-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Conversation
dart/lib/src/noop_hub.dart
Outdated
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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 {//...}
There was a problem hiding this comment.
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.
|
||
/// 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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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;
dart/lib/src/noop_hub.dart
Outdated
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'; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
Co-authored-by: Erick Ghaumez <[email protected]>
Co-authored-by: Erick Ghaumez <[email protected]>
… into ref/hub-pass-scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
📢 Type of change
📜 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
🔮 Next steps