@@ -127,47 +127,18 @@ function createToken(
127127 * @param requestOptions - The request options for the waitpoint.
128128 * @returns A promise that returns the token and anything you returned from your callback.
129129 */
130- async function createHttpCallback < TCallbackResult > (
131- callback : ( url : string ) => Promise < TCallbackResult > ,
130+ async function createHttpCallback (
132131 options ?: CreateWaitpointTokenRequestBody ,
133132 requestOptions ?: ApiRequestOptions
134- ) : Promise < {
135- /** The token that you can use to wait for the callback */
136- token : CreateWaitpointHttpCallbackResponseBody ;
137- /** Whatever you returned from the function */
138- data : TCallbackResult ;
139- } > {
133+ ) : Promise < CreateWaitpointHttpCallbackResponseBody > {
140134 const apiClient = apiClientManager . clientOrThrow ( ) ;
141135
142- return tracer . startActiveSpan (
143- `wait.createHttpCallback()` ,
144- async ( span ) => {
145- const waitpoint = await apiClient . createWaitpointHttpCallback ( options ?? { } , requestOptions ) ;
146-
147- span . setAttribute ( "id" , waitpoint . id ) ;
148- span . setAttribute ( "isCached" , waitpoint . isCached ) ;
149- span . setAttribute ( "url" , waitpoint . url ) ;
150-
151- const callbackResult = await tracer . startActiveSpan (
152- `callback()` ,
153- async ( ) => {
154- return callback ( waitpoint . url ) ;
155- } ,
156- {
157- attributes : {
158- [ SemanticInternalAttributes . STYLE_ICON ] : "function" ,
159- id : waitpoint . id ,
160- url : waitpoint . url ,
161- isCached : waitpoint . isCached ,
162- } ,
163- }
164- ) ;
165-
166- return { token : waitpoint , data : callbackResult } ;
167- } ,
136+ const $requestOptions = mergeRequestOptions (
168137 {
138+ tracer,
139+ name : "wait.createHttpCallback()" ,
140+ icon : "wait-http-callback" ,
169141 attributes : {
170- [ SemanticInternalAttributes . STYLE_ICON ] : "wait-http-callback" ,
171142 idempotencyKey : options ?. idempotencyKey ,
172143 idempotencyKeyTTL : options ?. idempotencyKeyTTL ,
173144 timeout : options ?. timeout
@@ -177,8 +148,16 @@ async function createHttpCallback<TCallbackResult>(
177148 : undefined ,
178149 tags : options ?. tags ,
179150 } ,
180- }
151+ onResponseBody : ( body : CreateWaitpointHttpCallbackResponseBody , span ) => {
152+ span . setAttribute ( "id" , body . id ) ;
153+ span . setAttribute ( "isCached" , body . isCached ) ;
154+ span . setAttribute ( "url" , body . url ) ;
155+ } ,
156+ } ,
157+ requestOptions
181158 ) ;
159+
160+ return apiClient . createWaitpointHttpCallback ( options ?? { } , $requestOptions ) ;
182161}
183162
184163/**
0 commit comments