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 idle timer to tracer, only start transaction if scope is not setโ€ฆ
โ€ฆ already
  • Loading branch information
Denis Andraลกec authored and Denis Andraลกec committed Nov 30, 2021
commit 75fa0434da7128be8ef3bb3cda9afda7268695c3
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 operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) =>
startTransactionWithContext(
Expand All @@ -357,6 +358,7 @@ class Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
Duration? idleFinishDuration,
}) {
if (!_isEnabled) {
_options.logger(
Expand All @@ -380,8 +382,13 @@ class Hub {
transactionContext = transactionContext.copyWith(sampled: sampled);
}

final tracer = SentryTracer(transactionContext, this);

final tracer = SentryTracer(
transactionContext,
this,
);
if (idleFinishDuration != null) {
tracer.finishAfterIdleTime(idleFinishDuration);
}
if (bindToScope ?? false) {
item.scope.span = tracer;
}
Expand Down
2 changes: 2 additions & 0 deletions dart/lib/src/hub_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class HubAdapter implements Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
Duration? idleFinishDuration,
}) =>
Sentry.startTransactionWithContext(
transactionContext,
Expand All @@ -115,6 +116,7 @@ class HubAdapter implements Hub {
String operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) =>
Sentry.startTransaction(
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 operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) =>
NoOpSentrySpan();
Expand All @@ -88,6 +89,7 @@ class NoOpHub implements Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
Duration? idleFinishDuration,
}) =>
NoOpSentrySpan();

Expand Down
14 changes: 14 additions & 0 deletions dart/lib/src/sentry_tracer.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:meta/meta.dart';

import '../sentry.dart';
Expand All @@ -12,6 +14,7 @@ class SentryTracer extends ISentrySpan {
late final SentrySpan _rootSpan;
final List<SentrySpan> _children = [];
final Map<String, String> _extra = {};
Timer? _idleTimer;

SentryTracer(SentryTransactionContext transactionContext, this._hub) {
_rootSpan = SentrySpan(
Expand All @@ -23,8 +26,19 @@ class SentryTracer extends ISentrySpan {
name = transactionContext.name;
}

void finishAfterIdleTime(Duration time) {
_idleTimer = Timer(time, () async {
SpanStatus? status;
if (_rootSpan.status == null) {
status = SpanStatus.ok();
}
await finish(status: status);
});
}

@override
Future<void> finish({SpanStatus? status}) async {
_idleTimer?.cancel();
await _rootSpan.finish(status: status);

// finish unfinished spans otherwise transaction gets dropped
Expand Down
8 changes: 5 additions & 3 deletions dart/test/default_integrations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ class PrintRecursionMockHub extends MockHub {

@override
ISentrySpan startTransactionWithContext(
SentryTransactionContext transactionContext,
{Map<String, dynamic>? customSamplingContext,
bool? bindToScope}) {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
Duration? idleFinishDuration,
}) {
return NoOpSentrySpan();
}
}
2 changes: 2 additions & 0 deletions dart/test/mocks/mock_hub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class MockHub implements Hub {
String operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) {
return NoOpSentrySpan();
Expand All @@ -137,6 +138,7 @@ class MockHub implements Hub {
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
bool? bindToScope,
Duration? idleFinishDuration,
}) {
return NoOpSentrySpan();
}
Expand Down
9 changes: 9 additions & 0 deletions dart/test/sentry_tracer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ void main() {
expect(sut.toSentryTrace().value,
'${sut.context.traceId}-${sut.context.spanId}-1');
});

test('tracer finishes after idle time', () async {
final sut = fixture.getSut();
sut.finishAfterIdleTime(Duration(milliseconds: 200));

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

class Fixture {
Expand Down
28 changes: 15 additions & 13 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
final bool _setRouteNameAsTransaction;

ISentrySpan? _transaction;
Timer? _idleTimer;

@override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
Expand Down Expand Up @@ -90,7 +89,9 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
);
_finishTransaction();
_startTransaction(
previousRoute?.settings.name, previousRoute?.settings.arguments);
previousRoute?.settings.name,
previousRoute?.settings.arguments,
);
}

void _addBreadcrumb({
Expand Down Expand Up @@ -123,21 +124,22 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
if (name == null) {
return;
}
_transaction = _hub.startTransaction(
name,
'ui.load',
bindToScope: true,
);
if (arguments != null) {
_transaction?.setData('route_settings_arguments', arguments);
}
_idleTimer = Timer(Duration(seconds: 3), () async {
await _finishTransaction();
_hub.configureScope((scope) {
if (scope.span == null) {
_transaction = _hub.startTransaction(
name,
'ui.load',
bindToScope: true,
idleFinishDuration: Duration(seconds: 3),
);
if (arguments != null) {
_transaction?.setData('route_settings_arguments', arguments);
}
}
});
}

Future<void> _finishTransaction() async {
_idleTimer?.cancel();
_transaction?.status ??= SpanStatus.ok();
return await _transaction?.finish();
}
Expand Down
3 changes: 3 additions & 0 deletions flutter/test/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ISentrySpan startTransactionShim(
String? operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) {
return MockNoOpSentrySpan();
Expand Down Expand Up @@ -187,6 +188,7 @@ class NoOpHub implements Hub {
String operation, {
String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext,
}) {
return NoOpSentrySpan();
Expand All @@ -196,6 +198,7 @@ class NoOpHub implements Hub {
ISentrySpan startTransactionWithContext(
SentryTransactionContext transactionContext, {
Map<String, dynamic>? customSamplingContext,
Duration? idleFinishDuration,
bool? bindToScope,
}) {
return NoOpSentrySpan();
Expand Down
9 changes: 7 additions & 2 deletions flutter/test/mocks.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class MockHub extends _i1.Mock implements _i4.Hub {
_i2.ISentrySpan startTransaction(String? name, String? operation,
{String? description,
bool? bindToScope,
Duration? idleFinishDuration,
Map<String, dynamic>? customSamplingContext}) =>
(super.noSuchMethod(
Invocation.method(#startTransaction, [
Expand All @@ -216,24 +217,28 @@ class MockHub extends _i1.Mock implements _i4.Hub {
], {
#description: description,
#bindToScope: bindToScope,
#idleFinishDuration: idleFinishDuration,
#customSamplingContext: customSamplingContext
}),
returnValue: _i10.startTransactionShim(name, operation,
description: description,
bindToScope: bindToScope,
idleFinishDuration: idleFinishDuration,
customSamplingContext: customSamplingContext))
as _i2.ISentrySpan);
@override
_i2.ISentrySpan startTransactionWithContext(
_i2.SentryTransactionContext? transactionContext,
{Map<String, dynamic>? customSamplingContext,
bool? bindToScope}) =>
bool? bindToScope,
Duration? idleFinishDuration}) =>
(super.noSuchMethod(
Invocation.method(#startTransactionWithContext, [
transactionContext
], {
#customSamplingContext: customSamplingContext,
#bindToScope: bindToScope
#bindToScope: bindToScope,
#idleFinishDuration: idleFinishDuration
}),
returnValue: _FakeISentrySpan_2()) as _i2.ISentrySpan);
@override
Expand Down
Loading