@@ -35,8 +35,7 @@ void main() {
3535 test ('sets transaction overwrites span name' , () {
3636 final sut = fixture.getSut ();
3737
38- final tracer = SentryTracer (fixture.context, MockHub ());
39- sut.span = tracer;
38+ sut.span = fixture.sentryTracer;
4039 sut.transaction = 'test' ;
4140
4241 expect (sut.transaction, 'test' );
@@ -46,13 +45,31 @@ void main() {
4645 test ('sets span overwrites transaction name' , () {
4746 final sut = fixture.getSut ();
4847
49- final tracer = SentryTracer (fixture.context, MockHub ());
50- sut.span = tracer;
48+ sut.span = fixture.sentryTracer;
5149
5250 expect (sut.transaction, 'name' );
5351 expect ((sut.span as SentryTracer ).name, 'name' );
5452 });
5553
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+
5673 test ('sets $SentryUser ' , () {
5774 final sut = fixture.getSut ();
5875
@@ -403,9 +420,9 @@ void main() {
403420 });
404421
405422 test ('apply trace context to event' , () async {
406- final tracer = SentryTracer (fixture.context, MockHub ());
407423 final event = SentryEvent ();
408- final scope = Scope (SentryOptions (dsn: fakeDsn))..span = tracer;
424+ final scope = Scope (SentryOptions (dsn: fakeDsn))
425+ ..span = fixture.sentryTracer;
409426
410427 final updatedEvent = await scope.applyToEvent (event);
411428
@@ -537,6 +554,16 @@ void main() {
537554
538555 expect (updatedEvent? .level, SentryLevel .error);
539556 });
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+ });
540567 });
541568
542569 test ('event processor drops the event' , () async {
@@ -551,8 +578,7 @@ void main() {
551578 });
552579
553580 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);
556582 final scope = Scope (SentryOptions (dsn: fakeDsn))..fingerprint = ['test' ];
557583
558584 final updatedTr = await scope.applyToEvent (tr);
@@ -561,8 +587,7 @@ void main() {
561587 });
562588
563589 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);
566591 final scope = Scope (SentryOptions (dsn: fakeDsn))..level = SentryLevel .error;
567592
568593 final updatedTr = await scope.applyToEvent (tr);
@@ -571,8 +596,7 @@ void main() {
571596 });
572597
573598 test ('apply sampled to trace' , () async {
574- final tracer = SentryTracer (fixture.context, MockHub ());
575- var tr = SentryTransaction (tracer);
599+ var tr = SentryTransaction (fixture.sentryTracer);
576600 final scope = Scope (SentryOptions (dsn: fakeDsn))..level = SentryLevel .error;
577601
578602 final updatedTr = await scope.applyToEvent (tr);
@@ -701,15 +725,19 @@ void main() {
701725}
702726
703727class Fixture {
704- final context = SentryTransactionContext (
705- 'name' ,
706- 'op' ,
707- samplingDecision: SentryTracesSamplingDecision (true ),
708- );
709728 final mockScopeObserver = MockScopeObserver ();
710729
711730 final options = SentryOptions (dsn: fakeDsn);
712731
732+ final sentryTracer = SentryTracer (
733+ SentryTransactionContext (
734+ 'name' ,
735+ 'op' ,
736+ samplingDecision: SentryTracesSamplingDecision (true ),
737+ ),
738+ MockHub (),
739+ );
740+
713741 SentryLevel ? loggedLevel;
714742 Object ? loggedException;
715743
0 commit comments