@@ -732,27 +732,76 @@ describe('startSpanManual', () => {
732
732
expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
733
733
} ) ;
734
734
735
- it ( 'allows to pass a scope' , ( ) => {
736
- const initialScope = getCurrentScope ( ) ;
735
+ describe ( 'allows to pass a scope' , ( ) => {
736
+ it ( 'with parent span' , ( ) => {
737
+ const initialScope = getCurrentScope ( ) ;
737
738
738
- const manualScope = initialScope . clone ( ) ;
739
- const parentSpan = new SentrySpan ( { spanId : 'parent-span-id' , sampled : true } ) ;
740
- _setSpanForScope ( manualScope , parentSpan ) ;
739
+ const manualScope = initialScope . clone ( ) ;
740
+ const parentSpan = new SentrySpan ( { spanId : 'parent-span-id' , sampled : true } ) ;
741
+ _setSpanForScope ( manualScope , parentSpan ) ;
741
742
742
- startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , span => {
743
- expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
744
- expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
745
- expect ( getActiveSpan ( ) ) . toBe ( span ) ;
746
- expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( 'parent-span-id' ) ;
743
+ let span1 : Span | undefined ;
747
744
748
- span . end ( ) ;
745
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , span => {
746
+ span1 = span ;
747
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
748
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
749
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
750
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( 'parent-span-id' ) ;
749
751
750
- // Is still the active span
751
- expect ( getActiveSpan ( ) ) . toBe ( span ) ;
752
+ span . end ( ) ;
753
+
754
+ // Is still the active span
755
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
756
+ } ) ;
757
+
758
+ startSpanManual ( { name : 'POST users/[id]' , scope : manualScope } , ( span , finish ) => {
759
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
760
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
761
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
762
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( span1 ?. spanContext ( ) . spanId ) ;
763
+
764
+ finish ( ) ;
765
+
766
+ // using finish() resets the scope correctly
767
+ expect ( getActiveSpan ( ) ) . toBe ( span1 ) ;
768
+ } ) ;
769
+
770
+ expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
771
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
752
772
} ) ;
753
773
754
- expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
755
- expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
774
+ it ( 'without parent span' , ( ) => {
775
+ const initialScope = getCurrentScope ( ) ;
776
+ const manualScope = initialScope . clone ( ) ;
777
+
778
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , ( span , finish ) => {
779
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
780
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
781
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
782
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
783
+
784
+ finish ( ) ;
785
+
786
+ // Is still the active span
787
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
788
+ } ) ;
789
+
790
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , ( span , finish ) => {
791
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
792
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
793
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
794
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
795
+
796
+ finish ( ) ;
797
+
798
+ // using finish() resets the scope correctly
799
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
800
+ } ) ;
801
+
802
+ expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
803
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
804
+ } ) ;
756
805
} ) ;
757
806
758
807
it ( 'allows to pass a parentSpan' , ( ) => {
0 commit comments