Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix merge conflicts
  • Loading branch information
marandaneto committed Oct 20, 2020
commit 3d989d517585ab7ed1e460d4888ad9d221d65eb6
48 changes: 9 additions & 39 deletions dart/lib/src/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,8 @@ import 'sentry_options.dart';
import 'utils.dart';
import 'version.dart';

SentryClient createSentryClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
}) =>
SentryBrowserClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
httpClient: httpClient,
clock: clock,
);
SentryClient createSentryClient(SentryOptions options) =>
SentryBrowserClient(options);

/// Logs crash reports and events to the Sentry.io service.
class SentryBrowserClient extends SentryClient {
Expand All @@ -46,42 +35,23 @@ class SentryBrowserClient extends SentryClient {
/// This parameter is dynamic to maintain backwards compatibility with
/// previous use of [Clock](https://pub.dartlang.org/documentation/quiver/latest/quiver.time/Clock-class.html)
/// from [`package:quiver`](https://pub.dartlang.org/packages/quiver).
factory SentryBrowserClient({
@required String dsn,
Event environmentAttributes,
Client httpClient,
dynamic clock,
String origin,
}) {
httpClient ??= BrowserClient();
clock ??= getUtcDateTime;
factory SentryBrowserClient(SentryOptions options, {String origin}) {
options.httpClient ??= BrowserClient();
options.clock ??= getUtcDateTime;

// origin is necessary for sentry to resolve stacktrace
origin ??= '${window.location.origin}/';

return SentryBrowserClient._(
httpClient: httpClient,
clock: clock,
environmentAttributes: environmentAttributes,
dsn: dsn,
options,
origin: origin,
platform: browserPlatform,
);
}

SentryBrowserClient._({
Client httpClient,
dynamic clock,
Event environmentAttributes,
String dsn,
String platform,
String origin,
}) : super.base(
httpClient: httpClient,
clock: clock,
environmentAttributes: environmentAttributes,
dsn: dsn,
platform: platform,
SentryBrowserClient._(SentryOptions options, {String origin, String platform})
: super.base(
options,
origin: origin,
sdk: Sdk(name: browserSdkName, version: sdkVersion),
platform: platform,
Expand Down
40 changes: 5 additions & 35 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,14 @@ abstract class SentryClient {
///
/// Creates an `SentryIOClient` if `dart:io` is available and a `SentryBrowserClient` if
/// `dart:html` is available, otherwise it will throw an unsupported error.
factory SentryClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
}) =>
createSentryClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
httpClient: httpClient,
clock: clock,
compressPayload: compressPayload,
);

SentryClient.base({
this.httpClient,
dynamic clock,
String dsn,
this.environmentAttributes,
factory SentryClient(SentryOptions options) => createSentryClient(options);

SentryClient.base(
this.options, {
String platform,
this.origin,
Sdk sdk,
}) : _dsn = Dsn.parse(dsn),
}) : _dsn = Dsn.parse(options.dsn),
_platform = platform ?? sdkPlatform,
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion) {
if (options.clock == null) {
Expand All @@ -56,20 +40,6 @@ abstract class SentryClient {
}
}

@protected
final Client httpClient;

ClockProvider _clock;

/// Contains [Event] attributes that are automatically mixed into all events
/// captured through this client.
///
/// This event is designed to contain static values that do not change from
/// event to event, such as local operating system version, the version of
/// Dart/Flutter SDK, etc. These attributes have lower precedence than those
/// supplied in the even passed to [capture].
final Event environmentAttributes;

final Dsn _dsn;

@protected
Expand Down
10 changes: 2 additions & 8 deletions dart/lib/src/client_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
// found in the LICENSE file.

import 'client.dart';
import 'protocol.dart';
import 'sentry_options.dart';

/// Implemented in `browser_client.dart` and `io_client.dart`.
SentryClient createSentryClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
}) =>
SentryClient createSentryClient(SentryOptions options) =>
throw UnsupportedError(
'Cannot create a client without dart:html or dart:io.');
10 changes: 2 additions & 8 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@ typedef ScopeCallback = void Function(Scope);

/// SDK API contract which combines a client and scope management
class Hub {
static SentryClient _getClient({SentryOptions fromOptions}) {
return SentryClient(
dsn: fromOptions.dsn,
environmentAttributes: fromOptions.environmentAttributes,
compressPayload: fromOptions.compressPayload,
httpClient: fromOptions.httpClient,
clock: fromOptions.clock,
);
static SentryClient _getClient(SentryOptions options) {
return SentryClient(options);
}

final ListQueue<_StackItem> _stack = ListQueue();
Expand Down
58 changes: 4 additions & 54 deletions dart/lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,8 @@ import 'package:sentry/sentry.dart';
import 'client.dart';
import 'protocol.dart';

SentryClient createSentryClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
}) =>
SentryIOClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
compressPayload: compressPayload,
httpClient: httpClient,
clock: clock,
);
SentryClient createSentryClient(SentryOptions options) =>
SentryIOClient(options);

/// Logs crash reports and events to the Sentry.io service.
class SentryIOClient extends SentryClient {
Expand All @@ -48,47 +36,9 @@ class SentryIOClient extends SentryClient {
/// This parameter is dynamic to maintain backwards compatibility with
/// previous use of [Clock](https://pub.dartlang.org/documentation/quiver/latest/quiver.time/Clock-class.html)
/// from [`package:quiver`](https://pub.dartlang.org/packages/quiver).
factory SentryIOClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
}) {
httpClient ??= Client();
clock ??= getUtcDateTime;
compressPayload ??= true;
factory SentryIOClient(SentryOptions options) => SentryIOClient._(options);

return SentryIOClient._(
httpClient: httpClient,
clock: clock,
environmentAttributes: environmentAttributes,
dsn: dsn,
compressPayload: compressPayload,
platform: sdkPlatform,
);
}

SentryIOClient._({
Client httpClient,
dynamic clock,
Event environmentAttributes,
String dsn,
this.compressPayload = true,
String platform,
String origin,
}) : super.base(
httpClient: httpClient,
clock: clock,
environmentAttributes: environmentAttributes,
dsn: dsn,
platform: platform,
origin: origin,
sdk: Sdk(name: sdkName, version: sdkVersion),
);

/// Whether to compress payloads sent to Sentry.io.
final bool compressPayload;
SentryIOClient._(SentryOptions options) : super.base(options);

@override
Map<String, String> buildHeaders(String authHeader) {
Expand Down
72 changes: 40 additions & 32 deletions dart/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ Future testCaptureException(
});

final client = SentryClient(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: compressPayload,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
SentryOptions(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: compressPayload,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
),
),
);

Expand Down Expand Up @@ -227,14 +229,16 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
});

final client = SentryClient(
dsn: _testDsnWithoutSecret,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
SentryOptions(
dsn: _testDsnWithoutSecret,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
),
),
);

Expand Down Expand Up @@ -282,14 +286,16 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
});

final client = SentryClient(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
SentryOptions(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
),
),
);

Expand Down Expand Up @@ -335,14 +341,16 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
extras: <String, String>{'foo': 'bar'});

final client = SentryClient(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
SentryOptions(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
environmentAttributes: Event(
serverName: 'test.server.com',
release: '1.2.3',
environment: 'staging',
),
),
);
client.userContext = clientUserContext;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.