@@ -779,27 +779,76 @@ describe('startSpanManual', () => {
779
779
expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
780
780
} ) ;
781
781
782
- it ( 'allows to pass a scope' , ( ) => {
783
- const initialScope = getCurrentScope ( ) ;
782
+ describe ( 'allows to pass a scope' , ( ) => {
783
+ it ( 'with parent span' , ( ) => {
784
+ const initialScope = getCurrentScope ( ) ;
784
785
785
- const manualScope = initialScope . clone ( ) ;
786
- const parentSpan = new SentrySpan ( { spanId : 'parent-span-id' , sampled : true } ) ;
787
- _setSpanForScope ( manualScope , parentSpan ) ;
786
+ const manualScope = initialScope . clone ( ) ;
787
+ const parentSpan = new SentrySpan ( { spanId : 'parent-span-id' , sampled : true } ) ;
788
+ _setSpanForScope ( manualScope , parentSpan ) ;
788
789
789
- startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , span => {
790
- expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
791
- expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
792
- expect ( getActiveSpan ( ) ) . toBe ( span ) ;
793
- expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( 'parent-span-id' ) ;
790
+ let span1 : Span | undefined ;
794
791
795
- span . end ( ) ;
792
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , span => {
793
+ span1 = span ;
794
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
795
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
796
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
797
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( 'parent-span-id' ) ;
796
798
797
- // Is still the active span
798
- expect ( getActiveSpan ( ) ) . toBe ( span ) ;
799
+ span . end ( ) ;
800
+
801
+ // Is still the active span
802
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
803
+ } ) ;
804
+
805
+ startSpanManual ( { name : 'POST users/[id]' , scope : manualScope } , ( span , finish ) => {
806
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
807
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
808
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
809
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( span1 ?. spanContext ( ) . spanId ) ;
810
+
811
+ finish ( ) ;
812
+
813
+ // using finish() resets the scope correctly
814
+ expect ( getActiveSpan ( ) ) . toBe ( span1 ) ;
815
+ } ) ;
816
+
817
+ expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
818
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
799
819
} ) ;
800
820
801
- expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
802
- expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
821
+ it ( 'without parent span' , ( ) => {
822
+ const initialScope = getCurrentScope ( ) ;
823
+ const manualScope = initialScope . clone ( ) ;
824
+
825
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , ( span , finish ) => {
826
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
827
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
828
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
829
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
830
+
831
+ finish ( ) ;
832
+
833
+ // Is still the active span
834
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
835
+ } ) ;
836
+
837
+ startSpanManual ( { name : 'GET users/[id]' , scope : manualScope } , ( span , finish ) => {
838
+ expect ( getCurrentScope ( ) ) . not . toBe ( initialScope ) ;
839
+ expect ( getCurrentScope ( ) ) . toBe ( manualScope ) ;
840
+ expect ( getActiveSpan ( ) ) . toBe ( span ) ;
841
+ expect ( spanToJSON ( span ) . parent_span_id ) . toBe ( undefined ) ;
842
+
843
+ finish ( ) ;
844
+
845
+ // using finish() resets the scope correctly
846
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
847
+ } ) ;
848
+
849
+ expect ( getCurrentScope ( ) ) . toBe ( initialScope ) ;
850
+ expect ( getActiveSpan ( ) ) . toBe ( undefined ) ;
851
+ } ) ;
803
852
} ) ;
804
853
805
854
it ( 'allows to pass a parentSpan' , ( ) => {
0 commit comments