@@ -1671,6 +1671,10 @@ include Pending_promises
16711671
16721672
16731673
1674+ let tracing_context = new_key ()
1675+ let tracing_counter = ref 0
1676+ let tracing_counter () = incr tracing_counter; ! tracing_counter
1677+
16741678module Sequential_composition :
16751679sig
16761680 (* Main interface (public) *)
@@ -1903,6 +1907,8 @@ struct
19031907 p''
19041908
19051909 let backtrace_bind (loc_f , loc_l , _ , _ ) add_loc p f =
1910+ let trace_context = Sequence_associated_storage. get tracing_context in
1911+ let trace_counter = tracing_counter () in
19061912 let Internal p = to_internal_promise p in
19071913 let p = underlying p in
19081914
@@ -1912,7 +1918,7 @@ struct
19121918 let saved_storage = ! current_storage in
19131919
19141920 let callback p_result =
1915- Lwt_rte. emit_trace End loc_f loc_l;
1921+ Lwt_rte. emit_trace End trace_context trace_counter loc_f loc_l;
19161922 match p_result with
19171923 | Fulfilled v ->
19181924 current_storage := saved_storage;
@@ -1956,7 +1962,7 @@ struct
19561962 to_public_promise {state = Rejected (add_loc exn )}
19571963
19581964 | Pending p_callbacks ->
1959- Lwt_rte. emit_trace Begin loc_f loc_l;
1965+ Lwt_rte. emit_trace Begin trace_context trace_counter loc_f loc_l;
19601966 let (p'', callback) = create_result_promise_and_callback_if_deferred () in
19611967 add_implicitly_removed_callback p_callbacks callback;
19621968 p''
@@ -2085,6 +2091,8 @@ struct
20852091 p''
20862092
20872093 let backtrace_catch (loc_f , loc_l , _ , _ ) add_loc f h =
2094+ let trace_context = Sequence_associated_storage. get tracing_context in
2095+ let trace_counter = tracing_counter () in
20882096 let p =
20892097 try f ()
20902098 with exn when Exception_filter. run exn -> fail exn
@@ -2098,7 +2106,7 @@ struct
20982106 let saved_storage = ! current_storage in
20992107
21002108 let callback p_result =
2101- Lwt_rte. emit_trace End loc_f loc_l;
2109+ Lwt_rte. emit_trace End trace_context trace_counter loc_f loc_l;
21022110 match p_result with
21032111 | Fulfilled _ as p_result ->
21042112 let State_may_now_be_pending_proxy p'' = may_now_be_proxy p'' in
@@ -2143,7 +2151,7 @@ struct
21432151 (p'', callback, p.state))
21442152
21452153 | Pending p_callbacks ->
2146- Lwt_rte. emit_trace Begin loc_f loc_l;
2154+ Lwt_rte. emit_trace Begin trace_context trace_counter loc_f loc_l;
21472155 let (p'', callback) = create_result_promise_and_callback_if_deferred () in
21482156 add_implicitly_removed_callback p_callbacks callback;
21492157 p''
@@ -2224,6 +2232,8 @@ struct
22242232 p''
22252233
22262234 let backtrace_try_bind (loc_f , loc_l , _ , _ ) add_loc f f' h =
2235+ let trace_context = Sequence_associated_storage. get tracing_context in
2236+ let trace_counter = tracing_counter () in
22272237 let p =
22282238 try f ()
22292239 with exn when Exception_filter. run exn -> fail exn
@@ -2237,7 +2247,7 @@ struct
22372247 let saved_storage = ! current_storage in
22382248
22392249 let callback p_result =
2240- Lwt_rte. emit_trace End loc_f loc_l;
2250+ Lwt_rte. emit_trace End trace_context trace_counter loc_f loc_l;
22412251 match p_result with
22422252 | Fulfilled v ->
22432253 current_storage := saved_storage;
@@ -2297,7 +2307,7 @@ struct
22972307 (p'', callback, p.state))
22982308
22992309 | Pending p_callbacks ->
2300- Lwt_rte. emit_trace Begin loc_f loc_l;
2310+ Lwt_rte. emit_trace Begin trace_context trace_counter loc_f loc_l;
23012311 let (p'', callback) = create_result_promise_and_callback_if_deferred () in
23022312 add_implicitly_removed_callback p_callbacks callback;
23032313 p''
0 commit comments