Skip to content

Commit

Permalink
Feat : add a Hub class (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxlabz authored Oct 19, 2020
1 parent 5018978 commit d577e35
Show file tree
Hide file tree
Showing 21 changed files with 793 additions and 160 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- new static API : Sentry.init(), Sentry.captureEvent() #108
- expect a sdkName based on the test platform #105
- Added Scope and Breadcrumb ring buffer #109
- Added Hub to SDK #113

# `package:sentry` changelog

Expand Down
2 changes: 1 addition & 1 deletion dart/example/event_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final event = Event(
serverName: 'server.dart',
release: '1.4.0-preview.1',
environment: 'Test',
message: Message(formatted: 'This is an example Dart event.'),
message: Message('This is an example Dart event.'),
transaction: '/example/app',
level: SeverityLevel.warning,
tags: const <String, String>{'project-id': '7371'},
Expand Down
16 changes: 4 additions & 12 deletions dart/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,21 @@ Future<void> main(List<String> rawArgs) async {
print('\nReporting a complete event example: ');

// Sends a full Sentry event payload to show the different parts of the UI.
final response = await Sentry.captureEvent(event);
final sentryId = await Sentry.captureEvent(event);

if (response.isSuccessful) {
print('SUCCESS\nid: ${response.eventId}');
} else {
print('FAILURE: ${response.error}');
}
print('SentryId : ${sentryId}');

try {
await foo();
} catch (error, stackTrace) {
print('\nReporting the following stack trace: ');
print(stackTrace);
final response = await Sentry.captureException(
final sentryId = await Sentry.captureException(
error,
stackTrace: stackTrace,
);

if (response.isSuccessful) {
print('SUCCESS\nid: ${response.eventId}');
} else {
print('FAILURE: ${response.error}');
}
print('SentryId : ${sentryId}');
} finally {
await Sentry.close();
}
Expand Down
41 changes: 27 additions & 14 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

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

import 'client_stub.dart'
if (dart.library.html) 'browser_client.dart'
Expand Down Expand Up @@ -136,9 +137,10 @@ abstract class SentryClient {
}

/// Reports an [event] to Sentry.io.
Future<SentryResponse> captureEvent({
@required Event event,
Future<SentryId> captureEvent(
Event event, {
StackFrameFilter stackFrameFilter,
Scope scope,
}) async {
final now = _clock();
var authHeader = 'Sentry sentry_version=6, sentry_client=$clientId, '
Expand Down Expand Up @@ -183,27 +185,38 @@ abstract class SentryClient {
);

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

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

/// Reports the [exception] and optionally its [stackTrace] to Sentry.io.
Future<SentryResponse> captureException({
@required dynamic exception,
dynamic stackTrace,
}) {
/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
Future<SentryId> captureException(dynamic throwable, {dynamic stackTrace}) {
final event = Event(
exception: exception,
exception: throwable,
stackTrace: stackTrace,
);
return captureEvent(event: event);
return captureEvent(event);
}

/// Reports the [template]
Future<SentryId> captureMessage(
String formatted, {
SeverityLevel level = SeverityLevel.info,
String template,
List<dynamic> params,
}) {
final event = Event(
message: Message(formatted, template: template, params: params),
level: level,
);
return captureEvent(event);
}

Future<void> close() async {
Expand Down
Loading

0 comments on commit d577e35

Please sign in to comment.