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: Introduce Hint data bag #1136

Merged
merged 44 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
957cde2
introduce hint class
denrase Nov 15, 2022
0c54fba
implement hint internal storage
denrase Nov 15, 2022
f3b3e64
ignore
denrase Nov 15, 2022
c863c7d
remove unneccessary imports
denrase Nov 15, 2022
fc5c48f
add changelog entry
denrase Nov 15, 2022
6133acd
make _internalStorage … internal
denrase Nov 15, 2022
50a5b3e
… and final
denrase Nov 15, 2022
e9a949c
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Nov 21, 2022
3bb6007
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Nov 21, 2022
07ecfb3
don’t return obj on remove
denrase Nov 21, 2022
1505bcc
create hint when none was provided
denrase Nov 21, 2022
d97805f
synt. sugar
denrase Nov 21, 2022
63430fa
pass log record as hint
denrase Nov 21, 2022
8acb622
pass on record hint to breadcrumb
denrase Nov 21, 2022
bac0e1d
remove unused import
denrase Nov 21, 2022
51b6b26
pass on errorDetails as hint in FlutterErrorIntegration
denrase Nov 21, 2022
cd719b2
pass on request and requestDuration
denrase Nov 21, 2022
07a3c4e
test capture of request and requestDuration in hint
denrase Nov 21, 2022
dfbd133
pass print callback values from runzonedguarded integration
denrase Nov 21, 2022
3beebd4
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Nov 22, 2022
5a0df89
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Nov 22, 2022
729ec1b
remove not needed hint
denrase Nov 22, 2022
a586aaa
change constructor to factory
denrase Nov 22, 2022
1c93a96
add response to hint
denrase Nov 22, 2022
855f366
use syntheticException key
denrase Nov 22, 2022
8347d07
move hint to captured event
denrase Dec 5, 2022
74966cd
intruduce capturedbreadcrum similar to capturedevent in mock
denrase Dec 5, 2022
9ea4b99
introduce TypeCheckHint class with constants
denrase Dec 5, 2022
9105299
fix merge issue in DioEventProcessor
denrase Dec 6, 2022
fbddcc4
add to type check hints
denrase Dec 6, 2022
cf57655
add TypeCheckHint.record
denrase Dec 6, 2022
69a875c
fix tests
denrase Dec 6, 2022
1d7924f
fix imports
denrase Dec 6, 2022
7e72222
add required trailing comma
denrase Dec 6, 2022
6bf4a83
remove disable of cyclomatic_complexity
denrase Dec 6, 2022
c38affd
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Dec 6, 2022
4073333
remove request duration hint
denrase Dec 6, 2022
0021a6a
fix issue in sentry user interaction widget
denrase Dec 12, 2022
0134de2
add comments for hint
denrase Dec 12, 2022
2f07ae0
add sample code to hint description
denrase Dec 12, 2022
215f330
Merge branch 'v7.0.0' into feat/introduce-hint-data-bag
denrase Dec 12, 2022
24b51c3
fix test
denrase Dec 12, 2022
026605e
Feat: Use `Hint` for screenshots (#1165)
denrase Dec 12, 2022
bfe155c
remove not needed option setup
denrase Dec 12, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 7.0.0

### Features

- Feat: Introduce Hint data bag ([#1136](https://github.com/getsentry/sentry-dart/pull/1136))

### Fixes

- Fix: Remove `SentryOptions` related parameters from classes which also take `Hub` as a parameter (#816)
Expand Down
2 changes: 2 additions & 0 deletions dart/lib/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export 'src/sentry_user_feedback.dart';
export 'src/utils/tracing_utils.dart';
// tracing
export 'src/tracing.dart';
export 'src/hint.dart';
export 'src/type_check_hint.dart';
3 changes: 2 additions & 1 deletion dart/lib/src/event_processor.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'hint.dart';
import 'protocol.dart';

/// [EventProcessor]s are callbacks that run for every event. They can either
Expand All @@ -8,6 +9,6 @@ import 'protocol.dart';
abstract class EventProcessor {
FutureOr<SentryEvent?> apply(
SentryEvent event, {
dynamic hint,
Hint? hint,
});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'dart:async';
import 'dart:io';

import '../../protocol.dart';
import '../../sentry_options.dart';
import '../../../sentry.dart';
import 'enricher_event_processor.dart';

EnricherEventProcessor enricherEventProcessor(SentryOptions options) {
Expand All @@ -20,7 +19,7 @@ class IoEnricherEventProcessor implements EnricherEventProcessor {
final SentryOptions _options;

@override
FutureOr<SentryEvent> apply(SentryEvent event, {dynamic hint}) {
FutureOr<SentryEvent> apply(SentryEvent event, {Hint? hint}) {
// If there's a native integration available, it probably has better
// information available than Flutter.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'dart:async';
import 'dart:html' as html show window, Window;

import '../../protocol.dart';
import '../../sentry_options.dart';
import '../../../sentry.dart';
import 'enricher_event_processor.dart';

EnricherEventProcessor enricherEventProcessor(SentryOptions options) {
Expand All @@ -23,7 +22,7 @@ class WebEnricherEventProcessor implements EnricherEventProcessor {
final SentryOptions _options;

@override
FutureOr<SentryEvent> apply(SentryEvent event, {dynamic hint}) {
FutureOr<SentryEvent> apply(SentryEvent event, {Hint? hint}) {
// Web has no native integration, so no need to check for it

final contexts = event.contexts.copyWith(
Expand Down
33 changes: 33 additions & 0 deletions dart/lib/src/hint.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Hint {
denrase marked this conversation as resolved.
Show resolved Hide resolved
final Map<String, Object> _internalStorage = {};

Hint();

factory Hint.withMap(Map<String, Object> map) {
final hint = Hint();
hint.addAll(map);
return hint;
}

// Objects

void addAll(Map<String, Object> keysAndValues) {
_internalStorage.addAll(keysAndValues);
}

void set(String key, Object value) {
_internalStorage[key] = value;
}

Object? get(String key) {
return _internalStorage[key];
}

void remove(String key) {
_internalStorage.remove(key);
}

void clear() {
_internalStorage.clear();
}
}
14 changes: 13 additions & 1 deletion dart/lib/src/http_client/failed_request_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:http/http.dart';
import '../hint.dart';
import '../type_check_hint.dart';
import 'sentry_http_client_error.dart';
import '../protocol.dart';
import '../hub.dart';
Expand Down Expand Up @@ -176,15 +178,25 @@ class FailedRequestClient extends BaseClient {
timestamp: _hub.options.clock(),
);

final hint = Hint.withMap({
TypeCheckHint.httpRequest: request,
TypeCheckHint.httpRequestDuration: requestDuration,
denrase marked this conversation as resolved.
Show resolved Hide resolved
});

if (response != null) {
event.contexts.response = SentryResponse(
headers: _hub.options.sendDefaultPii ? response.headers : null,
bodySize: response.contentLength,
statusCode: response.statusCode,
);
hint.set(TypeCheckHint.httpResponse, response);
}

await _hub.captureEvent(event, stackTrace: stackTrace);
await _hub.captureEvent(
event,
stackTrace: stackTrace,
hint: hint,
);
}

// Types of Request can be found here:
Expand Down
8 changes: 4 additions & 4 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Hub {
Future<SentryId> captureEvent(
SentryEvent event, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async {
var sentryId = SentryId.empty();
Expand Down Expand Up @@ -112,7 +112,7 @@ class Hub {
Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async {
var sentryId = SentryId.empty();
Expand Down Expand Up @@ -168,7 +168,7 @@ class Hub {
SentryLevel? level,
String? template,
List<dynamic>? params,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async {
var sentryId = SentryId.empty();
Expand Down Expand Up @@ -258,7 +258,7 @@ class Hub {
}

/// Adds a breacrumb to the current Scope
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {
Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) async {
if (!_isEnabled) {
_options.logger(
SentryLevel.warning,
Expand Down
9 changes: 5 additions & 4 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

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

import 'hub.dart';
import 'protocol.dart';
Expand All @@ -25,7 +26,7 @@ class HubAdapter implements Hub {
}

@override
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async =>
Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) async =>
await Sentry.addBreadcrumb(crumb, hint: hint);

@override
Expand All @@ -35,7 +36,7 @@ class HubAdapter implements Hub {
Future<SentryId> captureEvent(
SentryEvent event, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
Sentry.captureEvent(
Expand All @@ -49,7 +50,7 @@ class HubAdapter implements Hub {
Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
Sentry.captureException(
Expand All @@ -65,7 +66,7 @@ class HubAdapter implements Hub {
SentryLevel? level,
String? template,
List? params,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
Sentry.captureMessage(
Expand Down
9 changes: 5 additions & 4 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:meta/meta.dart';

import 'hint.dart';
import 'hub.dart';
import 'protocol.dart';
import 'sentry_client.dart';
Expand Down Expand Up @@ -31,7 +32,7 @@ class NoOpHub implements Hub {
Future<SentryId> captureEvent(
SentryEvent event, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async =>
SentryId.empty();
Expand All @@ -40,7 +41,7 @@ class NoOpHub implements Hub {
Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async =>
SentryId.empty();
Expand All @@ -51,7 +52,7 @@ class NoOpHub implements Hub {
SentryLevel? level,
String? template,
List? params,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) async =>
SentryId.empty();
Expand All @@ -72,7 +73,7 @@ class NoOpHub implements Hub {
SentryId get lastEventId => SentryId.empty();

@override
Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async {}
Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) async {}

@override
Future<SentryId> captureTransaction(
Expand Down
7 changes: 4 additions & 3 deletions dart/lib/src/noop_sentry_client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'hint.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_client.dart';
Expand All @@ -21,7 +22,7 @@ class NoOpSentryClient implements SentryClient {
SentryEvent event, {
dynamic stackTrace,
Scope? scope,
dynamic hint,
Hint? hint,
}) async =>
SentryId.empty();

Expand All @@ -30,7 +31,7 @@ class NoOpSentryClient implements SentryClient {
dynamic exception, {
dynamic stackTrace,
Scope? scope,
dynamic hint,
Hint? hint,
}) async =>
SentryId.empty();

Expand All @@ -41,7 +42,7 @@ class NoOpSentryClient implements SentryClient {
String? template,
List<dynamic>? params,
Scope? scope,
dynamic hint,
Hint? hint,
}) async =>
SentryId.empty();

Expand Down
10 changes: 6 additions & 4 deletions dart/lib/src/run_zoned_guarded_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ class RunZonedGuardedIntegration extends Integration {
_isPrinting = true;

try {
hub.addBreadcrumb(Breadcrumb.console(
message: line,
level: SentryLevel.debug,
));
hub.addBreadcrumb(
Breadcrumb.console(
message: line,
level: SentryLevel.debug,
),
);

parent.print(zone, line);
} finally {
Expand Down
7 changes: 4 additions & 3 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:collection';

import 'event_processor.dart';
import 'hint.dart';
import 'protocol.dart';
import 'scope_observer.dart';
import 'sentry_attachment/sentry_attachment.dart';
Expand Down Expand Up @@ -153,7 +154,7 @@ class Scope {

Scope(this._options);

bool _addBreadCrumbSync(Breadcrumb breadcrumb, {dynamic hint}) {
bool _addBreadCrumbSync(Breadcrumb breadcrumb, {Hint? hint}) {
// bail out if maxBreadcrumbs is zero
if (_options.maxBreadcrumbs == 0) {
return false;
Expand Down Expand Up @@ -195,7 +196,7 @@ class Scope {
}

/// Adds a breadcrumb to the breadcrumbs queue
Future<void> addBreadcrumb(Breadcrumb breadcrumb, {dynamic hint}) async {
Future<void> addBreadcrumb(Breadcrumb breadcrumb, {Hint? hint}) async {
if (_addBreadCrumbSync(breadcrumb, hint: hint)) {
await _callScopeObservers((scopeObserver) async =>
await scopeObserver.addBreadcrumb(breadcrumb));
Expand Down Expand Up @@ -282,7 +283,7 @@ class Scope {

Future<SentryEvent?> applyToEvent(
SentryEvent event, {
dynamic hint,
Hint? hint,
}) async {
event = event.copyWith(
transaction: event.transaction ?? transaction,
Expand Down
9 changes: 5 additions & 4 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'run_zoned_guarded_integration.dart';
import 'event_processor/enricher/enricher_event_processor.dart';
import 'environment/environment_variables.dart';
import 'event_processor/deduplication_event_processor.dart';
import 'hint.dart';
import 'event_processor/exception/exception_event_processor.dart';
import 'hub.dart';
import 'hub_adapter.dart';
Expand Down Expand Up @@ -156,7 +157,7 @@ class Sentry {
static Future<SentryId> captureEvent(
SentryEvent event, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
_hub.captureEvent(
Expand All @@ -170,7 +171,7 @@ class Sentry {
static Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
_hub.captureException(
Expand All @@ -186,7 +187,7 @@ class Sentry {
SentryLevel? level = SentryLevel.info,
String? template,
List<dynamic>? params,
dynamic hint,
Hint? hint,
ScopeCallback? withScope,
}) =>
_hub.captureMessage(
Expand Down Expand Up @@ -218,7 +219,7 @@ class Sentry {
static SentryId get lastEventId => _hub.lastEventId;

/// Adds a breacrumb to the current Scope
static Future<void> addBreadcrumb(Breadcrumb crumb, {dynamic hint}) async =>
static Future<void> addBreadcrumb(Breadcrumb crumb, {Hint? hint}) async =>
await _hub.addBreadcrumb(crumb, hint: hint);

/// Configures the scope through the callback.
Expand Down
Loading