@@ -128,38 +128,41 @@ function makeWrappedDocumentRequestFunction(
128
128
129
129
function makeWrappedDataFunction ( origFn : DataFunction , id : string , name : 'action' | 'loader' ) : DataFunction {
130
130
return async function ( this : unknown , args : DataFunctionArgs ) : Promise < Response | AppData > {
131
- let res : Response | AppData ;
132
- const activeTransaction = getActiveTransaction ( ) ;
133
- const currentScope = getCurrentHub ( ) . getScope ( ) ;
134
-
135
- if ( ! activeTransaction || ! currentScope ) {
136
- return origFn . call ( this , args ) ;
137
- }
138
-
139
- try {
140
- const span = activeTransaction . startChild ( {
141
- op : `remix.server.${ name } ` ,
142
- description : id ,
143
- tags : {
144
- name,
145
- } ,
146
- } ) ;
131
+ const local = domain . create ( ) ;
132
+ return local . bind ( async ( ) => {
133
+ let res : Response | AppData ;
134
+ const activeTransaction = getActiveTransaction ( ) ;
135
+ const currentScope = getCurrentHub ( ) . getScope ( ) ;
147
136
148
- if ( span ) {
149
- // Assign data function to hub to be able to see `db` transactions (if any) as children.
150
- currentScope . setSpan ( span ) ;
137
+ if ( ! activeTransaction || ! currentScope ) {
138
+ return origFn . call ( this , args ) ;
151
139
}
152
140
153
- res = await origFn . call ( this , args ) ;
154
-
155
- currentScope . setSpan ( activeTransaction ) ;
156
- span . finish ( ) ;
157
- } catch ( err ) {
158
- captureRemixServerException ( err , name ) ;
159
- throw err ;
160
- }
141
+ try {
142
+ const span = activeTransaction . startChild ( {
143
+ op : `remix.server.${ name } ` ,
144
+ description : id ,
145
+ tags : {
146
+ name,
147
+ } ,
148
+ } ) ;
149
+
150
+ if ( span ) {
151
+ // Assign data function to hub to be able to see `db` transactions (if any) as children.
152
+ currentScope . setSpan ( span ) ;
153
+ }
154
+
155
+ res = await origFn . call ( this , args ) ;
156
+
157
+ currentScope . setSpan ( activeTransaction ) ;
158
+ span . finish ( ) ;
159
+ } catch ( err ) {
160
+ captureRemixServerException ( err , name ) ;
161
+ throw err ;
162
+ }
161
163
162
- return res ;
164
+ return res ;
165
+ } ) ;
163
166
} ;
164
167
}
165
168
0 commit comments