Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
- Added Scope and Breadcrumb ring buffer #109
- Added Hub to SDK #113
- Ref: Hub passes the Scope to SentryClient
- feat: sentry options #116
- Feat: sentry options #116
- Ref: SentryId generates UUID

# `package:sentry` changelog

Expand Down
11 changes: 0 additions & 11 deletions dart/lib/src/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ SentryClient createSentryClient({
bool compressPayload,
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
}) =>
SentryBrowserClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
);

/// Logs crash reports and events to the Sentry.io service.
Expand All @@ -49,29 +47,22 @@ 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).
///
/// 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;

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

return SentryBrowserClient._(
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
environmentAttributes: environmentAttributes,
dsn: dsn,
origin: origin,
Expand All @@ -82,15 +73,13 @@ class SentryBrowserClient extends SentryClient {
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,
Expand Down
9 changes: 2 additions & 7 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,24 @@ abstract class SentryClient {
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,
String platform,
this.origin,
Sdk sdk,
}) : _dsn = Dsn.parse(dsn),
_uuidGenerator = uuidGenerator ?? generateUuidV4WithoutDashes,
_platform = platform ?? sdkPlatform,
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion) {
if (clock == null) {
Expand All @@ -63,7 +59,6 @@ abstract class SentryClient {
final Client httpClient;

ClockProvider _clock;
final UuidGenerator _uuidGenerator;

/// Contains [Event] attributes that are automatically mixed into all events
/// captured through this client.
Expand Down Expand Up @@ -153,7 +148,7 @@ abstract class SentryClient {

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

Expand Down Expand Up @@ -193,7 +188,7 @@ abstract class SentryClient {
}

final eventId = json.decode(response.body)['id'];
return eventId != null ? SentryId(eventId) : SentryId.empty();
return eventId != null ? SentryId.fromId(eventId) : SentryId.empty();
}

/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
Expand Down
2 changes: 0 additions & 2 deletions dart/lib/src/client_stub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:meta/meta.dart';

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

/// Implemented in `browser_client.dart` and `io_client.dart`.
SentryClient createSentryClient({
Expand All @@ -16,7 +15,6 @@ SentryClient createSentryClient({
bool compressPayload,
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
}) =>
throw UnsupportedError(
'Cannot create a client without dart:html or dart:io.');
4 changes: 1 addition & 3 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Hub {
compressPayload: fromOptions.compressPayload,
httpClient: fromOptions.httpClient,
clock: fromOptions.clock,
uuidGenerator: fromOptions.uuidGenerator,
);
}

Expand Down Expand Up @@ -80,10 +79,9 @@ class Hub {
try {
sentryId = await item.client.captureEvent(event, scope: item.scope);
} catch (err) {
/* TODO add Event.id */
_options.logger(
SentryLevel.error,
'Error while capturing event with id: ${event}',
'Error while capturing event with id: ${event.eventId}',
);
} finally {
_lastEventId = sentryId;
Expand Down
11 changes: 0 additions & 11 deletions dart/lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ SentryClient createSentryClient({
bool compressPayload,
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
}) =>
SentryIOClient(
dsn: dsn,
environmentAttributes: environmentAttributes,
compressPayload: compressPayload,
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
);

/// Logs crash reports and events to the Sentry.io service.
Expand All @@ -53,27 +51,20 @@ 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).
///
/// 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;

return SentryIOClient._(
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
environmentAttributes: environmentAttributes,
dsn: dsn,
compressPayload: compressPayload,
Expand All @@ -84,7 +75,6 @@ class SentryIOClient extends SentryClient {
SentryIOClient._({
Client httpClient,
dynamic clock,
UuidGenerator uuidGenerator,
Event environmentAttributes,
String dsn,
this.compressPayload = true,
Expand All @@ -93,7 +83,6 @@ class SentryIOClient extends SentryClient {
}) : super.base(
httpClient: httpClient,
clock: clock,
uuidGenerator: uuidGenerator,
environmentAttributes: environmentAttributes,
dsn: dsn,
platform: platform,
Expand Down
10 changes: 10 additions & 0 deletions dart/lib/src/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import '../version.dart';
class Event {
/// Creates an event.
const Event({
this.eventId,
this.loggerName,
this.serverName,
this.release,
Expand All @@ -34,6 +35,9 @@ class Event {
/// fingerprint with custom fingerprints.
static const String defaultFingerprint = '{{ default }}';

/// The ID Sentry.io assigned to the submitted event for future reference.
final SentryId eventId;

/// The logger that logged the event.
final String loggerName;

Expand Down Expand Up @@ -117,6 +121,7 @@ class Event {
final Sdk sdk;

Event copyWith({
SentryId eventId,
String loggerName,
String serverName,
String release,
Expand All @@ -136,6 +141,7 @@ class Event {
Sdk sdk,
}) =>
Event(
eventId: eventId ?? this.eventId,
loggerName: loggerName ?? this.loggerName,
serverName: serverName ?? this.serverName,
release: release ?? this.release,
Expand All @@ -162,6 +168,10 @@ class Event {
'platform': sdkPlatform,
};

if (eventId != null) {
json['event_id'] = eventId;
}

if (loggerName != null) {
json['logger'] = loggerName;
}
Expand Down
22 changes: 16 additions & 6 deletions dart/lib/src/protocol/sentry_id.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/// Sentry response id
import 'package:uuid/uuid.dart';

class SentryId {
static const String _emptyId = '00000000-0000-0000-0000-000000000000';
static final SentryId _emptyId =
SentryId.fromId('00000000-0000-0000-0000-000000000000');

/// The ID Sentry.io assigned to the submitted event for future reference.
final String _id;
String _id;

// TODO: should we generate the new UUID here with an empty ctor?
final Uuid _uuidGenerator = Uuid();

const SentryId(this._id);
SentryId._internal({String id}) {
_id = id ?? _uuidGenerator.v4();
}

factory SentryId.empty() => SentryId(_emptyId);
/// Generates a new SentryId
factory SentryId.newId() => SentryId._internal();

/// Generates a SentryId with the given UUID
factory SentryId.fromId(String id) => SentryId._internal(id: id);

/// SentryId with an empty UUID
factory SentryId.empty() => _emptyId;

@override
String toString() => _id.replaceAll('-', '');
Expand Down
7 changes: 0 additions & 7 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:sentry/sentry.dart';
import 'diagnostic_logger.dart';
import 'hub.dart';
import 'protocol.dart';
import 'utils.dart';

/// Sentry SDK options
class SentryOptions {
Expand Down Expand Up @@ -39,11 +38,6 @@ class SentryOptions {
/// from [`package:quiver`](https://pub.dartlang.org/packages/quiver).
dynamic clock;

/// 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.
UuidGenerator uuidGenerator;

int maxBreadcrumbs;

/// Logger interface to log useful debugging information if debug is enabled
Expand Down Expand Up @@ -145,7 +139,6 @@ class SentryOptions {
this.compressPayload,
this.httpClient,
this.clock,
this.uuidGenerator,
});

/// Adds an event processor
Expand Down
5 changes: 0 additions & 5 deletions dart/lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
// found in the LICENSE file.

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

typedef UuidGenerator = String Function();

String generateUuidV4WithoutDashes() => Uuid().v4().replaceAll('-', '');

/// Sentry does not take a timezone and instead expects the date-time to be
/// submitted in UTC timezone.
Expand Down
4 changes: 0 additions & 4 deletions dart/test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ Future testCaptureException(
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
uuidGenerator: () => 'X' * 32,
compressPayload: compressPayload,
environmentAttributes: const Event(
serverName: 'test.server.com',
Expand Down Expand Up @@ -232,7 +231,6 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
httpClient: httpMock,
clock: fakeClockProvider,
compressPayload: false,
uuidGenerator: () => 'X' * 32,
environmentAttributes: const Event(
serverName: 'test.server.com',
release: '1.2.3',
Expand Down Expand Up @@ -287,7 +285,6 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
uuidGenerator: () => 'X' * 32,
compressPayload: false,
environmentAttributes: const Event(
serverName: 'test.server.com',
Expand Down Expand Up @@ -341,7 +338,6 @@ void runTest({Codec<List<int>, List<int>> gzip, bool isWeb = false}) {
dsn: testDsn,
httpClient: httpMock,
clock: fakeClockProvider,
uuidGenerator: () => 'X' * 32,
compressPayload: false,
environmentAttributes: const Event(
serverName: 'test.server.com',
Expand Down