-
-
Notifications
You must be signed in to change notification settings - Fork 277
feature : static SDK main entry withSentry.init(options),... #108
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
Changes from 2 commits
6b4d9aa
f091386
43109b3
03405a0
870724a
898b451
d9652da
408fa5a
ae4689a
b971db2
6459069
c070153
0c2aaaf
cf5cd50
83c59d4
02d0918
f63ac27
edf665a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import 'package:sentry/src/protocol.dart'; | ||
|
|
||
| final event = Event( | ||
| loggerName: 'main', | ||
| serverName: 'server.dart', | ||
| release: '1.4.0-preview.1', | ||
| environment: 'Test', | ||
| message: Message(formatted: 'This is an example Dart event.'), | ||
| transaction: '/example/app', | ||
| level: SeverityLevel.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('UI Lifecycle', DateTime.now().toUtc(), | ||
| category: 'ui.lifecycle', | ||
| type: 'navigation', | ||
| data: {'screen': 'MainActivity', 'state': 'created'}, | ||
| level: SeverityLevel.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', | ||
| ), | ||
| ), | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ | |
| import 'dart:async'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:sentry/sentry.dart'; | ||
| import 'package:sentry/src/sentry.dart'; | ||
| import 'package:sentry/src/sentry_options.dart'; | ||
|
|
||
| import 'event_example.dart'; | ||
|
|
||
| /// Sends a test exception report to Sentry.io using this Dart client. | ||
| Future<void> main(List<String> rawArgs) async { | ||
|
|
@@ -16,18 +19,26 @@ Future<void> main(List<String> rawArgs) async { | |
| } | ||
|
|
||
| final dsn = rawArgs.single; | ||
| final client = SentryClient(dsn: dsn); | ||
| Sentry.init(SentryOptions(dsn: dsn)); | ||
|
|
||
| print('\nReporting a complete event example: '); | ||
|
|
||
| // Sends a full Sentry event payload to show the different parts of the UI. | ||
| await captureCompleteExampleEvent(client); | ||
| final response = await Sentry.captureEvent(event); | ||
|
|
||
| if (response.isSuccessful) { | ||
| print('SUCCESS\nid: ${response.eventId}'); | ||
| } else { | ||
| print('FAILURE: ${response.error}'); | ||
| } | ||
|
|
||
| try { | ||
| await foo(); | ||
| } catch (error, stackTrace) { | ||
| print('\nReporting the following stack trace: '); | ||
| print(stackTrace); | ||
| final response = await client.captureException( | ||
| exception: error, | ||
| final response = await Sentry.captureException( | ||
| error, | ||
| stackTrace: stackTrace, | ||
| ); | ||
|
|
||
|
|
@@ -37,80 +48,13 @@ Future<void> main(List<String> rawArgs) async { | |
| print('FAILURE: ${response.error}'); | ||
| } | ||
| } finally { | ||
| await client.close(); | ||
| await Sentry.close(); | ||
| } | ||
| } | ||
|
|
||
| Future<void> captureCompleteExampleEvent(SentryClient client) async { | ||
| final event = Event( | ||
| loggerName: 'main', | ||
| serverName: 'server.dart', | ||
| release: '1.4.0-preview.1', | ||
| environment: 'Test', | ||
| message: Message(formatted: 'This is an example Dart event.'), | ||
| transaction: '/example/app', | ||
| level: SeverityLevel.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('UI Lifecycle', DateTime.now().toUtc(), | ||
| category: 'ui.lifecycle', | ||
| type: 'navigation', | ||
| data: {'screen': 'MainActivity', 'state': 'created'}, | ||
| level: SeverityLevel.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', | ||
| ))); | ||
| /* TODO(rxlabz) Sentry CaptureMessage(message, level) */ | ||
|
|
||
| /*Future<void> captureCompleteExampleEvent(SentryClient client) async { | ||
|
|
||
|
|
||
| final response = await client.captureEvent(event: event); | ||
|
|
||
|
|
@@ -120,6 +64,7 @@ Future<void> captureCompleteExampleEvent(SentryClient client) async { | |
| } else { | ||
| print('FAILURE: ${response.error}'); | ||
| } | ||
| */ | ||
| } | ||
|
|
||
| Future<void> foo() async { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import 'package:meta/meta.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| import 'client.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import 'protocol.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import 'sentry_options.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import 'stack_trace.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Sentry SDK main entry point | ||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||
| class Sentry { | ||||||||||||||||||||||||||||||||||||||||||||||||
| static SentryClient _client; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| Sentry._(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| static void init(SentryOptions options) { | ||||||||||||||||||||||||||||||||||||||||||||||||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
| _client = SentryClient( | ||||||||||||||||||||||||||||||||||||||||||||||||
| dsn: options.dsn, | ||||||||||||||||||||||||||||||||||||||||||||||||
| environmentAttributes: options.environmentAttributes, | ||||||||||||||||||||||||||||||||||||||||||||||||
| compressPayload: options.compressPayload, | ||||||||||||||||||||||||||||||||||||||||||||||||
| httpClient: options.httpClient, | ||||||||||||||||||||||||||||||||||||||||||||||||
| clock: options.clock, | ||||||||||||||||||||||||||||||||||||||||||||||||
| uuidGenerator: options.uuidGenerator, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Initializes the SDK | ||||||||||||||||||||||||||||||||||||||||||||||||
| static void initDns(String dns) => _client = SentryClient(dsn: dns); | ||||||||||||||||||||||||||||||||||||||||||||||||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// Reports an [event] to Sentry.io. | ||||||||||||||||||||||||||||||||||||||||||||||||
| static Future<SentryResponse> captureEvent( | ||||||||||||||||||||||||||||||||||||||||||||||||
| Event event, { | ||||||||||||||||||||||||||||||||||||||||||||||||
| StackFrameFilter stackFrameFilter, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }) async { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return _client.captureEvent( | ||||||||||||||||||||||||||||||||||||||||||||||||
| event: event, | ||||||||||||||||||||||||||||||||||||||||||||||||
| stackFrameFilter: stackFrameFilter, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
| /// A response from Sentry.io. | |
| /// | |
| /// If [isSuccessful] the [eventId] field will contain the ID assigned to the | |
| /// captured event by the Sentry.io backend. Otherwise, the [error] field will | |
| /// contain the description of the error. | |
| @immutable | |
| class SentryResponse { | |
| const SentryResponse.success({@required this.eventId}) | |
| : isSuccessful = true, | |
| error = null; | |
| const SentryResponse.failure(this.error) | |
| : isSuccessful = false, | |
| eventId = null; | |
| /// Whether event was submitted successfully. | |
| final bool isSuccessful; | |
| /// The ID Sentry.io assigned to the submitted event for future reference. | |
| final String eventId; | |
| /// Error message, if the response is not successful. | |
| final String error; |
SentryId?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, not really, this is the whole response, we'd need to create a SentryId class and inside of the client, we just read the uuid out of the response and create a SentryId with the proper uuid, this doesn't need to be in this PR
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import 'package:http/http.dart'; | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| import 'protocol.dart'; | ||
| import 'utils.dart'; | ||
|
|
||
| /// Sentry SDK options | ||
| class SentryOptions { | ||
| /// Default Log level if not specified Default is DEBUG | ||
| static final SeverityLevel defaultDiagnosticLevel = SeverityLevel.debug; | ||
|
|
||
| /// The DSN tells the SDK where to send the events to. If this value is not provided, the SDK will | ||
| /// just not send any events. | ||
| final String dsn; | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Contains [Event] attributes that are automatically mixed into all events | ||
| /// captured through this client. | ||
| /// | ||
| /// This event is designed to contain static values that do not change from | ||
| /// event to event, such as local operating system version, the version of | ||
| /// Dart/Flutter SDK, etc. These attributes have lower precedence than those | ||
| /// supplied in the even passed to [capture]. | ||
| final Event environmentAttributes; | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// 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. | ||
| final 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. | ||
| final Client httpClient; | ||
|
|
||
| /// If [clock] is provided, it is used to get time instead of the system | ||
| /// clock. This is useful in tests. Should be an implementation of [ClockProvider]. | ||
| /// This parameter is dynamic to maintain backwards compatibility with | ||
| /// previous use of [Clock](https://pub.dartlang.org/documentation/quiver/latest/quiver.time/Clock-class.html) | ||
| /// from [`package:quiver`](https://pub.dartlang.org/packages/quiver). | ||
| final dynamic clock; | ||
|
|
||
| /// If [uuidGenerator] is provided, it is used to generate the "event_id" | ||
| /// field instead of the built-in random UUID v4 generator. This is useful in | ||
| /// tests. | ||
| final UuidGenerator uuidGenerator; | ||
|
|
||
| const SentryOptions({ | ||
| @required this.dsn, | ||
| this.environmentAttributes, | ||
| this.compressPayload, | ||
| this.httpClient, | ||
| this.clock, | ||
| this.uuidGenerator, | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.