Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move auto finish after duration to start transactions as param
  • Loading branch information
Denis Andraลกec authored and Denis Andraลกec committed Dec 14, 2021
commit 7817a285a69007d8064eab2c6f3f40ee5d1f1adb
11 changes: 9 additions & 2 deletions dart/lib/src/hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class Hub {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
startTransactionWithContext(
Expand All @@ -350,6 +351,7 @@ class Hub {
),
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

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

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

@override
Expand All @@ -118,6 +120,7 @@ class HubAdapter implements Hub {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
Sentry.startTransaction(
Expand All @@ -126,6 +129,7 @@ class HubAdapter implements Hub {
description: description,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/noop_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class NoOpHub implements Hub {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
NoOpSentrySpan();
Expand All @@ -89,6 +90,7 @@ class NoOpHub implements Hub {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) =>
NoOpSentrySpan();

Expand Down
11 changes: 1 addition & 10 deletions dart/lib/src/protocol/sentry_span.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class SentrySpan extends ISentrySpan {

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

@override
Expand All @@ -37,8 +36,7 @@ class SentrySpan extends ISentrySpan {
}

@override
Future<void> finish({SpanStatus? status}) async {
_finishAfterTimer?.cancel();
Future<void> finish({SpanStatus? status, Duration? autoFinishAfter}) async {
if (status != null) {
_status = status;
}
Expand All @@ -52,13 +50,6 @@ class SentrySpan extends ISentrySpan {
await super.finish(status: status);
}

@override
void finishAfter(Duration duration, {SpanStatus? status}) {
_finishAfterTimer = Timer(duration, () async {
await finish(status: status);
});
}

@override
void removeData(String key) {
_data.remove(key);
Expand Down
4 changes: 4 additions & 0 deletions dart/lib/src/sentry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class Sentry {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) =>
_hub.startTransaction(
Expand All @@ -238,6 +239,7 @@ class Sentry {
description: description,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext,
);

Expand All @@ -247,12 +249,14 @@ class Sentry {
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
3 changes: 0 additions & 3 deletions dart/lib/src/sentry_span_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ abstract class ISentrySpan {
/// Sets span timestamp marking this span as finished.
Future<void> finish({SpanStatus? status}) async {}

/// Calls finish after the provided duration with the status parameter.
void finishAfter(Duration duration, {SpanStatus? status}) {}

/// Gets span status.
SpanStatus? get status;

Expand Down
18 changes: 8 additions & 10 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,29 @@ class SentryTracer extends ISentrySpan {
late final SentrySpan _rootSpan;
final List<SentrySpan> _children = [];
final Map<String, String> _extra = {};
Timer? _finishAfterTimer;
Timer? _autoFinishAfterTimer;
var _finishStatus = SentryTracerFinishStatus.notFinishing();

SentryTracer(SentryTransactionContext transactionContext, this._hub,
{bool waitForChildren = false}) {
{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 {
_finishAfterTimer?.cancel();
_autoFinishAfterTimer?.cancel();
_finishStatus = SentryTracerFinishStatus.finishing(status);
if (!_rootSpan.finished &&
(!_waitForChildren || _haveAllChildrenFinished())) {
Expand All @@ -57,13 +62,6 @@ class SentryTracer extends ISentrySpan {
}
}

@override
void finishAfter(Duration duration, {SpanStatus? status}) {
_finishAfterTimer = Timer(duration, () async {
await finish(status: status);
});
}

@override
void removeData(String key) {
_extra.remove(key);
Expand Down
1 change: 1 addition & 0 deletions dart/test/default_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class PrintRecursionMockHub extends MockHub {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) {
return NoOpSentrySpan();
}
Expand Down
2 changes: 2 additions & 0 deletions dart/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class MockHub implements Hub {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) {
return NoOpSentrySpan();
Expand All @@ -137,6 +138,7 @@ class MockHub implements Hub {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) {
return NoOpSentrySpan();
}
Expand Down
10 changes: 0 additions & 10 deletions dart/test/sentry_span_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ void main() {
'${sut.context.traceId}-${sut.context.spanId}-1');
});

test('finishes after duration', () async {
final sut = fixture.getSut();
sut.finishAfter(Duration(milliseconds: 200), status: SpanStatus.ok());

expect(sut.finished, false);
await Future.delayed(Duration(milliseconds: 210));
expect(sut.status, SpanStatus.ok());
expect(sut.finished, true);
});

test('callback called on finish', () async {
var numberOfCallbackCalls = 0;
final sut = fixture.getSut(finishedCallback: () {
Expand Down
13 changes: 9 additions & 4 deletions dart/test/sentry_tracer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ void main() {
'${sut.context.traceId}-${sut.context.spanId}-1');
});

test('tracer finishes after duration', () async {
final sut = fixture.getSut();
sut.finishAfter(Duration(milliseconds: 200), status: SpanStatus.ok());
test('tracer finishes after auto finish duration', () async {
final sut = fixture.getSut(autoFinishAfter: Duration(milliseconds: 200));

expect(sut.finished, false);
await Future.delayed(Duration(milliseconds: 210));
Expand Down Expand Up @@ -175,12 +174,18 @@ class Fixture {
SentryTracer getSut({
bool? sampled = true,
bool waitForChildren = false,
Duration? autoFinishAfter,
}) {
final context = SentryTransactionContext(
'name',
'op',
sampled: sampled,
);
return SentryTracer(context, hub, waitForChildren: waitForChildren);
return SentryTracer(
context,
hub,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
'ui.load',
bindToScope: scope.span == null,
waitForChildren: true,
autoFinishAfter: Duration(seconds: 3),
);
if (arguments != null) {
_transaction?.setData('route_settings_arguments', arguments);
}
_transaction?.finishAfter(Duration(seconds: 3), status: SpanStatus.ok());
});
}

Expand Down
3 changes: 3 additions & 0 deletions flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ISentrySpan startTransactionShim(
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) {
return MockNoOpSentrySpan();
Expand Down Expand Up @@ -187,6 +188,7 @@ class NoOpHub implements Hub {
String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext,
}) {
return NoOpSentrySpan();
Expand All @@ -198,6 +200,7 @@ class NoOpHub implements Hub {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
}) {
return NoOpSentrySpan();
}
Expand Down
21 changes: 12 additions & 9 deletions flutter/test/mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ class MockNoOpSentrySpan extends _i1.Mock implements _i2.NoOpSentrySpan {
super.noSuchMethod(Invocation.setter(#status, status),
returnValueForMissingStub: null);
@override
_i6.Future<void> finish({_i3.SpanStatus? status}) =>
(super.noSuchMethod(Invocation.method(#finish, [], {#status: status}),
_i6.Future<void> finish(
{_i3.SpanStatus? status, Duration? autoFinishAfter}) =>
(super.noSuchMethod(
Invocation.method(#finish, [],
{#status: status, #autoFinishAfter: autoFinishAfter}),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i6.Future<void>);
@override
Expand Down Expand Up @@ -115,11 +118,6 @@ class MockNoOpSentrySpan extends _i1.Mock implements _i2.NoOpSentrySpan {
(super.noSuchMethod(Invocation.method(#toSentryTrace, []),
returnValue: _FakeSentryTraceHeader_3()) as _i3.SentryTraceHeader);
@override
void finishAfter(Duration? duration, {_i3.SpanStatus? status}) =>
super.noSuchMethod(
Invocation.method(#finishAfter, [duration], {#status: status}),
returnValueForMissingStub: null);
@override
String toString() => super.toString();
}

Expand Down Expand Up @@ -214,6 +212,7 @@ class MockHub extends _i1.Mock implements _i4.Hub {
{String? description,
bool? bindToScope,
bool? waitForChildren,
Duration? autoFinishAfter,
Map<String, dynamic>? customSamplingContext}) =>
(super.noSuchMethod(
Invocation.method(#startTransaction, [
Expand All @@ -223,27 +222,31 @@ class MockHub extends _i1.Mock implements _i4.Hub {
#description: description,
#bindToScope: bindToScope,
#waitForChildren: waitForChildren,
#autoFinishAfter: autoFinishAfter,
#customSamplingContext: customSamplingContext
}),
returnValue: _i10.startTransactionShim(name, operation,
description: description,
bindToScope: bindToScope,
waitForChildren: waitForChildren,
autoFinishAfter: autoFinishAfter,
customSamplingContext: customSamplingContext))
as _i2.ISentrySpan);
@override
_i2.ISentrySpan startTransactionWithContext(
_i2.SentryTransactionContext? transactionContext,
{Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
bool? waitForChildren}) =>
bool? waitForChildren,
Duration? autoFinishAfter}) =>
(super.noSuchMethod(
Invocation.method(#startTransactionWithContext, [
transactionContext
], {
#customSamplingContext: customSamplingContext,
#bindToScope: bindToScope,
#waitForChildren: waitForChildren
#waitForChildren: waitForChildren,
#autoFinishAfter: autoFinishAfter
}),
returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan);
@override
Expand Down
Loading