Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
28792c6
ioClient : set a default Client
rxlabz Oct 26, 2020
a5e3fb8
options.compressPayload default value + minor
rxlabz Oct 26, 2020
4b5e8ea
captureMessage as a static method
rxlabz Oct 26, 2020
ee35bad
io example : send a formatted message
rxlabz Oct 26, 2020
51d18de
add a Dart web example
rxlabz Oct 26, 2020
f0ab2b9
changelog
rxlabz Oct 26, 2020
cc4e835
update web example
rxlabz Oct 26, 2020
c43d5bd
Merge remote-tracking branch 'origin/feature/unified-api' into fix/un…
rxlabz Oct 26, 2020
c2f89fa
Merge remote-tracking branch 'origin/feature/unified-api' into fix/un…
rxlabz Oct 26, 2020
27a8d31
add tests ( applyScope, captureMessage )
rxlabz Oct 26, 2020
070bfa5
minor
rxlabz Oct 26, 2020
eaa39e0
more applyScope tests
rxlabz Oct 26, 2020
352a270
refacto sentry client tests
rxlabz Oct 26, 2020
9c5110c
add a client.captureException test
rxlabz Oct 26, 2020
904b7b9
clean
rxlabz Oct 26, 2020
d0728c7
Update dart/examples/web_example/pubspec.yaml
rxlabz Oct 27, 2020
3f6f198
update the web example readme
rxlabz Oct 27, 2020
f5dc698
rename example methods
rxlabz Oct 27, 2020
c2e6b4d
clear the SentryOptions ctor
rxlabz Oct 27, 2020
fa1a8b1
refactor clients and update tests
rxlabz Oct 27, 2020
1f5828d
fix a test
rxlabz Oct 27, 2020
b0de53b
typo
rxlabz Oct 27, 2020
91beccc
clear tests
rxlabz Oct 27, 2020
1e36ab9
update examples
rxlabz Oct 27, 2020
d30a89b
move back example to /example ( pub.dev visibility)
rxlabz Oct 27, 2020
7b618c7
update example events
rxlabz Oct 27, 2020
edc6f35
update example events
rxlabz Oct 27, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ ios/
build/
.cxx/


.test_coverage.dart
dart/coverage/*
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- Ref: execute before send callback
- Feat: add lastEventId to the Sentry static API
- Feat: addBreadcrumb on Static API
- Add a Dart web example
- Fix: Integrations are executed on Hub creation
- Fix: NoOp encode for Web
- Fix: Breadcrumb data should accept serializable types and not only String values
Expand Down
File renamed without changes.
28 changes: 20 additions & 8 deletions dart/example/main.dart → dart/examples/io_example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,22 @@ Future<void> main(List<String> rawArgs) async {
// Sends a full Sentry event payload to show the different parts of the UI.
final sentryId = await Sentry.captureEvent(event);

print('SentryId : ${sentryId}');
print('Capture event result : SentryId : ${sentryId}');

print('\nCapture message: ');

// Sends a full Sentry event payload to show the different parts of the UI.
final messageSentryId = await Sentry.captureMessage(
'Message 1',
level: SentryLevel.warning,
template: 'Message %s',
params: ['1'],
);

print('Capture message result : SentryId : ${messageSentryId}');

try {
await foo();
await loadConfig();
} catch (error, stackTrace) {
print('\nReporting the following stack trace: ');
print(stackTrace);
Expand All @@ -37,22 +49,22 @@ Future<void> main(List<String> rawArgs) async {
stackTrace: stackTrace,
);

print('SentryId : ${sentryId}');
print('Capture exception result : SentryId : ${sentryId}');
} finally {
await Sentry.close();
}

/* TODO(rxlabz) Sentry CaptureMessage(message, level) */
}

Future<void> foo() async {
await bar();
Future<void> loadConfig() async {
await parseConfig();
}

Future<void> bar() async {
await baz();
Future<void> parseConfig() async {
await decode();
}

Future<void> baz() async {
Future<void> decode() async {
throw StateError('This is a test error');
}
9 changes: 9 additions & 0 deletions dart/examples/web_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Files and directories created by pub
.dart_tool/
.packages

# Conventional directory for build outputs
build/

# Directory created by dartdoc
doc/api/
9 changes: 9 additions & 0 deletions dart/examples/web_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Sentry Dart : web example

```dart
pub get

# run the project ( see https://dart.dev/tools/webdev#serve )
webdev serve --release

```
16 changes: 16 additions & 0 deletions dart/examples/web_example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: sentry_dart_web_example
description: An absolute bare-bones web app.
# version: 1.0.0
#homepage: https://www.example.com

environment:
sdk: ^2.0.0

dependencies:
sentry:
path: ../..

dev_dependencies:
build_runner: ^1.10.0
build_web_compilers: ^2.13.0
pedantic: ^1.9.0
Binary file added dart/examples/web_example/web/favicon.ico
Binary file not shown.
49 changes: 49 additions & 0 deletions dart/examples/web_example/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="scaffolded-by" content="https://github.com/dart-lang/stagehand">
<title>dart_web</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.ico">

<style>
.bloc {
display: flex;
margin: 1rem;
}

.result {
padding-left: 1rem;
color: green;
display: none;
}
</style>

<script defer src="main.dart.js"></script>
</head>

<body>

<div id="output"></div>

<div class="bloc">
<button id="btEvent">Capture Event</button>
<div id="eventResult" class="result">Captured</div>
</div>

<div class="bloc">
<button id="btMessage">Capture Message</button>
<div id="messageResult" class="result">Captured</div>
</div>

<div class="bloc">
<button id="btException">Capture Exception</button>
<div id="exceptionResult" class="result">Captured</div>
</div>

</body>
</html>
150 changes: 150 additions & 0 deletions dart/examples/web_example/web/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import 'dart:async';
import 'dart:html';

import 'package:sentry/sentry.dart';

const dsn =
'https://[email protected]/5428562';

void main() {
querySelector('#output').text = 'Your Dart app is running.';

querySelector('#btEvent')
.onClick
.listen((event) => captureCompleteExampleEvent());
querySelector('#btMessage').onClick.listen((event) => captureMessage());
querySelector('#btException').onClick.listen((event) => captureException());

Sentry.init((options) => options.dsn = dsn);
}

void captureMessage() async {
print('Capturing Message : ');
final sentryId = await Sentry.captureMessage(
'Message 2',
template: 'Message %s',
params: ['2'],
);
print('capture message result : $sentryId');
if (sentryId != SentryId.empty()) {
querySelector('#messageResult').style.display = 'block';
}
await Sentry.close();
}

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

print('Capture exception : SentryId: ${sentryId}');

if (sentryId != SentryId.empty()) {
querySelector('#exceptionResult').style.display = 'block';
}
}
}

Future<void> captureCompleteExampleEvent() async {
final event = SentryEvent(
logger: 'main',
serverName: 'server.dart',
release: '1.4.0-preview.1',
environment: 'Test',
message: Message('This is an example Dart event.'),
transaction: '/example/app',
level: SentryLevel.warning,
tags: const <String, String>{'project-id': '7371'},
extra: const <String, String>{'company-name': 'Dart Inc'},
fingerprint: const <String>['example-dart'],
userContext: const User(
id: '800',
username: 'first-user',
email: '[email protected]',
ipAddress: '127.0.0.1',
extras: <String, String>{'first-sign-in': '2020-01-01'}),
breadcrumbs: [
Breadcrumb(
message: 'UI Lifecycle',
timestamp: DateTime.now().toUtc(),
category: 'ui.lifecycle',
type: 'navigation',
data: {'screen': 'MainActivity', 'state': 'created'},
level: SentryLevel.info,
)
],
contexts: Contexts(
operatingSystem: const OperatingSystem(
name: 'Android',
version: '5.0.2',
build: 'LRX22G.P900XXS0BPL2',
kernelVersion:
'Linux version 3.4.39-5726670 (dpi@SWHC3807) (gcc version 4.8 (GCC) ) #1 SMP PREEMPT Thu Dec 1 19:42:39 KST 2016',
rooted: false),
runtimes: [const Runtime(name: 'ART', version: '5')],
app: App(
name: 'Example Dart App',
version: '1.42.0',
identifier: 'HGT-App-13',
build: '93785',
buildType: 'release',
deviceAppHash: '5afd3a6',
startTime: DateTime.now().toUtc()),
browser: const Browser(name: 'Firefox', version: '42.0.1'),
device: Device(
name: 'SM-P900',
family: 'SM-P900',
model: 'SM-P900 (LRX22G)',
modelId: 'LRX22G',
arch: 'armeabi-v7a',
batteryLevel: 99,
orientation: Orientation.landscape,
manufacturer: 'samsung',
brand: 'samsung',
screenResolution: '2560x1600',
screenDensity: 2.1,
screenDpi: 320,
online: true,
charging: true,
lowMemory: true,
simulator: false,
memorySize: 1500,
freeMemory: 200,
usableMemory: 4294967296,
storageSize: 4294967296,
freeStorage: 2147483648,
externalStorageSize: 8589934592,
externalFreeStorage: 2863311530,
bootTime: DateTime.now().toUtc(),
timezone: 'America/Toronto',
),
),
);

final sentryId = await Sentry.captureEvent(event);

print('\nReporting a complete event example: ${sdkName}');
print('Response SentryId: ${sentryId}');

if (sentryId != SentryId.empty()) {
querySelector('#eventResult').style.display = 'block';
}
}

Future<void> buildCard() async {
await loadData();
}

Future<void> loadData() async {
await parseData();
}

Future<void> parseData() async {
throw StateError('This is a test error');
}
14 changes: 14 additions & 0 deletions dart/examples/web_example/web/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import url(https://fonts.googleapis.com/css?family=Roboto);

html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}

#output {
padding: 20px;
text-align: center;
}
1 change: 0 additions & 1 deletion dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ abstract class SentryClient {
event = event.copyWith(breadcrumbs: scope.breadcrumbs);
}

// TODO add tests
// Merge the scope tags.
event = event.copyWith(
tags: scope.tags.map((key, value) => MapEntry(key, value))
Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

/// A pure Dart client for Sentry.io crash reporting.
Expand All @@ -16,6 +17,7 @@ class SentryIOClient extends SentryClient {
/// Instantiates a client using [SentryOptions]
factory SentryIOClient(SentryOptions options) {
options.sdk ??= Sdk(name: sdkName, version: sdkVersion);
options.httpClient ??= Client();
return SentryIOClient._(options);
}

Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:meta/meta.dart';

import 'client.dart';
import 'hub.dart';
import 'noop_hub.dart';
import 'protocol.dart';
import 'sentry_options.dart';
import 'noop_hub.dart';

/// Configuration options callback
typedef OptionsConfiguration = void Function(SentryOptions);
Expand Down
4 changes: 2 additions & 2 deletions dart/lib/src/sentry_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SentryOptions {
/// If [compressPayload] is `true` the outgoing HTTP payloads are compressed
/// using gzip. Otherwise, the payloads are sent in plain UTF8-encoded JSON
/// text. If not specified, the compression is enabled by default.
bool compressPayload = false;
bool compressPayload;

/// If [httpClient] is provided, it is used instead of the default client to
/// make HTTP calls to Sentry.io. This is useful in tests.
Expand Down Expand Up @@ -136,7 +136,7 @@ class SentryOptions {
// TODO: those ctor params could be set on Sentry._setDefaultConfiguration or instantiate by default here
SentryOptions({
this.dsn,
this.compressPayload,
this.compressPayload = true,
this.httpClient,
ClockProvider clock = getUtcDateTime,
}) {
Expand Down
2 changes: 2 additions & 0 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:mockito/mockito.dart';
import 'package:sentry/sentry.dart';
Expand Down
6 changes: 4 additions & 2 deletions dart/test/scope_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ void main() {
expect(sut.tags, clone.tags);
expect(sut.breadcrumbs, clone.breadcrumbs);
expect(ListEquality().equals(sut.fingerprint, clone.fingerprint), true);
expect(ListEquality().equals(sut.eventProcessors, clone.eventProcessors),
true);
expect(
ListEquality().equals(sut.eventProcessors, clone.eventProcessors),
true,
);
});
}

Expand Down
Loading