Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
163cce7
Merge branch 'main' into feature/unified-api
marandaneto Oct 14, 2020
b91c954
Merge branch 'main' into feature/unified-api
marandaneto Oct 14, 2020
5018978
feat : static SDK main entry withSentry.init(options),... (#108)
rxlabz Oct 14, 2020
d577e35
Feat : add a Hub class (#113)
rxlabz Oct 19, 2020
fabf56f
feat: sentry options (#116)
marandaneto Oct 20, 2020
2b36bec
ref: Hub passes the Scope (#114)
marandaneto Oct 20, 2020
af3ecc0
Refacto : initialize SentryClient with SentryOptions (#118)
rxlabz Oct 20, 2020
19f5592
ref: SentryId generates UUID (#119)
marandaneto Oct 21, 2020
b51b0da
ref: Event now is SentryEvent and added GPU (#121)
marandaneto Oct 22, 2020
3fa0b79
feat: before breadcrumb and scope ref (#122)
marandaneto Oct 22, 2020
2cc1d78
Ref: Hint is passed across Sentry static class, Hub and Client (#124)
marandaneto Oct 22, 2020
11b821b
Ref: Remove stackFrameFilter in favor of beforeSendCallback (#125)
marandaneto Oct 22, 2020
ee737a2
Ref: Sentry init with null and empty DSN and close method (#126)
marandaneto Oct 22, 2020
eab4ccf
Refacto : add a Transport class (#123)
rxlabz Oct 23, 2020
c301ec6
Ref: execute before send callback (#128)
marandaneto Oct 24, 2020
1794f04
feat: addBreadcrumb to the Sentry static API (#133)
marandaneto Oct 26, 2020
e7db5d1
Feat: add lastEventId to the Sentry static API (#134)
marandaneto Oct 26, 2020
dc962ae
Fix: Breadcrumb data should accept serializable types and not only St…
marandaneto Oct 26, 2020
b9cd68b
Fix: NoOp encode for Web (#138)
marandaneto Oct 26, 2020
7b81890
Fix: execute Integrations on Hub creation (#136)
marandaneto Oct 26, 2020
b1761f4
unified api fixes and add web example (#137)
rxlabz Oct 27, 2020
d249c97
Ref/prepare event & scope.applyToEvent (#140)
rxlabz Oct 27, 2020
dc258d9
Ref : rename files accordely to their content (#141)
rxlabz Oct 27, 2020
c6669c3
rename the `throwable` argument to `exception` (#142)
rxlabz Oct 27, 2020
a0bb939
lint : prefer relative imports and show error when a @required argume…
rxlabz Oct 27, 2020
a7ca364
fix: Unified API code review (#144)
marandaneto Oct 28, 2020
56ac62a
Ref : remove dsn from Transport public API (#145)
rxlabz Oct 28, 2020
209f18a
Fix the pubspecs SDK constraints (#146)
rxlabz Oct 28, 2020
108ac6c
fix : throws on invalid dsn (#148)
rxlabz Oct 28, 2020
a81da3e
add comment to change the DSN
marandaneto Oct 28, 2020
c1812b7
update the workflow to run both on vm and on browser (#150)
rxlabz Oct 28, 2020
f597604
Bump sentry sdk to 4.0.0-alpha.1 (#151)
marandaneto Oct 28, 2020
6d9caff
remove TODOs
marandaneto Oct 28, 2020
32debd7
fix the web example pubspec (#153)
rxlabz Oct 28, 2020
c80365f
Ref: remove platform specific clients to use SentryClient (#152)
rxlabz Oct 29, 2020
2ed0f92
fix conflict
marandaneto Oct 29, 2020
c3ab59f
rewrite changelog
marandaneto Oct 29, 2020
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
Prev Previous commit
Next Next commit
Ref/prepare event & scope.applyToEvent (#140)
  • Loading branch information
rxlabz authored Oct 27, 2020
commit d249c9722eb78014ff992e6a040ada084bb1aad0
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Fix: Integrations are executed on Hub creation
- Fix: NoOp encode for Web
- Fix: Breadcrumb data should accept serializable types and not only String values
- Ref: added Scope.applyToEvent

# `package:sentry` changelog

Expand Down
70 changes: 16 additions & 54 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:math';

import 'package:meta/meta.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/transport/noop_transport.dart';

Expand Down Expand Up @@ -44,20 +43,18 @@ abstract class SentryClient {
return emptyFuture;
}

event = _applyScope(event: event, scope: scope);
if (scope != null) {
event = scope.applyToEvent(event, hint);
} else {
_options.logger(SentryLevel.debug, 'No scope is defined');
}

// dropped by scope event processors
if (event == null) {
return emptyFuture;
}

// TODO create eventProcessors ?
event = event.copyWith(
serverName: _options.serverName,
environment: _options.environment,
release: _options.release,
platform: event.platform ?? sdkPlatform,
);
event = _prepareEvent(event);

if (_options.beforeSendCallback != null) {
try {
Expand All @@ -77,6 +74,16 @@ abstract class SentryClient {
return _options.transport.send(event);
}

SentryEvent _prepareEvent(SentryEvent event) => event.copyWith(
serverName: event.serverName ?? _options.serverName,
dist: event.dist ?? _options.dist,
environment:
event.environment ?? _options.environment ?? defaultEnvironment,
release: event.release ?? _options.release,
sdk: event.sdk ?? _options.sdk,
platform: event.platform ?? sdkPlatform,
);

/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
Future<SentryId> captureException(
dynamic throwable, {
Expand Down Expand Up @@ -142,51 +149,6 @@ abstract class SentryClient {
return event;
}

SentryEvent _applyScope({
@required SentryEvent event,
@required Scope scope,
}) {
if (scope != null) {
// Merge the scope transaction.
if (event.transaction == null) {
event = event.copyWith(transaction: scope.transaction);
}

// Merge the user context.
if (event.userContext == null) {
event = event.copyWith(userContext: scope.user);
}

// Merge the scope fingerprint.
if (event.fingerprint == null) {
event = event.copyWith(fingerprint: scope.fingerprint);
}

// Merge the scope breadcrumbs.
if (event.breadcrumbs == null) {
event = event.copyWith(breadcrumbs: scope.breadcrumbs);
}

// Merge the scope tags.
event = event.copyWith(
tags: scope.tags.map((key, value) => MapEntry(key, value))
..addAll(event.tags ?? {}));

// Merge the scope extra.
event = event.copyWith(
extra: scope.extra.map((key, value) => MapEntry(key, value))
..addAll(event.extra ?? {}));

// Merge the scope level.
if (scope.level != null) {
event = event.copyWith(level: scope.level);
}

// TODO: execute scope event processors
}
return event;
}

bool _sampleRate() {
if (_options.sampleRate != null && _random != null) {
return (_options.sampleRate < _random.nextDouble());
Expand Down
5 changes: 2 additions & 3 deletions dart/lib/src/protocol/sentry_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SentryEvent {
SentryEvent({
SentryId eventId,
DateTime timestamp,
Sdk sdk,
this.sdk,
this.platform,
this.logger,
this.serverName,
Expand All @@ -33,8 +33,7 @@ class SentryEvent {
this.contexts,
this.breadcrumbs,
}) : eventId = eventId ?? SentryId.newId(),
timestamp = timestamp ?? getUtcDateTime(),
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion);
timestamp = timestamp ?? getUtcDateTime();

/// Refers to the default fingerprinting algorithm.
///
Expand Down
40 changes: 40 additions & 0 deletions dart/lib/src/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,46 @@ class Scope {
/// Removes an extra from the Scope
void removeExtra(String key) => _extra.remove(key);

SentryEvent applyToEvent(SentryEvent event, dynamic hint) {
event = event.copyWith(
transaction: event.transaction ?? transaction,
userContext: event.userContext ?? user,
fingerprint: event.fingerprint ?? fingerprint,
breadcrumbs: event.breadcrumbs ?? breadcrumbs,
tags: tags.isNotEmpty ? _mergeEventTags(event) : event.tags,
extra: extra.isNotEmpty ? _mergeEventExtra(event) : event.extra,
level: level ?? event.level,
);

for (final processor in _eventProcessors) {
try {
event = processor(event, hint);
} catch (err) {
_options.logger(
SentryLevel.error,
'An exception occurred while processing event by a processor : $err',
);
}
if (event == null) {
_options.logger(SentryLevel.debug, 'Event was dropped by a processor');
break;
}
}

return event;
}

/// the event tags will be kept
/// if the scope and the event have tag entries with the same key,
Map<String, String> _mergeEventTags(SentryEvent event) =>
tags.map((key, value) => MapEntry(key, value))..addAll(event.tags ?? {});

/// if the scope and the event have extra entries with the same key,
/// the event extra will be kept
Map<String, dynamic> _mergeEventExtra(SentryEvent event) =>
extra.map((key, value) => MapEntry(key, value))
..addAll(event.extra ?? {});

/// Clones the current Scope
Scope clone() {
final clone = Scope(_options)
Expand Down
11 changes: 9 additions & 2 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'hub.dart';
import 'protocol.dart';
import 'utils.dart';

const defaultEnvironment = 'production';

/// Sentry SDK options
class SentryOptions {
/// Default Log level if not specified Default is DEBUG
Expand Down Expand Up @@ -98,7 +100,6 @@ class SentryOptions {
/// Sets the release. SDK will try to automatically configure a release out of the box
String release;

// TODO: probably its part of environmentAttributes
/// Sets the environment. This string is freeform and not set by default. A release can be
/// associated with more than one environment to separate them in the UI Think staging vs prod or
/// similar.
Expand Down Expand Up @@ -137,8 +138,14 @@ class SentryOptions {
/// The server name used in the Sentry messages.
String serverName;

Sdk _sdk = Sdk(name: sdkName, version: sdkVersion);

/// Sdk object that contains the Sentry Client Name and its version
Sdk sdk;
Sdk get sdk => _sdk;

set sdk(Sdk sdk) {
_sdk = sdk ?? _sdk;
}

// TODO: Scope observers, enableScopeSync

Expand Down