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
Next Next commit
didPush starts transaction
  • Loading branch information
Denis Andraลกec authored and Denis Andraลกec committed Nov 24, 2021
commit 5c874775eebe7aec2fa685f91c45b0b0da397135
14 changes: 14 additions & 0 deletions flutter/lib/src/navigation/sentry_navigator_observer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {

final Hub _hub;
final bool _setRouteNameAsTransaction;
ISentrySpan? _transaction;

@override
void didPush(Route<dynamic> route, Route<dynamic>? previousRoute) {
Expand All @@ -54,6 +55,7 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
from: previousRoute?.settings,
to: route.settings,
);
_startTransaction(route.settings.name, route.settings.arguments);
}

@override
Expand Down Expand Up @@ -100,6 +102,18 @@ class SentryNavigatorObserver extends RouteObserver<PageRoute<dynamic>> {
});
}
}

void _startTransaction(String? name, Object? arguments) {
_transaction = _hub.startTransaction(
name ?? 'unknown',
'ui.load',
bindToScope: true,
);
if (arguments != null) {
_transaction?.setData('route_settings_arguments', arguments);
}
}

}

/// This class makes it easier to record breadcrumbs for events of Flutters
Expand Down
1 change: 1 addition & 0 deletions flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
package_info_plus: ^1.0.0

dev_dependencies:
build_runner: ^2.1.5
flutter_test:
sdk: flutter
mockito: ^5.0.16
Expand Down
125 changes: 89 additions & 36 deletions flutter/test/mocks.mocks.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
// Mocks generated by Mockito 5.0.7 from annotations
// in sentry_flutter/example/ios/.symlinks/plugins/sentry_flutter/test/mocks.dart.
// Mocks generated by Mockito 5.0.16 from annotations
// in sentry_flutter/test/mocks.dart.
// Do not manually edit this file.

import 'dart:async' as _i4;
import 'dart:async' as _i5;

import 'package:mockito/mockito.dart' as _i1;
import 'package:sentry/src/hub.dart' as _i3;
import 'package:sentry/src/protocol/breadcrumb.dart' as _i7;
import 'package:sentry/src/protocol/sentry_event.dart' as _i5;
import 'package:sentry/src/protocol/sentry_id.dart' as _i2;
import 'package:sentry/src/protocol/sentry_level.dart' as _i6;
import 'package:sentry/src/sentry_client.dart' as _i8;
import 'package:sentry/src/sentry_envelope.dart' as _i10;
import 'package:sentry/src/transport/transport.dart' as _i9;
import 'package:sentry/src/protocol.dart' as _i2;
import 'package:sentry/src/sentry_client.dart' as _i7;
import 'package:sentry/src/sentry_envelope.dart' as _i9;
import 'package:sentry/src/sentry_user_feedback.dart' as _i6;
import 'package:sentry/src/tracing.dart' as _i4;
import 'package:sentry/src/transport/transport.dart' as _i8;

// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: unnecessary_parenthesis

// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types

// ignore_for_file: avoid_redundant_argument_values
class _FakeSentryId_0 extends _i1.Fake implements _i2.SentryId {}

class _FakeSentryId extends _i1.Fake implements _i2.SentryId {}
class _FakeHub_1 extends _i1.Fake implements _i3.Hub {}

class _FakeHub extends _i1.Fake implements _i3.Hub {}
class _FakeISentrySpan_2 extends _i1.Fake implements _i4.ISentrySpan {}

/// A class which mocks [Hub].
///
Expand All @@ -40,9 +43,9 @@ class MockHub extends _i1.Mock implements _i3.Hub {
@override
_i2.SentryId get lastEventId =>
(super.noSuchMethod(Invocation.getter(#lastEventId),
returnValue: _FakeSentryId()) as _i2.SentryId);
returnValue: _FakeSentryId_0()) as _i2.SentryId);
@override
_i4.Future<_i2.SentryId> captureEvent(_i5.SentryEvent? event,
_i5.Future<_i2.SentryId> captureEvent(_i2.SentryEvent? event,
{dynamic stackTrace, dynamic hint, _i3.ScopeCallback? withScope}) =>
(super.noSuchMethod(
Invocation.method(#captureEvent, [
Expand All @@ -52,10 +55,10 @@ class MockHub extends _i1.Mock implements _i3.Hub {
#hint: hint,
#withScope: withScope
}),
returnValue: Future<_i2.SentryId>.value(_FakeSentryId()))
as _i4.Future<_i2.SentryId>);
returnValue: Future<_i2.SentryId>.value(_FakeSentryId_0()))
as _i5.Future<_i2.SentryId>);
@override
_i4.Future<_i2.SentryId> captureException(dynamic throwable,
_i5.Future<_i2.SentryId> captureException(dynamic throwable,
{dynamic stackTrace, dynamic hint, _i3.ScopeCallback? withScope}) =>
(super.noSuchMethod(
Invocation.method(#captureException, [
Expand All @@ -65,11 +68,11 @@ class MockHub extends _i1.Mock implements _i3.Hub {
#hint: hint,
#withScope: withScope
}),
returnValue: Future<_i2.SentryId>.value(_FakeSentryId()))
as _i4.Future<_i2.SentryId>);
returnValue: Future<_i2.SentryId>.value(_FakeSentryId_0()))
as _i5.Future<_i2.SentryId>);
@override
_i4.Future<_i2.SentryId> captureMessage(String? message,
{_i6.SentryLevel? level,
_i5.Future<_i2.SentryId> captureMessage(String? message,
{_i2.SentryLevel? level,
String? template,
List<dynamic>? params,
dynamic hint,
Expand All @@ -84,40 +87,90 @@ class MockHub extends _i1.Mock implements _i3.Hub {
#hint: hint,
#withScope: withScope
}),
returnValue: Future<_i2.SentryId>.value(_FakeSentryId()))
as _i4.Future<_i2.SentryId>);
returnValue: Future<_i2.SentryId>.value(_FakeSentryId_0()))
as _i5.Future<_i2.SentryId>);
@override
_i5.Future<void> captureUserFeedback(_i6.SentryUserFeedback? userFeedback) =>
(super.noSuchMethod(
Invocation.method(#captureUserFeedback, [userFeedback]),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i5.Future<void>);
@override
void addBreadcrumb(_i7.Breadcrumb? crumb, {dynamic hint}) => super
void addBreadcrumb(_i2.Breadcrumb? crumb, {dynamic hint}) => super
.noSuchMethod(Invocation.method(#addBreadcrumb, [crumb], {#hint: hint}),
returnValueForMissingStub: null);
@override
void bindClient(_i8.SentryClient? client) =>
void bindClient(_i7.SentryClient? client) =>
super.noSuchMethod(Invocation.method(#bindClient, [client]),
returnValueForMissingStub: null);
@override
_i3.Hub clone() => (super.noSuchMethod(Invocation.method(#clone, []),
returnValue: _FakeHub()) as _i3.Hub);
returnValue: _FakeHub_1()) as _i3.Hub);
@override
_i4.Future<void> close() => (super.noSuchMethod(Invocation.method(#close, []),
returnValue: Future<void>.value(null),
returnValueForMissingStub: Future.value()) as _i4.Future<void>);
_i5.Future<void> close() => (super.noSuchMethod(Invocation.method(#close, []),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i5.Future<void>);
@override
void configureScope(_i3.ScopeCallback? callback) =>
super.noSuchMethod(Invocation.method(#configureScope, [callback]),
returnValueForMissingStub: null);
@override
_i4.ISentrySpan startTransaction(String? name, String? operation,
{String? description,
bool? bindToScope,
Map<String, dynamic>? customSamplingContext}) =>
(super.noSuchMethod(
Invocation.method(#startTransaction, [
name,
operation
], {
#description: description,
#bindToScope: bindToScope,
#customSamplingContext: customSamplingContext
}),
returnValue: _FakeISentrySpan_2()) as _i4.ISentrySpan);
@override
_i4.ISentrySpan startTransactionWithContext(
_i4.SentryTransactionContext? transactionContext,
{Map<String, dynamic>? customSamplingContext,
bool? bindToScope}) =>
(super.noSuchMethod(
Invocation.method(#startTransactionWithContext, [
transactionContext
], {
#customSamplingContext: customSamplingContext,
#bindToScope: bindToScope
}),
returnValue: _FakeISentrySpan_2()) as _i4.ISentrySpan);
@override
_i5.Future<_i2.SentryId> captureTransaction(
_i2.SentryTransaction? transaction) =>
(super.noSuchMethod(Invocation.method(#captureTransaction, [transaction]),
returnValue: Future<_i2.SentryId>.value(_FakeSentryId_0()))
as _i5.Future<_i2.SentryId>);
@override
void setSpanContext(
dynamic throwable, _i4.ISentrySpan? span, String? transaction) =>
super.noSuchMethod(
Invocation.method(#setSpanContext, [throwable, span, transaction]),
returnValueForMissingStub: null);
@override
String toString() => super.toString();
}

/// A class which mocks [Transport].
///
/// See the documentation for Mockito's code generation for more information.
class MockTransport extends _i1.Mock implements _i9.Transport {
class MockTransport extends _i1.Mock implements _i8.Transport {
MockTransport() {
_i1.throwOnMissingStub(this);
}

@override
_i4.Future<_i2.SentryId> send(_i10.SentryEnvelope? envelope) =>
_i5.Future<_i2.SentryId?> send(_i9.SentryEnvelope? envelope) =>
(super.noSuchMethod(Invocation.method(#send, [envelope]),
returnValue: Future<_i2.SentryId>.value(_FakeSentryId()))
as _i4.Future<_i2.SentryId>);
returnValue: Future<_i2.SentryId?>.value())
as _i5.Future<_i2.SentryId?>);
@override
String toString() => super.toString();
}
30 changes: 26 additions & 4 deletions flutter/test/sentry_navigator_observer_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
Expand All @@ -6,13 +7,37 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'mocks.dart';
import 'mocks.mocks.dart';


void main() {
late Fixture fixture;

PageRoute route(RouteSettings? settings) => PageRouteBuilder<void>(
pageBuilder: (_, __, ___) => Container(),
settings: settings,
);

setUp(() {
fixture = Fixture();
});

group('RouteObserverTransaction', () {
test('didPush starts transaction', () {
final currentRoute = route(RouteSettings(name: 'Current Route'));

final hub = MockHub();
when(hub.startTransaction('Current Route', 'ui.load', description: null, bindToScope: true, customSamplingContext: null)).thenReturn(NoOpSentrySpan());
final sut = fixture.getSut(hub: hub, setRouteNameAsTransaction: false);

sut.didPush(currentRoute, null);

verify(hub.startTransaction('Current Route', 'ui.load', description: null, bindToScope: true, customSamplingContext: null));
});

test('didPush finishes previous transaction', () {

});
});

group('RouteObserverBreadcrumb', () {
test('happy path with string route agrument', () {
const fromRouteSettings = RouteSettings(
Expand Down Expand Up @@ -142,10 +167,7 @@ void main() {
});

group('SentryNavigatorObserver', () {
PageRoute route(RouteSettings? settings) => PageRouteBuilder<void>(
pageBuilder: (_, __, ___) => Container(),
settings: settings,
);


RouteSettings routeSettings(String? name, [Object? arguments]) =>
RouteSettings(name: name, arguments: arguments);
Expand Down