Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5c87477
didPush starts transaction
Nov 24, 2021
e72ccc6
didPush finishes previous transaction
Nov 24, 2021
ff0896e
fix mocking
Nov 25, 2021
adde75d
test finish with idle timer
Nov 25, 2021
7a0c96b
finish transaction on pop
Nov 25, 2021
0f79e44
check if span status is set
Nov 25, 2021
0bbce7a
test setting of arguments
Nov 25, 2021
45186fe
format
Nov 25, 2021
deef4a9
re-start previous
Nov 25, 2021
1e204c0
dont start transaction with empty name
Nov 25, 2021
0dd396c
dont expose options
Nov 25, 2021
998ee18
Update changelog
Nov 25, 2021
c3c7de8
provide opt-out of auto transactions
Nov 26, 2021
5406ad4
run format
Nov 26, 2021
75fa043
move idle timer to tracer, only start transaction if scope is not setโ€ฆ
Nov 30, 2021
f7b8417
implement waitForChildren
Nov 30, 2021
e5276c0
move finishAfter to ISentrySpan
Nov 30, 2021
97533fc
expose waitForChildren api
Dec 1, 2021
6161cb0
move finishAfter implementation out of abstract class
Dec 1, 2021
e5f8c7e
Merge branch 'main' into feat/auto-transactions
Dec 1, 2021
c003afc
add missing tests for callback on finish
Dec 1, 2021
5656aa6
move SentryTracerFinishStatus to own file
Dec 1, 2021
941d854
run format
Dec 1, 2021
3456911
propagate waitForChildren
Dec 1, 2021
c32a413
only bind to scope if scope span is null
Dec 3, 2021
5b791ad
format
Dec 3, 2021
90c6de3
Merge branch 'main' into feat/auto-transactions
Dec 3, 2021
22a395f
move finifhed callback to SentrySpan ctor
Dec 9, 2021
96b4a5c
update doc for enableAutoTransactions
Dec 9, 2021
762cf12
Merge branch 'main' into feat/auto-transactions
Dec 9, 2021
28bc711
remove unneccesary imports
Dec 9, 2021
c43b04b
Merge branch 'main' into feat/auto-transactions
Dec 14, 2021
ef633a0
dont call super in noop method
Dec 14, 2021
7817a28
move auto finish after duration to start transactions as param
Dec 14, 2021
835fbd3
Remove unused param
Dec 15, 2021
8bb14a4
return immed.
Dec 15, 2021
9ab1b87
Merge branch 'main' into feat/auto-transactions
Dec 15, 2021
25c1a81
Merge branch 'main' into feat/auto-transactions
Dec 15, 2021
7cdf854
no need to double check finished
Dec 15, 2021
2251af2
use more descriptive changelog
Dec 15, 2021
2f268a3
use current span instead of new transaction for sample
marandaneto Dec 15, 2021
3063a14
fix
marandaneto Dec 15, 2021
b369fc2
fix test
marandaneto Dec 15, 2021
4d8e600
fix tests
marandaneto Dec 15, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Feat: Automatically create transactions when navigating between screens (#643)
# 6.2.2

* Fix: ConcurrentModificationError in when finishing span (#664)
Expand Down
15 changes: 12 additions & 3 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:collection';

import 'package:meta/meta.dart';

import 'noop_sentry_span.dart';
import 'protocol.dart';
import 'scope.dart';
import 'sentry_client.dart';
Expand Down Expand Up @@ -340,6 +339,8 @@ class Hub {
String operation, {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
startTransactionWithContext(
Expand All @@ -349,6 +350,8 @@ class Hub {
description: description,
),
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

Expand All @@ -357,6 +360,8 @@ class Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) {
if (!_isEnabled) {
_options.logger(
Expand All @@ -380,8 +385,12 @@ class Hub {
transactionContext = transactionContext.copyWith(sampled: sampled);
}

final tracer = SentryTracer(transactionContext, this);

final tracer = SentryTracer(
transactionContext,
this,
waitForChildren: waitForChildren ?? false,
autoFinishAfter: autoFinishAfter,
);
if (bindToScope ?? false) {
item.scope.span = tracer;
}
Expand Down
8 changes: 8 additions & 0 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,15 @@ class HubAdapter implements Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) =>
Sentry.startTransactionWithContext(
transactionContext,
customSamplingContext: customSamplingContext,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
);

@override
Expand All @@ -115,13 +119,17 @@ class HubAdapter implements Hub {
String operation, {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
Sentry.startTransaction(
name,
operation,
description: description,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

Expand Down
5 changes: 4 additions & 1 deletion dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'protocol.dart';
import 'sentry_client.dart';
import 'sentry_user_feedback.dart';
import 'tracing.dart';
import 'noop_sentry_span.dart';

class NoOpHub implements Hub {
NoOpHub._();
Expand Down Expand Up @@ -79,6 +78,8 @@ class NoOpHub implements Hub {
String operation, {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
NoOpSentrySpan();
Expand All @@ -88,6 +89,8 @@ class NoOpHub implements Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) =>
NoOpSentrySpan();

Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/protocol/breadcrumb.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:meta/meta.dart';

import '../utils.dart';
import 'sentry_level.dart';
import '../protocol.dart';

/// Structed data to describe more information pior to the event captured.
Expand Down
7 changes: 7 additions & 0 deletions dart/lib/src/protocol/sentry_span.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import '../hub.dart';
import '../protocol.dart';

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

SpanStatus? _status;
final Map<String, String> _tags = {};
void Function()? _finishedCallback;

@override
bool? sampled;
Expand All @@ -26,8 +29,10 @@ class SentrySpan extends ISentrySpan {
this._context,
this._hub, {
bool? sampled,
Function()? finishedCallback,
}) {
this.sampled = sampled;
_finishedCallback = finishedCallback;
}

@override
Expand All @@ -45,6 +50,8 @@ class SentrySpan extends ISentrySpan {
if (_throwable != null) {
_hub.setSpanContext(_throwable, this, _tracer.name);
}
_finishedCallback?.call();
await super.finish(status: status);
}

@override
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/protocol/sentry_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:meta/meta.dart';

import '../protocol.dart';
import '../sentry_tracer.dart';
import 'sentry_span.dart';
import '../utils.dart';

@immutable
Expand Down
8 changes: 8 additions & 0 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ class Sentry {
String operation, {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
_hub.startTransaction(
name,
operation,
description: description,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

Expand All @@ -244,11 +248,15 @@ class Sentry {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) =>
_hub.startTransactionWithContext(
transactionContext,
customSamplingContext: customSamplingContext,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
);

/// Gets the current active transaction or span.
Expand Down
2 changes: 0 additions & 2 deletions dart/lib/src/sentry_envelope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'utils.dart';
import 'sentry_attachment/sentry_attachment.dart';
import 'sentry_envelope_header.dart';
import 'sentry_envelope_item.dart';
import 'protocol/sentry_event.dart';
import 'protocol/sdk_version.dart';
import 'sentry_user_feedback.dart';

/// Class representation of `Envelope` file.
Expand Down
1 change: 0 additions & 1 deletion dart/lib/src/sentry_envelope_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'protocol.dart';
import 'utils.dart';
import 'sentry_attachment/sentry_attachment.dart';
import 'sentry_item_type.dart';
import 'protocol/sentry_event.dart';
import 'sentry_envelope_item_header.dart';
import 'sentry_user_feedback.dart';

Expand Down
4 changes: 1 addition & 3 deletions dart/lib/src/sentry_span_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ abstract class ISentrySpan {
void removeData(String key);

/// Sets span timestamp marking this span as finished.
Future<void> finish({
SpanStatus? status,
});
Future<void> finish({SpanStatus? status}) async {}

/// Gets span status.
SpanStatus? get status;
Expand Down
90 changes: 56 additions & 34 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
@@ -1,52 +1,65 @@
import 'dart:async';

import 'package:meta/meta.dart';

import '../sentry.dart';
import 'sentry_tracer_finish_status.dart';

@internal
class SentryTracer extends ISentrySpan {
final Hub _hub;
late bool _waitForChildren;
late String name;

// missing waitForChildren

late final SentrySpan _rootSpan;
final List<SentrySpan> _children = [];
final Map<String, String> _extra = {};
Timer? _autoFinishAfterTimer;
var _finishStatus = SentryTracerFinishStatus.notFinishing();

SentryTracer(SentryTransactionContext transactionContext, this._hub) {
SentryTracer(SentryTransactionContext transactionContext, this._hub,
{bool waitForChildren = false, Duration? autoFinishAfter}) {
_rootSpan = SentrySpan(
this,
transactionContext,
_hub,
sampled: transactionContext.sampled,
);
_waitForChildren = waitForChildren;
if (autoFinishAfter != null) {
_autoFinishAfterTimer = Timer(autoFinishAfter, () async {
await finish(status: status ?? SpanStatus.ok());
});
}
name = transactionContext.name;
}

@override
Future<void> finish({SpanStatus? status}) async {
if (finished) {
return;
}

await _rootSpan.finish(status: status);

// finish unfinished spans otherwise transaction gets dropped
for (final span in _children) {
if (!span.finished) {
await span.finish(status: SpanStatus.deadlineExceeded());
_autoFinishAfterTimer?.cancel();
_finishStatus = SentryTracerFinishStatus.finishing(status);
if (!_rootSpan.finished &&
(!_waitForChildren || _haveAllChildrenFinished())) {
_rootSpan.status ??= status;
await _rootSpan.finish();

// finish unfinished spans otherwise transaction gets dropped
for (final span in _children) {
if (!span.finished) {
await span.finish(status: SpanStatus.deadlineExceeded());
}
}
}

// remove from scope
_hub.configureScope((scope) {
if (scope.span == this) {
scope.span = null;
}
});
// remove from scope
_hub.configureScope((scope) {
if (scope.span == this) {
scope.span = null;
}
});

final transaction = SentryTransaction(this);
await _hub.captureTransaction(transaction);
final transaction = SentryTransaction(this);
await _hub.captureTransaction(transaction);
}
}

@override
Expand Down Expand Up @@ -110,18 +123,18 @@ class SentryTracer extends ISentrySpan {
}

final context = SentrySpanContext(
traceId: _rootSpan.context.traceId,
parentSpanId: parentSpanId,
operation: operation,
description: description,
);

final child = SentrySpan(
this,
context,
_hub,
sampled: _rootSpan.sampled,
);
traceId: _rootSpan.context.traceId,
parentSpanId: parentSpanId,
operation: operation,
description: description);

final child = SentrySpan(this, context, _hub, sampled: _rootSpan.sampled,
finishedCallback: () {
final finishStatus = _finishStatus;
if (finishStatus.finishing) {
finish(status: finishStatus.status);
}
});

_children.add(child);

Expand Down Expand Up @@ -163,4 +176,13 @@ class SentryTracer extends ISentrySpan {

@override
SentryTraceHeader toSentryTrace() => _rootSpan.toSentryTrace();

bool _haveAllChildrenFinished() {
for (final child in children) {
if (!child.finished) {
return false;
}
}
return true;
}
}
17 changes: 17 additions & 0 deletions dart/lib/src/sentry_tracer_finish_status.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:meta/meta.dart';

import '../sentry.dart';

@internal
class SentryTracerFinishStatus {
final bool finishing;
final SpanStatus? status;

SentryTracerFinishStatus.finishing(SpanStatus? status)
: finishing = true,
status = status;

SentryTracerFinishStatus.notFinishing()
: finishing = false,
status = null;
}
1 change: 0 additions & 1 deletion dart/lib/src/sentry_traces_sampler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:math';
import 'package:meta/meta.dart';

import '../sentry.dart';
import 'tracing.dart';

@internal
class SentryTracesSampler {
Expand Down
1 change: 0 additions & 1 deletion dart/test/contexts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/protocol/sentry_gpu.dart';
import 'package:test/test.dart';

void main() {
Expand Down
Loading