-
-
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,12 @@ import 'dart:async'; | |
|
|
||
| import 'package:meta/meta.dart'; | ||
| import 'package:sentry/sentry.dart'; | ||
| import 'package:sentry/src/transport/noop_transport.dart'; | ||
|
|
||
| import 'client_stub.dart' | ||
| if (dart.library.html) 'browser_client.dart' | ||
| if (dart.library.io) 'io_client.dart'; | ||
| import 'protocol.dart'; | ||
| import 'transport/transport.dart'; | ||
|
|
||
| /// Logs crash reports and events to the Sentry.io service. | ||
| abstract class SentryClient { | ||
|
|
@@ -17,13 +17,19 @@ abstract class SentryClient { | |
| /// `dart:html` is available, otherwise it will throw an unsupported error. | ||
| factory SentryClient(SentryOptions options) => createSentryClient(options); | ||
|
|
||
| SentryClient.base(this.options, {@required this.transport}); | ||
| SentryClient.base(this.options, {String origin}) { | ||
| if (options.transport is NoOpTransport) { | ||
| options.transport = Transport( | ||
| options: options, | ||
| sdkIdentifier: '${sdkName}/${sdkVersion}', | ||
| origin: origin, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| @protected | ||
| SentryOptions options; | ||
|
|
||
| @visibleForTesting | ||
| final Transport transport; | ||
| SentryOptions options; | ||
|
||
|
|
||
| /// Information about the current user. | ||
| /// | ||
|
|
@@ -47,9 +53,9 @@ abstract class SentryClient { | |
|
|
||
| event = _applyScope(event: event, scope: scope); | ||
|
|
||
| event = event.copyWith(platform: transport.platform); | ||
| event = event.copyWith(platform: sdkPlatform); | ||
|
|
||
| return transport.send(event); | ||
| return options.transport.send(event); | ||
| } | ||
|
|
||
| /// Reports the [throwable] and optionally its [stackTrace] to Sentry.io. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import 'package:http/http.dart'; | ||
| import 'package:sentry/sentry.dart'; | ||
| import 'package:sentry/src/transport/noop_transport.dart'; | ||
|
|
||
| import 'diagnostic_logger.dart'; | ||
| import 'hub.dart'; | ||
| import 'protocol.dart'; | ||
|
|
@@ -118,7 +120,14 @@ class SentryOptions { | |
|
|
||
| List<String> get inAppIncludes => List.unmodifiable(_inAppIncludes); | ||
|
|
||
| // TODO: transport, transportGate, connectionTimeoutMillis, readTimeoutMillis, hostnameVerifier, sslSocketFactory, proxy | ||
| Transport _transport = NoOpTransport(); | ||
|
|
||
| Transport get transport => _transport; | ||
|
|
||
| set transport(Transport transport) => | ||
| _transport = transport ?? NoOpTransport(); | ||
|
|
||
| // TODO: transportGate, connectionTimeoutMillis, readTimeoutMillis, hostnameVerifier, sslSocketFactory, proxy | ||
|
|
||
| /// Sets the distribution. Think about it together with release and environment | ||
| String dist; | ||
|
|
@@ -139,8 +148,9 @@ class SentryOptions { | |
| this.environmentAttributes, | ||
| this.compressPayload, | ||
| this.httpClient, | ||
| Transport transport, | ||
| ClockProvider clock = getUtcDateTime, | ||
| }) { | ||
| }) : _transport = transport ?? NoOpTransport() { | ||
|
||
| _clock = clock; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:sentry/sentry.dart'; | ||
|
|
||
| class NoOpTransport implements Transport { | ||
| @override | ||
| Dsn get dsn => null; | ||
|
|
||
| @override | ||
| String get origin => null; | ||
|
|
||
| @override | ||
| String get sdkIdentifier => null; | ||
|
||
|
|
||
| @override | ||
| Future<SentryId> send(SentryEvent event) => Future.value(SentryId.empty()); | ||
| } | ||
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.
could this be replaced by
options.sdkVersion.identifier? it looks duplicated nowThere 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.
✅ my bad, I thought
sdkVersionwas just a String, I renamed itsdk, and define it in the ioClient & BrowserClient if null