Skip to content

Commit

Permalink
Merge branch 'main' into feat/database-breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Sep 25, 2023
2 parents 347b8f4 + 21f1bf7 commit 12f0b6d
Show file tree
Hide file tree
Showing 9 changed files with 16,797 additions and 16,072 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## Unreleased

### Features

- Breadcrumbs for file I/O operations ([#1649](https://github.com/getsentry/sentry-dart/pull/1649))

### Dependencies

- Enable compatibility with uuid v4 ([#1647](https://github.com/getsentry/sentry-dart/pull/1647))
- Bump Cocoa SDK from v8.11.0 to v8.12.0 ([#1650](https://github.com/getsentry/sentry-dart/pull/1650))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#8120)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/8.11.0...8.12.0)

## 7.10.1

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
http: '>=0.13.0 <2.0.0'
meta: ^1.3.0
stack_trace: ^1.10.0
uuid: ^3.0.0
uuid: '>=3.0.0 <5.0.0'

dev_dependencies:
mockito: ^5.1.0
Expand Down
32 changes: 30 additions & 2 deletions file/lib/src/sentry_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ import 'version.dart';
typedef Callback<T> = FutureOr<T> Function();

/// The Sentry wrapper for the File IO implementation that creates a span
/// out of the active transaction in the scope.
/// out of the active transaction in the scope and a breadcrumb, which gets
/// added to the hub.
/// The span is started before the operation is executed and finished after.
/// The File tracing isn't available for Web.
///
Expand All @@ -228,7 +229,7 @@ typedef Callback<T> = FutureOr<T> Function();
/// final sentryFile = SentryFile(file);
/// // span starts
/// await sentryFile.writeAsString('Hello World');
/// // span finishes
/// // span finishes, adds breadcrumb
/// ```
///
/// All the copy, create, delete, open, rename, read, and write operations are
Expand Down Expand Up @@ -425,8 +426,13 @@ class SentryFile implements File {

span?.origin = SentryTraceOrigins.autoFile;
span?.setData('file.async', true);

final Map<String, dynamic> breadcrumbData = {};
breadcrumbData['file.async'] = true;

if (_hub.options.sendDefaultPii) {
span?.setData('file.path', absolute.path);
breadcrumbData['file.path'] = absolute.path;
}
T data;
try {
Expand All @@ -453,6 +459,7 @@ class SentryFile implements File {

if (length != null) {
span?.setData('file.size', length);
breadcrumbData['file.size'] = length;
}

span?.status = SpanStatus.ok();
Expand All @@ -462,6 +469,14 @@ class SentryFile implements File {
rethrow;
} finally {
await span?.finish();

await _hub.addBreadcrumb(
Breadcrumb(
message: desc,
data: breadcrumbData,
category: operation,
),
);
}
return data;
}
Expand All @@ -475,8 +490,12 @@ class SentryFile implements File {
span?.origin = SentryTraceOrigins.autoFile;
span?.setData('file.async', false);

final Map<String, dynamic> breadcrumbData = {};
breadcrumbData['file.async'] = false;

if (_hub.options.sendDefaultPii) {
span?.setData('file.path', absolute.path);
breadcrumbData['file.path'] = absolute.path;
}

T data;
Expand Down Expand Up @@ -504,6 +523,7 @@ class SentryFile implements File {

if (length != null) {
span?.setData('file.size', length);
breadcrumbData['file.size'] = length;
}

span?.status = SpanStatus.ok();
Expand All @@ -513,6 +533,14 @@ class SentryFile implements File {
rethrow;
} finally {
span?.finish();

_hub.addBreadcrumb(
Breadcrumb(
message: desc,
data: breadcrumbData,
category: operation,
),
);
}
return data;
}
Expand Down
5 changes: 3 additions & 2 deletions file/test/mock_sentry_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class MockSentryClient with NoSuchMethodProvider implements SentryClient {
SentryTraceContextHeader? traceContext,
}) async {
captureTransactionCalls
.add(CaptureTransactionCall(transaction, traceContext));
.add(CaptureTransactionCall(transaction, traceContext, scope));
return transaction.eventId;
}
}

class CaptureTransactionCall {
final SentryTransaction transaction;
final SentryTraceContextHeader? traceContext;
final Scope? scope;

CaptureTransactionCall(this.transaction, this.traceContext);
CaptureTransactionCall(this.transaction, this.traceContext, this.scope);
}
Loading

0 comments on commit 12f0b6d

Please sign in to comment.