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

Fix: Mark Sentry.currentHub as deprecated #406

Merged
merged 3 commits into from
Apr 6, 2021
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
@@ -1,6 +1,7 @@
# Unreleased

* Fix: `Sentry.close()` closes native SDK integrations (#388)
* Fix: Mark `Sentry.currentHub` as deprecated (#406)

# 5.0.0

Expand Down
26 changes: 15 additions & 11 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Sentry {
Sentry._();

/// Returns the current hub
@Deprecated(
'This is scheduled to be removed in Sentry v6.0.0. '
'Instead of currentHub you should use Sentry\'s static methods.',
)
static Hub get currentHub => _hub;

/// Initializes the SDK
Expand Down Expand Up @@ -98,7 +102,7 @@ class Sentry {

// let's set the default values to options
if (await _setDefaultConfiguration(options)) {
final hub = currentHub;
final hub = _hub;
_hub = Hub(options);
await hub.close();
}
Expand Down Expand Up @@ -138,15 +142,15 @@ class Sentry {
dynamic stackTrace,
dynamic hint,
}) async =>
currentHub.captureEvent(event, stackTrace: stackTrace, hint: hint);
_hub.captureEvent(event, stackTrace: stackTrace, hint: hint);

/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
static Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
dynamic hint,
}) async =>
currentHub.captureException(
_hub.captureException(
throwable,
stackTrace: stackTrace,
hint: hint,
Expand All @@ -159,7 +163,7 @@ class Sentry {
List<dynamic>? params,
dynamic hint,
}) async =>
currentHub.captureMessage(
_hub.captureMessage(
message,
level: level,
template: template,
Expand All @@ -169,30 +173,30 @@ class Sentry {

/// Close the client SDK
static Future<void> close() async {
final hub = currentHub;
final hub = _hub;
_hub = NoOpHub();
await hub.close();
}

/// Check if the current Hub is enabled/active.
static bool get isEnabled => currentHub.isEnabled;
static bool get isEnabled => _hub.isEnabled;

/// Last event id recorded by the current Hub
static SentryId get lastEventId => currentHub.lastEventId;
static SentryId get lastEventId => _hub.lastEventId;

/// Adds a breacrumb to the current Scope
static void addBreadcrumb(Breadcrumb crumb, {dynamic hint}) =>
currentHub.addBreadcrumb(crumb, hint: hint);
_hub.addBreadcrumb(crumb, hint: hint);

/// Configures the scope through the callback.
static void configureScope(ScopeCallback callback) =>
currentHub.configureScope(callback);
_hub.configureScope(callback);

/// Clones the current Hub
static Hub clone() => currentHub.clone();
static Hub clone() => _hub.clone();

/// Binds a different client to the current hub
static void bindClient(SentryClient client) => currentHub.bindClient(client);
static void bindClient(SentryClient client) => _hub.bindClient(client);

static Future<bool> _setDefaultConfiguration(SentryOptions options) async {
// if the DSN is empty, let's disable the SDK
Expand Down