UNPKG

@sentry/nextjs

Version:
27 lines (26 loc) • 1.77 kB
/// <reference types="node" /> import { ServerResponse } from 'http'; import { Transaction } from '@sentry/types'; /** * Wrap `res.end()` so that it closes the transaction and flushes events before letting the request finish. * * Note: This wraps a sync method with an async method. While in general that's not a great idea in terms of keeping * things in the right order, in this case it's safe, because the native `.end()` actually *is* (effectively) async, and * its run actually *is* (literally) awaited, just manually so (which reflects the fact that the core of the * request/response code in Node by far predates the introduction of `async`/`await`). When `.end()` is done, it emits * the `prefinish` event, and only once that fires does request processing continue. See * https://github.com/nodejs/node/commit/7c9b607048f13741173d397795bac37707405ba7. * * Also note: `res.end()` isn't called until *after* all response data and headers have been sent, so blocking inside of * `end` doesn't delay data getting to the end user. See * https://nodejs.org/api/http.html#responseenddata-encoding-callback. * * @param transaction The transaction tracing request handling * @param res: The request's corresponding response */ export declare function autoEndTransactionOnResponseEnd(transaction: Transaction, res: ServerResponse): void; /** Finish the given response's transaction and set HTTP status data */ export declare function finishTransaction(transaction: Transaction | undefined, res: ServerResponse): void; /** Flush the event queue to ensure that events get sent to Sentry before the response is finished and the lambda ends */ export declare function flushQueue(): Promise<void>; //# sourceMappingURL=responseEnd.d.ts.map