@@ -854,6 +854,29 @@ void ddtrace_close_span(ddtrace_span_data *span) {
854854 ddtrace_switch_span_stack (span -> stack );
855855 }
856856
857+ ddtrace_close_stack_userland_spans_until (span );
858+
859+ ddtrace_close_top_span_without_stack_swap (span );
860+ }
861+
862+ void ddtrace_close_span_restore_stack (ddtrace_span_data * span ) {
863+ assert (span != NULL );
864+ if (span -> type == DDTRACE_SPAN_CLOSED ) {
865+ return ;
866+ }
867+
868+ // switches to the stack of the passed span, closes the span and switches back to the original stack
869+ ddtrace_span_stack * active_stack_before = DDTRACE_G (active_stack );
870+ assert (active_stack_before != NULL );
871+ GC_ADDREF (& active_stack_before -> std );
872+
873+ ddtrace_close_span (span );
874+
875+ ddtrace_switch_span_stack (active_stack_before );
876+ GC_DELREF (& active_stack_before -> std );
877+ }
878+
879+ void ddtrace_close_top_span_without_stack_swap (ddtrace_span_data * span ) {
857880 if (span -> std .ce == ddtrace_ce_root_span_data ) {
858881 ddtrace_span_data * inferred_span = ddtrace_get_inferred_span (ROOTSPANDATA (& span -> std ));
859882 if (inferred_span ) {
@@ -912,29 +935,6 @@ void ddtrace_close_span(ddtrace_span_data *span) {
912935 // Must be done at closing because we need to read the "component" span's meta which is not available at creation
913936 ddtrace_telemetry_inc_spans_created (span );
914937
915- ddtrace_close_stack_userland_spans_until (span );
916-
917- ddtrace_close_top_span_without_stack_swap (span );
918- }
919-
920- void ddtrace_close_span_restore_stack (ddtrace_span_data * span ) {
921- assert (span != NULL );
922- if (span -> type == DDTRACE_SPAN_CLOSED ) {
923- return ;
924- }
925-
926- // switches to the stack of the passed span, closes the span and switches back to the original stack
927- ddtrace_span_stack * active_stack_before = DDTRACE_G (active_stack );
928- assert (active_stack_before != NULL );
929- GC_ADDREF (& active_stack_before -> std );
930-
931- ddtrace_close_span (span );
932-
933- ddtrace_switch_span_stack (active_stack_before );
934- GC_DELREF (& active_stack_before -> std );
935- }
936-
937- void ddtrace_close_top_span_without_stack_swap (ddtrace_span_data * span ) {
938938 ddtrace_span_stack * stack = span -> stack ;
939939
940940 span -> type = DDTRACE_SPAN_CLOSED ;
0 commit comments