|
1 | 1 | import { captureException, getCurrentHub } from '@sentry/core';
|
2 | 2 | import { Event } from '@sentry/types';
|
3 | 3 | import { forget, isString, logger, normalize } from '@sentry/utils';
|
| 4 | +import { flush } from './sdk'; |
4 | 5 | import * as cookie from 'cookie';
|
5 | 6 | import * as domain from 'domain';
|
6 | 7 | import * as http from 'http';
|
@@ -221,12 +222,21 @@ export function requestHandler(options?: {
|
221 | 222 | transaction?: boolean | TransactionTypes;
|
222 | 223 | user?: boolean | string[];
|
223 | 224 | version?: boolean;
|
| 225 | + flushTimeout?: number; |
224 | 226 | }): (req: http.IncomingMessage, res: http.ServerResponse, next: (error?: any) => void) => void {
|
225 | 227 | return function sentryRequestMiddleware(
|
226 | 228 | req: http.IncomingMessage,
|
227 | 229 | res: http.ServerResponse,
|
228 | 230 | next: (error?: any) => void,
|
229 | 231 | ): void {
|
| 232 | + if (options && options.flushTimeout && options.flushTimeout > 0) { |
| 233 | + const _end = res.end |
| 234 | + |
| 235 | + res.end = async function end (chunk?: any, encodingOrCb?: string | Function, cb?: Function) { |
| 236 | + await flush(options.flushTimeout) |
| 237 | + return _end.call(this, chunk, encodingOrCb, cb) |
| 238 | + } |
| 239 | + } |
230 | 240 | const local = domain.create();
|
231 | 241 | local.add(req);
|
232 | 242 | local.add(res);
|
|
0 commit comments