-
-
Notifications
You must be signed in to change notification settings - Fork 277
Refacto : add a Transport class #123
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
Changes from 1 commit
a10d740
623c904
0dcb613
c97c98b
477fdac
b8fb322
fd92e3f
0944c68
46829fc
01d4e19
fbd001e
4d39531
34fb528
2437fa4
57798f5
789e154
1aa05d6
9895142
cb5e309
e563d2c
71b53c8
be3f0a2
43b798c
19dc91d
cec1f21
909d4f9
8b600dc
4ff58a6
5493e19
621d6c4
e11f653
88526e2
796b633
fb8b9e0
1dbcba4
8b56bce
daeb29e
098d58c
2833a94
35671d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
+ move origin to Transport
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,7 +54,7 @@ class SentryBrowserClient extends SentryClient { | |
| sdk: Sdk(name: browserSdkName, version: sdkVersion), | ||
| headersBuilder: SentryClient.buildHeaders, | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| platform: platform, | ||
|
||
| origin: origin, | ||
| ), | ||
| origin: origin, | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ abstract class SentryClient { | |
|
|
||
| SentryClient.base( | ||
| this.options, { | ||
| this.origin, | ||
| @required this.transport, | ||
| }); | ||
|
|
||
|
|
@@ -43,9 +42,6 @@ abstract class SentryClient { | |
| /// * https://docs.sentry.io/learn/context/#capturing-the-user | ||
| User userContext; | ||
|
||
|
|
||
| /// Use for browser stacktrace | ||
| String origin; | ||
|
|
||
| /// Reports an [event] to Sentry.io. | ||
| Future<SentryId> captureEvent( | ||
| SentryEvent event, { | ||
|
|
@@ -54,6 +50,8 @@ abstract class SentryClient { | |
| }) async { | ||
| event = _processEvent(event, eventProcessors: options.eventProcessors); | ||
|
|
||
| event = _applyScope(event: event, scope: scope); | ||
|
|
||
| final data = <String, dynamic>{ | ||
| 'event_id': event.eventId.toString(), | ||
| }; | ||
|
|
@@ -62,16 +60,10 @@ abstract class SentryClient { | |
| mergeAttributes(options.environmentAttributes.toJson(), into: data); | ||
| } | ||
|
|
||
| // Merge the user context. | ||
| if (userContext != null) { | ||
| mergeAttributes(<String, dynamic>{'user': userContext.toJson()}, | ||
| into: data); | ||
| } | ||
|
|
||
| mergeAttributes( | ||
| event.toJson( | ||
| stackFrameFilter: stackFrameFilter, | ||
| origin: origin, | ||
| origin: transport.origin, | ||
| ), | ||
| into: data, | ||
| ); | ||
|
|
@@ -128,6 +120,46 @@ abstract class SentryClient { | |
| return event; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still missing the execution of the beforeSendCallback -> |
||
| } | ||
|
|
||
| Event _applyScope({@required Event event, @required Scope scope}) { | ||
| if (scope != null) { | ||
| // Merge the scope transaction. | ||
| if (event.transaction == null) { | ||
| event = event.copyWith(transaction: scope.transaction); | ||
| } | ||
|
|
||
| // Merge the user context. | ||
| if (event.userContext == null) { | ||
| event = event.copyWith(userContext: scope.user); | ||
| } | ||
|
|
||
| // Merge the scope fingerprint. | ||
| if (event.fingerprint == null) { | ||
| event = event.copyWith(fingerprint: scope.fingerprint); | ||
| } | ||
|
|
||
| // Merge the scope breadcrumbs. | ||
| if (event.breadcrumbs == null) { | ||
| event = event.copyWith(breadcrumbs: scope.breadcrumbs); | ||
| } | ||
|
|
||
| // Merge the scope tags. | ||
| if (event.tags == null) { | ||
| event = event.copyWith(tags: scope.tags); | ||
| } | ||
|
|
||
| // Merge the scope extra. | ||
| if (event.extra == null) { | ||
| event = event.copyWith(extra: scope.extra); | ||
| } | ||
|
|
||
| // Merge the scope level. | ||
| if (event.level == null) { | ||
| event = event.copyWith(level: scope.level); | ||
| } | ||
|
||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some fields, we actually append items from the Scope to the event, see:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ fixed |
||
| return event; | ||
| } | ||
|
|
||
| @override | ||
| String toString() => '$SentryClient("${options.dsn}")'; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,6 @@ class NoOpSentryClient implements SentryClient { | |
| @override | ||
| SentryOptions options; | ||
|
|
||
| @override | ||
| String origin; | ||
|
|
||
| @override | ||
| Transport transport; | ||
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,30 +339,32 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) { | |
| }); | ||
|
|
||
| const clientUserContext = User( | ||
| id: 'client_user', | ||
| username: 'username', | ||
| email: '[email protected]', | ||
| ipAddress: '127.0.0.1'); | ||
| id: 'client_user', | ||
| username: 'username', | ||
| email: '[email protected]', | ||
| ipAddress: '127.0.0.1', | ||
| ); | ||
| const eventUserContext = User( | ||
| id: 'event_user', | ||
| username: 'username', | ||
| email: '[email protected]', | ||
| ipAddress: '127.0.0.1', | ||
| extras: <String, String>{'foo': 'bar'}); | ||
| id: 'event_user', | ||
| username: 'username', | ||
| email: '[email protected]', | ||
| ipAddress: '127.0.0.1', | ||
| extras: <String, String>{'foo': 'bar'}, | ||
| ); | ||
|
|
||
| final client = SentryClient( | ||
| SentryOptions( | ||
| dsn: testDsn, | ||
| httpClient: httpMock, | ||
| clock: fakeClockProvider, | ||
| compressPayload: false, | ||
| environmentAttributes: SentryEvent( | ||
| serverName: 'test.server.com', | ||
| release: '1.2.3', | ||
| environment: 'staging', | ||
| ), | ||
| final options = SentryOptions( | ||
| dsn: testDsn, | ||
| httpClient: httpMock, | ||
| clock: fakeClockProvider, | ||
| compressPayload: false, | ||
| environmentAttributes: SentryEvent( | ||
| serverName: 'test.server.com', | ||
| release: '1.2.3', | ||
| environment: 'staging', | ||
| ), | ||
| ); | ||
|
|
||
| final client = SentryClient(options); | ||
| client.userContext = clientUserContext; | ||
|
|
||
| try { | ||
|
|
@@ -379,9 +381,13 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) { | |
| stackTrace: stackTrace, | ||
| userContext: eventUserContext, | ||
| ); | ||
| await client.captureEvent(eventWithoutContext); | ||
| await client.captureEvent(eventWithoutContext, | ||
| scope: Scope(options)..user = clientUserContext); | ||
| expect(loggedUserId, clientUserContext.id); | ||
| await client.captureEvent(eventWithContext); | ||
| await client.captureEvent( | ||
| eventWithContext, | ||
| scope: Scope(options)..user = clientUserContext, | ||
| ); | ||
| expect(loggedUserId, eventUserContext.id); | ||
| } | ||
|
|
||
|
|
||
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.
options.sdkVersionalready exists, but its probably null, we'd need to find a way to instantiate it based on the platform (dart, flutter or web), but ideally, we just read this field from the options hereThere 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.
on a second thought, shouldn't this be just either:
sentry.dartorsentry.flutter? Given that this is what the user installed at the end?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 we need only the identifier of the client, yes, only a String would be fine.
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.
✅ fixed