Skip to content

Commit 24e8131

Browse files
authored
Auto Transactions (#643)
1 parent 336a5fd commit 24e8131

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+700
-159
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
* Feat: Automatically create transactions when navigating between screens (#643)
34
# 6.2.2
45

56
* Fix: ConcurrentModificationError in when finishing span (#664)

dart/lib/src/hub.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:collection';
33

44
import 'package:meta/meta.dart';
55

6-
import 'noop_sentry_span.dart';
76
import 'protocol.dart';
87
import 'scope.dart';
98
import 'sentry_client.dart';
@@ -340,6 +339,8 @@ class Hub {
340339
String operation, {
341340
String? description,
342341
bool? bindToScope,
342+
bool? waitForChildren,
343+
Duration? autoFinishAfter,
343344
Map<String, dynamic>? customSamplingContext,
344345
}) =>
345346
startTransactionWithContext(
@@ -349,6 +350,8 @@ class Hub {
349350
description: description,
350351
),
351352
bindToScope: bindToScope,
353+
waitForChildren: waitForChildren,
354+
autoFinishAfter: autoFinishAfter,
352355
customSamplingContext: customSamplingContext,
353356
);
354357

@@ -357,6 +360,8 @@ class Hub {
357360
SentryTransactionContext transactionContext, {
358361
Map<String, dynamic>? customSamplingContext,
359362
bool? bindToScope,
363+
bool? waitForChildren,
364+
Duration? autoFinishAfter,
360365
}) {
361366
if (!_isEnabled) {
362367
_options.logger(
@@ -380,8 +385,12 @@ class Hub {
380385
transactionContext = transactionContext.copyWith(sampled: sampled);
381386
}
382387

383-
final tracer = SentryTracer(transactionContext, this);
384-
388+
final tracer = SentryTracer(
389+
transactionContext,
390+
this,
391+
waitForChildren: waitForChildren ?? false,
392+
autoFinishAfter: autoFinishAfter,
393+
);
385394
if (bindToScope ?? false) {
386395
item.scope.span = tracer;
387396
}

dart/lib/src/hub_adapter.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ class HubAdapter implements Hub {
102102
SentryTransactionContext transactionContext, {
103103
Map<String, dynamic>? customSamplingContext,
104104
bool? bindToScope,
105+
bool? waitForChildren,
106+
Duration? autoFinishAfter,
105107
}) =>
106108
Sentry.startTransactionWithContext(
107109
transactionContext,
108110
customSamplingContext: customSamplingContext,
109111
bindToScope: bindToScope,
112+
waitForChildren: waitForChildren,
113+
autoFinishAfter: autoFinishAfter,
110114
);
111115

112116
@override
@@ -115,13 +119,17 @@ class HubAdapter implements Hub {
115119
String operation, {
116120
String? description,
117121
bool? bindToScope,
122+
bool? waitForChildren,
123+
Duration? autoFinishAfter,
118124
Map<String, dynamic>? customSamplingContext,
119125
}) =>
120126
Sentry.startTransaction(
121127
name,
122128
operation,
123129
description: description,
124130
bindToScope: bindToScope,
131+
waitForChildren: waitForChildren,
132+
autoFinishAfter: autoFinishAfter,
125133
customSamplingContext: customSamplingContext,
126134
);
127135

dart/lib/src/noop_hub.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'protocol.dart';
44
import 'sentry_client.dart';
55
import 'sentry_user_feedback.dart';
66
import 'tracing.dart';
7-
import 'noop_sentry_span.dart';
87

98
class NoOpHub implements Hub {
109
NoOpHub._();
@@ -79,6 +78,8 @@ class NoOpHub implements Hub {
7978
String operation, {
8079
String? description,
8180
bool? bindToScope,
81+
bool? waitForChildren,
82+
Duration? autoFinishAfter,
8283
Map<String, dynamic>? customSamplingContext,
8384
}) =>
8485
NoOpSentrySpan();
@@ -88,6 +89,8 @@ class NoOpHub implements Hub {
8889
SentryTransactionContext transactionContext, {
8990
Map<String, dynamic>? customSamplingContext,
9091
bool? bindToScope,
92+
bool? waitForChildren,
93+
Duration? autoFinishAfter,
9194
}) =>
9295
NoOpSentrySpan();
9396

dart/lib/src/protocol/breadcrumb.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:meta/meta.dart';
22

33
import '../utils.dart';
4-
import 'sentry_level.dart';
54
import '../protocol.dart';
65

76
/// Structed data to describe more information pior to the event captured.

dart/lib/src/protocol/sentry_span.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import '../hub.dart';
24
import '../protocol.dart';
35

@@ -17,6 +19,7 @@ class SentrySpan extends ISentrySpan {
1719

1820
SpanStatus? _status;
1921
final Map<String, String> _tags = {};
22+
void Function()? _finishedCallback;
2023

2124
@override
2225
bool? sampled;
@@ -26,8 +29,10 @@ class SentrySpan extends ISentrySpan {
2629
this._context,
2730
this._hub, {
2831
bool? sampled,
32+
Function()? finishedCallback,
2933
}) {
3034
this.sampled = sampled;
35+
_finishedCallback = finishedCallback;
3136
}
3237

3338
@override
@@ -45,6 +50,8 @@ class SentrySpan extends ISentrySpan {
4550
if (_throwable != null) {
4651
_hub.setSpanContext(_throwable, this, _tracer.name);
4752
}
53+
_finishedCallback?.call();
54+
await super.finish(status: status);
4855
}
4956

5057
@override

dart/lib/src/protocol/sentry_transaction.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:meta/meta.dart';
22

33
import '../protocol.dart';
44
import '../sentry_tracer.dart';
5-
import 'sentry_span.dart';
65
import '../utils.dart';
76

87
@immutable

dart/lib/src/sentry.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,17 @@ class Sentry {
229229
String operation, {
230230
String? description,
231231
bool? bindToScope,
232+
bool? waitForChildren,
233+
Duration? autoFinishAfter,
232234
Map<String, dynamic>? customSamplingContext,
233235
}) =>
234236
_hub.startTransaction(
235237
name,
236238
operation,
237239
description: description,
238240
bindToScope: bindToScope,
241+
waitForChildren: waitForChildren,
242+
autoFinishAfter: autoFinishAfter,
239243
customSamplingContext: customSamplingContext,
240244
);
241245

@@ -244,11 +248,15 @@ class Sentry {
244248
SentryTransactionContext transactionContext, {
245249
Map<String, dynamic>? customSamplingContext,
246250
bool? bindToScope,
251+
bool? waitForChildren,
252+
Duration? autoFinishAfter,
247253
}) =>
248254
_hub.startTransactionWithContext(
249255
transactionContext,
250256
customSamplingContext: customSamplingContext,
251257
bindToScope: bindToScope,
258+
waitForChildren: waitForChildren,
259+
autoFinishAfter: autoFinishAfter,
252260
);
253261

254262
/// Gets the current active transaction or span.

dart/lib/src/sentry_envelope.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import 'utils.dart';
66
import 'sentry_attachment/sentry_attachment.dart';
77
import 'sentry_envelope_header.dart';
88
import 'sentry_envelope_item.dart';
9-
import 'protocol/sentry_event.dart';
10-
import 'protocol/sdk_version.dart';
119
import 'sentry_user_feedback.dart';
1210

1311
/// Class representation of `Envelope` file.

dart/lib/src/sentry_envelope_item.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'protocol.dart';
33
import 'utils.dart';
44
import 'sentry_attachment/sentry_attachment.dart';
55
import 'sentry_item_type.dart';
6-
import 'protocol/sentry_event.dart';
76
import 'sentry_envelope_item_header.dart';
87
import 'sentry_user_feedback.dart';
98

0 commit comments

Comments
 (0)