@@ -35,8 +35,7 @@ void main() {
35
35
test ('sets transaction overwrites span name' , () {
36
36
final sut = fixture.getSut ();
37
37
38
- final tracer = SentryTracer (fixture.context, MockHub ());
39
- sut.span = tracer;
38
+ sut.span = fixture.sentryTracer;
40
39
sut.transaction = 'test' ;
41
40
42
41
expect (sut.transaction, 'test' );
@@ -46,13 +45,31 @@ void main() {
46
45
test ('sets span overwrites transaction name' , () {
47
46
final sut = fixture.getSut ();
48
47
49
- final tracer = SentryTracer (fixture.context, MockHub ());
50
- sut.span = tracer;
48
+ sut.span = fixture.sentryTracer;
51
49
52
50
expect (sut.transaction, 'name' );
53
51
expect ((sut.span as SentryTracer ).name, 'name' );
54
52
});
55
53
54
+ test ('removing span resets transaction if not set separately' , () {
55
+ final sut = fixture.getSut ();
56
+
57
+ sut.span = fixture.sentryTracer;
58
+ sut.span = null ;
59
+
60
+ expect (sut.transaction, isNull);
61
+ });
62
+
63
+ test ('removing span does not reset transaction if set separately' , () {
64
+ final sut = fixture.getSut ();
65
+
66
+ sut.transaction = 'test' ;
67
+ sut.span = fixture.sentryTracer;
68
+ sut.span = null ;
69
+
70
+ expect (sut.transaction, 'test' );
71
+ });
72
+
56
73
test ('sets $SentryUser ' , () {
57
74
final sut = fixture.getSut ();
58
75
@@ -403,9 +420,9 @@ void main() {
403
420
});
404
421
405
422
test ('apply trace context to event' , () async {
406
- final tracer = SentryTracer (fixture.context, MockHub ());
407
423
final event = SentryEvent ();
408
- final scope = Scope (SentryOptions (dsn: fakeDsn))..span = tracer;
424
+ final scope = Scope (SentryOptions (dsn: fakeDsn))
425
+ ..span = fixture.sentryTracer;
409
426
410
427
final updatedEvent = await scope.applyToEvent (event);
411
428
@@ -537,6 +554,16 @@ void main() {
537
554
538
555
expect (updatedEvent? .level, SentryLevel .error);
539
556
});
557
+
558
+ test ('should apply the scope transaction from the span' , () async {
559
+ final event = SentryEvent ();
560
+ final scope = Scope (SentryOptions (dsn: fakeDsn))
561
+ ..span = fixture.sentryTracer;
562
+
563
+ final updatedEvent = await scope.applyToEvent (event);
564
+
565
+ expect (updatedEvent? .transaction, 'name' );
566
+ });
540
567
});
541
568
542
569
test ('event processor drops the event' , () async {
@@ -551,8 +578,7 @@ void main() {
551
578
});
552
579
553
580
test ('should not apply fingerprint if transaction' , () async {
554
- final tracer = SentryTracer (fixture.context, MockHub ());
555
- var tr = SentryTransaction (tracer);
581
+ var tr = SentryTransaction (fixture.sentryTracer);
556
582
final scope = Scope (SentryOptions (dsn: fakeDsn))..fingerprint = ['test' ];
557
583
558
584
final updatedTr = await scope.applyToEvent (tr);
@@ -561,8 +587,7 @@ void main() {
561
587
});
562
588
563
589
test ('should not apply level if transaction' , () async {
564
- final tracer = SentryTracer (fixture.context, MockHub ());
565
- var tr = SentryTransaction (tracer);
590
+ var tr = SentryTransaction (fixture.sentryTracer);
566
591
final scope = Scope (SentryOptions (dsn: fakeDsn))..level = SentryLevel .error;
567
592
568
593
final updatedTr = await scope.applyToEvent (tr);
@@ -571,8 +596,7 @@ void main() {
571
596
});
572
597
573
598
test ('apply sampled to trace' , () async {
574
- final tracer = SentryTracer (fixture.context, MockHub ());
575
- var tr = SentryTransaction (tracer);
599
+ var tr = SentryTransaction (fixture.sentryTracer);
576
600
final scope = Scope (SentryOptions (dsn: fakeDsn))..level = SentryLevel .error;
577
601
578
602
final updatedTr = await scope.applyToEvent (tr);
@@ -701,15 +725,19 @@ void main() {
701
725
}
702
726
703
727
class Fixture {
704
- final context = SentryTransactionContext (
705
- 'name' ,
706
- 'op' ,
707
- samplingDecision: SentryTracesSamplingDecision (true ),
708
- );
709
728
final mockScopeObserver = MockScopeObserver ();
710
729
711
730
final options = SentryOptions (dsn: fakeDsn);
712
731
732
+ final sentryTracer = SentryTracer (
733
+ SentryTransactionContext (
734
+ 'name' ,
735
+ 'op' ,
736
+ samplingDecision: SentryTracesSamplingDecision (true ),
737
+ ),
738
+ MockHub (),
739
+ );
740
+
713
741
SentryLevel ? loggedLevel;
714
742
Object ? loggedException;
715
743
0 commit comments