Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
163cce7
Merge branch 'main' into feature/unified-api
marandaneto Oct 14, 2020
b91c954
Merge branch 'main' into feature/unified-api
marandaneto Oct 14, 2020
5018978
feat : static SDK main entry withSentry.init(options),... (#108)
rxlabz Oct 14, 2020
d577e35
Feat : add a Hub class (#113)
rxlabz Oct 19, 2020
fabf56f
feat: sentry options (#116)
marandaneto Oct 20, 2020
2b36bec
ref: Hub passes the Scope (#114)
marandaneto Oct 20, 2020
af3ecc0
Refacto : initialize SentryClient with SentryOptions (#118)
rxlabz Oct 20, 2020
19f5592
ref: SentryId generates UUID (#119)
marandaneto Oct 21, 2020
b51b0da
ref: Event now is SentryEvent and added GPU (#121)
marandaneto Oct 22, 2020
3fa0b79
feat: before breadcrumb and scope ref (#122)
marandaneto Oct 22, 2020
2cc1d78
Ref: Hint is passed across Sentry static class, Hub and Client (#124)
marandaneto Oct 22, 2020
11b821b
Ref: Remove stackFrameFilter in favor of beforeSendCallback (#125)
marandaneto Oct 22, 2020
ee737a2
Ref: Sentry init with null and empty DSN and close method (#126)
marandaneto Oct 22, 2020
eab4ccf
Refacto : add a Transport class (#123)
rxlabz Oct 23, 2020
c301ec6
Ref: execute before send callback (#128)
marandaneto Oct 24, 2020
1794f04
feat: addBreadcrumb to the Sentry static API (#133)
marandaneto Oct 26, 2020
e7db5d1
Feat: add lastEventId to the Sentry static API (#134)
marandaneto Oct 26, 2020
dc962ae
Fix: Breadcrumb data should accept serializable types and not only St…
marandaneto Oct 26, 2020
b9cd68b
Fix: NoOp encode for Web (#138)
marandaneto Oct 26, 2020
7b81890
Fix: execute Integrations on Hub creation (#136)
marandaneto Oct 26, 2020
b1761f4
unified api fixes and add web example (#137)
rxlabz Oct 27, 2020
d249c97
Ref/prepare event & scope.applyToEvent (#140)
rxlabz Oct 27, 2020
dc258d9
Ref : rename files accordely to their content (#141)
rxlabz Oct 27, 2020
c6669c3
rename the `throwable` argument to `exception` (#142)
rxlabz Oct 27, 2020
a0bb939
lint : prefer relative imports and show error when a @required argume…
rxlabz Oct 27, 2020
a7ca364
fix: Unified API code review (#144)
marandaneto Oct 28, 2020
56ac62a
Ref : remove dsn from Transport public API (#145)
rxlabz Oct 28, 2020
209f18a
Fix the pubspecs SDK constraints (#146)
rxlabz Oct 28, 2020
108ac6c
fix : throws on invalid dsn (#148)
rxlabz Oct 28, 2020
a81da3e
add comment to change the DSN
marandaneto Oct 28, 2020
c1812b7
update the workflow to run both on vm and on browser (#150)
rxlabz Oct 28, 2020
f597604
Bump sentry sdk to 4.0.0-alpha.1 (#151)
marandaneto Oct 28, 2020
6d9caff
remove TODOs
marandaneto Oct 28, 2020
32debd7
fix the web example pubspec (#153)
rxlabz Oct 28, 2020
c80365f
Ref: remove platform specific clients to use SentryClient (#152)
rxlabz Oct 29, 2020
2ed0f92
fix conflict
marandaneto Oct 29, 2020
c3ab59f
rewrite changelog
marandaneto Oct 29, 2020
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
Refacto : initialize SentryClient with SentryOptions (#118)
  • Loading branch information
rxlabz authored Oct 20, 2020
commit af3ecc069f3da17344ce002aca7bbf17048e61c9
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- BREAKING CHANGE: `package:http` min version bumped to 0.12.0 #104
- BREAKING CHANGE: replace the `package:usage` by `package:uuid` #94
- BREAKING CHANGE: `Event.message` must now be an instance of `Message`
- BREAKING CHANGE: SentryClient must now be initialized with a SentryOptions #118
- By default no logger it set #63
- Added missing Contexts to Event.copyWith() #62
- remove the `package:args` dependency #94
Expand Down
60 changes: 12 additions & 48 deletions dart/lib/src/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,15 @@ import 'dart:convert';
import 'dart:html' show window;

import 'package:http/browser_client.dart';
import 'package:http/http.dart';
import 'package:meta/meta.dart';

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

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

/// Logs crash reports and events to the Sentry.io service.
class SentryBrowserClient extends SentryClient {
Expand All @@ -53,49 +39,27 @@ class SentryBrowserClient extends SentryClient {
/// If [uuidGenerator] is provided, it is used to generate the "event_id"
/// field instead of the built-in random UUID v4 generator. This is useful in
/// tests.
factory SentryBrowserClient({
@required String dsn,
Event environmentAttributes,
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
String origin,
}) {
httpClient ??= BrowserClient();
clock ??= getUtcDateTime;
uuidGenerator ??= generateUuidV4WithoutDashes;
factory SentryBrowserClient(SentryOptions options, {String origin}) {
options.httpClient ??= BrowserClient();
options.clock ??= getUtcDateTime;
options.uuidGenerator ??= generateUuidV4WithoutDashes;

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

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

SentryBrowserClient._({
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
Event environmentAttributes,
String dsn,
String platform,
String origin,
}) : super.base(
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
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,
);

@override
Expand Down
75 changes: 20 additions & 55 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:convert';

import 'package:http/http.dart';
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';

Expand All @@ -22,60 +21,30 @@ 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,
UuidGenerator uuidGenerator,
}) =>
createSentryClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
compressPayload: compressPayload,
);

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

SentryClient.base(
this.options, {
String platform,
this.origin,
Sdk sdk,
}) : _dsn = Dsn.parse(dsn),
_uuidGenerator = uuidGenerator ?? generateUuidV4WithoutDashes,
}) : _dsn = Dsn.parse(options.dsn),
_platform = platform ?? sdkPlatform,
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion) {
if (clock == null) {
_clock = getUtcDateTime;
if (options.clock == null) {
options.clock = getUtcDateTime;
} else {
_clock = (clock is ClockProvider ? clock : clock.get) as ClockProvider;
options.clock = (options.clock is ClockProvider
? options.clock
: options.clock.get) as ClockProvider;
}
}

@protected
final Client httpClient;

ClockProvider _clock;
final UuidGenerator _uuidGenerator;

/// 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
SentryOptions options;

/// The DSN URI.
@visibleForTesting
Uri get dsnUri => _dsn.uri;
Expand Down Expand Up @@ -108,7 +77,7 @@ abstract class SentryClient {
User userContext;

/// Use for browser stacktrace
final String origin;
String origin;

/// Used by sentry to differentiate browser from io environment
final String _platform;
Expand Down Expand Up @@ -142,7 +111,7 @@ abstract class SentryClient {
StackFrameFilter stackFrameFilter,
Scope scope,
}) async {
final now = _clock();
final now = options.clock();
var authHeader = 'Sentry sentry_version=6, sentry_client=$clientId, '
'sentry_timestamp=${now.millisecondsSinceEpoch}, sentry_key=$publicKey';
if (secretKey != null) {
Expand All @@ -153,12 +122,12 @@ abstract class SentryClient {

final data = <String, dynamic>{
'project': projectId,
'event_id': _uuidGenerator(),
'event_id': options.uuidGenerator(),
'timestamp': formatDateAsIso8601WithSecondPrecision(now),
};

if (environmentAttributes != null) {
mergeAttributes(environmentAttributes.toJson(), into: data);
if (options.environmentAttributes != null) {
mergeAttributes(options.environmentAttributes.toJson(), into: data);
}

// Merge the user context.
Expand All @@ -178,17 +147,13 @@ abstract class SentryClient {

final body = bodyEncoder(data, headers);

final response = await httpClient.post(
final response = await options.httpClient.post(
postUri,
headers: headers,
body: body,
);

if (response.statusCode != 200) {
/*var errorMessage = 'Sentry.io responded with HTTP ${response.statusCode}';
if (response.headers['x-sentry-error'] != null) {
errorMessage += ': ${response.headers['x-sentry-error']}';
}*/
return SentryId.empty();
}

Expand Down Expand Up @@ -222,7 +187,7 @@ abstract class SentryClient {
}

Future<void> close() async {
httpClient.close();
options.httpClient?.close();
}

@override
Expand Down
15 changes: 2 additions & 13 deletions dart/lib/src/client_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:http/http.dart';
import 'package:meta/meta.dart';

import 'client.dart';
import 'protocol.dart';
import 'utils.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,
UuidGenerator uuidGenerator,
}) =>
SentryClient createSentryClient(SentryOptions options) =>
throw UnsupportedError(
'Cannot create a client without dart:html or dart:io.');
13 changes: 3 additions & 10 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +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,
uuidGenerator: fromOptions.uuidGenerator,
);
static SentryClient _getClient(SentryOptions options) {
return SentryClient(options);
}

final ListQueue<_StackItem> _stack = ListQueue();
Expand All @@ -36,7 +29,7 @@ class Hub {
}

Hub._(SentryOptions options) : _options = options {
_stack.add(_StackItem(_getClient(fromOptions: options), Scope(_options)));
_stack.add(_StackItem(_getClient(_options), Scope(_options)));
_isEnabled = true;
}

Expand Down
72 changes: 6 additions & 66 deletions dart/lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,13 @@
import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart';
import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';

import 'client.dart';
import 'protocol.dart';
import 'utils.dart';
import 'version.dart';

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

/// Logs crash reports and events to the Sentry.io service.
class SentryIOClient extends SentryClient {
Expand Down Expand Up @@ -57,52 +40,9 @@ class SentryIOClient extends SentryClient {
/// If [uuidGenerator] is provided, it is used to generate the "event_id"
/// field instead of the built-in random UUID v4 generator. This is useful in
/// tests.
factory SentryIOClient({
@required String dsn,
Event environmentAttributes,
bool compressPayload,
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
}) {
httpClient ??= Client();
clock ??= getUtcDateTime;
uuidGenerator ??= generateUuidV4WithoutDashes;
compressPayload ??= true;
factory SentryIOClient(SentryOptions options) => SentryIOClient._(options);

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

SentryIOClient._({
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
Event environmentAttributes,
String dsn,
this.compressPayload = true,
String platform,
String origin,
}) : super.base(
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
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 All @@ -123,7 +63,7 @@ class SentryIOClient extends SentryClient {
// [SentryIOClient] implement gzip compression
// gzip compression is not available on browser
var body = utf8.encode(json.encode(data));
if (compressPayload) {
if (options.compressPayload) {
headers['Content-Encoding'] = 'gzip';
body = gzip.encode(body);
}
Expand Down
Loading