Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/instrumentation/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,26 @@ export function instrumentClientFetch(
if (request.cf) span.setAttributes(gatherOutgoingCfAttributes(request.cf))
const response = await Reflect.apply(target, thisArg, [request])
span.setAttributes(gatherResponseAttributes(response))
return response

if (!response.body) {
span.end()
return response
}

const transformer = new TransformStream({
transform(chunk, controller) {
controller.enqueue(chunk)
},
flush() {
span.end()
},
})
return new Response(response.body.pipeThrough(transformer), response)
} catch (error: unknown) {
span.recordException(error as Exception)
span.setStatus({ code: SpanStatusCode.ERROR })
throw error
} finally {
span.end()
throw error
}
})
return promise
Expand Down