Skip to content
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

feat: sentry options #116

Merged
merged 7 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- expect a sdkName based on the test platform #105
- Added Scope and Breadcrumb ring buffer #109
- Added Hub to SDK #113
- feat: sentry options #116

# `package:sentry` changelog

Expand Down
4 changes: 2 additions & 2 deletions dart/example/event_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final event = Event(
environment: 'Test',
message: Message('This is an example Dart event.'),
transaction: '/example/app',
level: SeverityLevel.warning,
level: SentryLevel.warning,
tags: const <String, String>{'project-id': '7371'},
extra: const <String, String>{'company-name': 'Dart Inc'},
fingerprint: const <String>['example-dart'],
Expand All @@ -22,7 +22,7 @@ final event = Event(
category: 'ui.lifecycle',
type: 'navigation',
data: {'screen': 'MainActivity', 'state': 'created'},
level: SeverityLevel.info)
level: SentryLevel.info)
],
contexts: Contexts(
operatingSystem: const OperatingSystem(
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ abstract class SentryClient {
/// Reports the [template]
Future<SentryId> captureMessage(
String formatted, {
SeverityLevel level = SeverityLevel.info,
SentryLevel level = SentryLevel.info,
String template,
List<dynamic> params,
}) {
Expand Down
18 changes: 18 additions & 0 deletions dart/lib/src/diagnostic_logger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:sentry/sentry.dart';

class DiagnosticLogger {
final Logger _logger;
final SentryOptions _options;

DiagnosticLogger(this._logger, this._options);

void log(SentryLevel level, String message) {
if (_isEnabled(level)) {
_logger(level, message);
}
}

bool _isEnabled(SentryLevel level) {
return _options.debug && level.ordinal >= _options.diagnosticLevel.ordinal;
}
}
48 changes: 24 additions & 24 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class Hub {

if (!_isEnabled) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
"Instance is disabled and this 'captureEvent' call is a no-op.",
);
} else if (event == null) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
'captureEvent called with null parameter.',
);
} else {
Expand All @@ -81,15 +81,15 @@ class Hub {
} catch (err) {
/* TODO add Event.id */
_options.logger(
SeverityLevel.error,
SentryLevel.error,
'Error while capturing event with id: ${event}',
);
} finally {
_lastEventId = sentryId;
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was null when captureEvent',
);
}
Expand All @@ -106,12 +106,12 @@ class Hub {

if (!_isEnabled) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
"Instance is disabled and this 'captureException' call is a no-op.",
);
} else if (throwable == null) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
'captureException called with null parameter.',
);
} else {
Expand All @@ -125,15 +125,15 @@ class Hub {
);
} catch (err) {
_options.logger(
SeverityLevel.error,
SentryLevel.error,
'Error while capturing exception : ${throwable}',
);
} finally {
_lastEventId = sentryId;
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was null when captureException',
);
}
Expand All @@ -145,20 +145,20 @@ class Hub {
/// Captures the message.
Future<SentryId> captureMessage(
String message, {
SeverityLevel level = SeverityLevel.info,
SentryLevel level = SentryLevel.info,
String template,
List<dynamic> params,
}) async {
var sentryId = SentryId.empty();

if (!_isEnabled) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
"Instance is disabled and this 'captureMessage' call is a no-op.",
);
} else if (message == null) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
'captureMessage called with null parameter.',
);
} else {
Expand All @@ -174,15 +174,15 @@ class Hub {
);
} catch (err) {
_options.logger(
SeverityLevel.error,
SentryLevel.error,
'Error while capturing message with id: ${message}',
);
} finally {
_lastEventId = sentryId;
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was null when captureMessage',
);
}
Expand All @@ -193,21 +193,21 @@ class Hub {
/// Binds a different client to the hub
void bindClient(SentryClient client) {
if (!_isEnabled) {
_options.logger(SeverityLevel.warning,
_options.logger(SentryLevel.warning,
"Instance is disabled and this 'bindClient' call is a no-op.");
} else {
final item = _stack.first;
if (item != null) {
if (client != null) {
_options.logger(SeverityLevel.debug, 'New client bound to scope.');
_options.logger(SentryLevel.debug, 'New client bound to scope.');
item.client = client;
} else {
_options.logger(SeverityLevel.debug, 'NoOp client bound to scope.');
_options.logger(SentryLevel.debug, 'NoOp client bound to scope.');
item.client = NoOpSentryClient();
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was null when bindClient',
);
}
Expand All @@ -217,7 +217,7 @@ class Hub {
/// Clones the Hub
Hub clone() {
if (!_isEnabled) {
_options..logger(SeverityLevel.warning, 'Disabled Hub cloned.');
_options..logger(SentryLevel.warning, 'Disabled Hub cloned.');
}
final clone = Hub(_options);
for (final item in _stack) {
Expand All @@ -230,7 +230,7 @@ class Hub {
void close() {
if (!_isEnabled) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
"Instance is disabled and this 'close' call is a no-op.",
);
} else {
Expand All @@ -240,13 +240,13 @@ class Hub {
item.client.close();
} catch (err) {
_options.logger(
SeverityLevel.error,
SentryLevel.error,
'Error while closing the Hub.',
);
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was NULL when closing Hub',
);
}
Expand All @@ -258,7 +258,7 @@ class Hub {
void configureScope(ScopeCallback callback) {
if (!_isEnabled) {
_options.logger(
SeverityLevel.warning,
SentryLevel.warning,
"Instance is disabled and this 'configureScope' call is a no-op.",
);
} else {
Expand All @@ -268,13 +268,13 @@ class Hub {
callback(item.scope);
} catch (err) {
_options.logger(
SeverityLevel.error,
SentryLevel.error,
"Error in the 'configureScope' callback.",
);
}
} else {
_options.logger(
SeverityLevel.fatal,
SentryLevel.fatal,
'Stack peek was NULL when configureScope',
);
}
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/noop_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NoOpSentryClient implements SentryClient {
@override
Future<SentryId> captureMessage(
String message, {
SeverityLevel level = SeverityLevel.info,
SentryLevel level = SentryLevel.info,
String template,
List<dynamic> params,
}) =>
Expand Down
51 changes: 51 additions & 0 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'dart:async';

import 'client.dart';
import 'hub.dart';
import 'protocol/event.dart';
import 'protocol/sentry_level.dart';
import 'protocol/sentry_id.dart';

class NoOpHub implements Hub {
NoOpHub._();

static final NoOpHub _instance = NoOpHub._();

factory NoOpHub() {
return _instance;
}

@override
void bindClient(SentryClient client) {}

@override
Future<SentryId> captureEvent(Event event) => Future.value(SentryId.empty());

@override
Future<SentryId> captureException(throwable, {stackTrace}) =>
Future.value(SentryId.empty());

@override
Future<SentryId> captureMessage(
String message, {
SentryLevel level = SentryLevel.info,
String template,
List params,
}) =>
Future.value(SentryId.empty());

@override
Hub clone() => this;

@override
void close() {}

@override
void configureScope(callback) {}

@override
bool get isEnabled => false;

@override
SentryId get lastEventId => SentryId.empty();
}
2 changes: 1 addition & 1 deletion dart/lib/src/protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export 'protocol/contexts.dart';
export 'protocol/device.dart';
export 'protocol/dsn.dart';
export 'protocol/event.dart';
export 'protocol/level.dart';
export 'protocol/sentry_level.dart';
export 'protocol/message.dart';
export 'protocol/package.dart';
export 'protocol/runtime.dart';
Expand Down
6 changes: 3 additions & 3 deletions dart/lib/src/protocol/breadcrumb.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import '../utils.dart';
import 'level.dart';
import 'sentry_level.dart';

/// Structed data to describe more information pior to the event [captured][SentryClient.captureEvent].
///
Expand All @@ -24,7 +24,7 @@ class Breadcrumb {
this.timestamp, {
this.category,
this.data,
this.level = SeverityLevel.info,
this.level = SentryLevel.info,
this.type,
}) : assert(timestamp != null);

Expand Down Expand Up @@ -52,7 +52,7 @@ class Breadcrumb {
/// Severity of the breadcrumb.
///
/// This field is optional and may be set to null.
final SeverityLevel level;
final SentryLevel level;

/// Describes what type of breadcrumb this is.
///
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Event {
final String transaction;

/// How important this event is.
final SeverityLevel level;
final SentryLevel level;

/// What caused this event to be logged.
final String culprit;
Expand Down Expand Up @@ -125,7 +125,7 @@ class Event {
String transaction,
dynamic exception,
dynamic stackTrace,
SeverityLevel level,
SentryLevel level,
String culprit,
Map<String, String> tags,
Map<String, dynamic> extra,
Expand Down
16 changes: 0 additions & 16 deletions dart/lib/src/protocol/level.dart

This file was deleted.

17 changes: 17 additions & 0 deletions dart/lib/src/protocol/sentry_level.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:meta/meta.dart';

/// Severity of the logged [Event].
@immutable
class SentryLevel {
const SentryLevel._(this.name, this.ordinal);

static const fatal = SentryLevel._('fatal', 5);
static const error = SentryLevel._('error', 4);
static const warning = SentryLevel._('warning', 3);
static const info = SentryLevel._('info', 2);
static const debug = SentryLevel._('debug', 1);

/// API name of the level as it is encoded in the JSON protocol.
final String name;
final int ordinal;
}
Loading