Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
- Added Scope and Breadcrumb ring buffer #109
- Added Hub to SDK #113
- Ref: Hub passes the Scope to SentryClient
- Feat: sentry options #116
- Feature: sentry options #116
- Ref: SentryId generates UUID
- Ref: Event now is SentryEvent and added GPU

# `package:sentry` changelog

Expand Down
4 changes: 2 additions & 2 deletions dart/example/event_example.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:sentry/src/protocol.dart';

final event = Event(
loggerName: 'main',
final event = SentryEvent(
logger: 'main',
serverName: 'server.dart',
release: '1.4.0-preview.1',
environment: 'Test',
Expand Down
8 changes: 0 additions & 8 deletions dart/lib/src/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:http/browser_client.dart';
import 'client.dart';
import 'protocol.dart';
import 'sentry_options.dart';
import 'utils.dart';
import 'version.dart';

SentryClient createSentryClient(SentryOptions options) =>
Expand All @@ -29,15 +28,8 @@ class SentryBrowserClient extends SentryClient {
///
/// If [httpClient] is provided, it is used instead of the default client to
/// make HTTP calls to Sentry.io. This is useful in tests.
///
/// 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).
factory SentryBrowserClient(SentryOptions options, {String origin}) {
options.httpClient ??= BrowserClient();
options.clock ??= getUtcDateTime;

// origin is necessary for sentry to resolve stacktrace
origin ??= '${window.location.origin}/';
Expand Down
36 changes: 17 additions & 19 deletions dart/lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import 'stack_trace.dart';
import 'utils.dart';
import 'version.dart';

/// Used to provide timestamp for logging.
typedef ClockProvider = DateTime Function();

/// Logs crash reports and events to the Sentry.io service.
abstract class SentryClient {
/// Creates a new platform appropriate client.
Expand All @@ -30,15 +27,7 @@ abstract class SentryClient {
Sdk sdk,
}) : _dsn = Dsn.parse(options.dsn),
_platform = platform ?? sdkPlatform,
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion) {
if (options.clock == null) {
options.clock = getUtcDateTime;
} else {
options.clock = (options.clock is ClockProvider
? options.clock
: options.clock.get) as ClockProvider;
}
}
sdk = sdk ?? Sdk(name: sdkName, version: sdkVersion);

final Dsn _dsn;

Expand Down Expand Up @@ -107,7 +96,7 @@ abstract class SentryClient {

/// Reports an [event] to Sentry.io.
Future<SentryId> captureEvent(
Event event, {
SentryEvent event, {
StackFrameFilter stackFrameFilter,
Scope scope,
}) async {
Expand All @@ -123,7 +112,7 @@ abstract class SentryClient {
final data = <String, dynamic>{
'project': projectId,
'event_id': event.eventId.toString(),
'timestamp': formatDateAsIso8601WithSecondPrecision(now),
'timestamp': formatDateAsIso8601WithSecondPrecision(event.timestamp),
};

if (options.environmentAttributes != null) {
Expand Down Expand Up @@ -162,11 +151,15 @@ abstract class SentryClient {
}

/// Reports the [throwable] and optionally its [stackTrace] to Sentry.io.
Future<SentryId> captureException(dynamic throwable,
{dynamic stackTrace, Scope scope}) {
final event = Event(
Future<SentryId> captureException(
dynamic throwable, {
dynamic stackTrace,
Scope scope,
}) {
final event = SentryEvent(
exception: throwable,
stackTrace: stackTrace,
timestamp: options.clock(),
);
return captureEvent(event, scope: scope);
}
Expand All @@ -179,9 +172,14 @@ abstract class SentryClient {
List<dynamic> params,
Scope scope,
}) {
final event = Event(
message: Message(formatted, template: template, params: params),
final event = SentryEvent(
message: Message(
formatted,
template: template,
params: params,
),
level: level,
timestamp: options.clock(),
);
return captureEvent(event, scope: scope);
}
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Hub {
SentryId get lastEventId => _lastEventId;

/// Captures the event.
Future<SentryId> captureEvent(Event event) async {
Future<SentryId> captureEvent(SentryEvent event) async {
var sentryId = SentryId.empty();

if (!_isEnabled) {
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:io';
import 'package:sentry/sentry.dart';

import 'client.dart';
import 'protocol.dart';

SentryClient createSentryClient(SentryOptions options) =>
SentryIOClient(options);
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/noop_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NoOpSentryClient implements SentryClient {
Map<String, String> buildHeaders(String authHeader) => {};

@override
Future<SentryId> captureEvent(Event event, {stackFrameFilter, scope}) =>
Future<SentryId> captureEvent(SentryEvent event, {stackFrameFilter, scope}) =>
Future.value(SentryId.empty());

@override
Expand Down
5 changes: 3 additions & 2 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:async';

import 'client.dart';
import 'hub.dart';
import 'protocol/event.dart';
import 'protocol/sentry_event.dart';
import 'protocol/sentry_level.dart';
import 'protocol/sentry_id.dart';

Expand All @@ -19,7 +19,8 @@ class NoOpHub implements Hub {
void bindClient(SentryClient client) {}

@override
Future<SentryId> captureEvent(Event event) => Future.value(SentryId.empty());
Future<SentryId> captureEvent(SentryEvent event) =>
Future.value(SentryId.empty());

@override
Future<SentryId> captureException(throwable, {stackTrace}) =>
Expand Down
2 changes: 1 addition & 1 deletion dart/lib/src/protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export 'protocol/browser.dart';
export 'protocol/contexts.dart';
export 'protocol/device.dart';
export 'protocol/dsn.dart';
export 'protocol/event.dart';
export 'protocol/sentry_event.dart';
export 'protocol/sentry_level.dart';
export 'protocol/message.dart';
export 'protocol/package.dart';
Expand Down
12 changes: 12 additions & 0 deletions dart/lib/src/protocol/contexts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '../protocol.dart';
import 'app.dart';
import 'browser.dart';
import 'device.dart';
import 'gpu.dart';
import 'runtime.dart';

/// The context interfaces provide additional context data.
Expand All @@ -17,6 +18,7 @@ class Contexts {
this.runtimes,
this.app,
this.browser,
this.gpu,
});

/// This describes the device that caused the event.
Expand Down Expand Up @@ -48,6 +50,11 @@ class Contexts {
/// agent of a web request that triggered the event.
final Browser browser;

/// GPU context describes the GPU of the device.
final Gpu gpu;

// TODO: contexts should accept arbitrary values

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
Expand All @@ -73,6 +80,11 @@ class Contexts {
json['browser'] = browserMap;
}

Map<String, dynamic> gpuMap;
if (gpu != null && (gpuMap = gpu.toJson()).isNotEmpty) {
json['gpu'] = gpuMap;
}

if (runtimes != null) {
if (runtimes.length == 1) {
final runtime = runtimes[0];
Expand Down
95 changes: 95 additions & 0 deletions dart/lib/src/protocol/gpu.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// https://develop.sentry.dev/sdk/event-payloads/contexts/#gpu-context
// Example:
// "gpu": {
// "name": "AMD Radeon Pro 560",
// "vendor_name": "Apple",
// "memory_size": 4096,
// "api_type": "Metal",
// "multi_threaded_rendering": true,
// "version": "Metal",
// "npot_support": "Full"
// }

class Gpu {
/// The name of the graphics device.
final String name;

/// The PCI identifier of the graphics device.
final int id;

/// The PCI vendor identifier of the graphics device.
final int vendorId;

/// The vendor name as reported by the graphics device.
final String vendorName;

/// The total GPU memory available in Megabytes.
final int memorySize;

/// The device low-level API type.
final String apiType;

/// Whether the GPU has multi-threaded rendering or not.
final bool multiThreadedRendering;

/// The Version of the graphics device.
final String version;

/// The Non-Power-Of-Two-Support support.
final String npotSupport;

const Gpu({
this.name,
this.id,
this.vendorId,
this.vendorName,
this.memorySize,
this.apiType,
this.multiThreadedRendering,
this.version,
this.npotSupport,
});

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};

if (name != null) {
json['name'] = name;
}

if (id != null) {
json['id'] = id;
}

if (vendorId != null) {
json['vendor_id'] = vendorId;
}

if (vendorName != null) {
json['vendor_name'] = vendorName;
}

if (memorySize != null) {
json['memory_size'] = memorySize;
}

if (apiType != null) {
json['api_type'] = apiType;
}

if (multiThreadedRendering != null) {
json['multi_threaded_rendering'] = multiThreadedRendering;
}

if (version != null) {
json['version'] = version;
}

if (npotSupport != null) {
json['npot_support'] = npotSupport;
}

return json;
}
}
Loading