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