UNPKG

2.46 kBTypeScriptView Raw
1/// <reference types="node" />
2import type * as http from 'node:http';
3export declare const instrumentExpress: ((options?: unknown) => void) & {
4 id: string;
5};
6/**
7 * Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).
8 *
9 * If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.
10 *
11 * For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).
12 *
13 * @example
14 * ```javascript
15 * const Sentry = require('@sentry/node');
16 *
17 * Sentry.init({
18 * integrations: [Sentry.expressIntegration()],
19 * })
20 * ```
21 */
22export declare const expressIntegration: () => import("@sentry/core").Integration;
23interface MiddlewareError extends Error {
24 status?: number | string;
25 statusCode?: number | string;
26 status_code?: number | string;
27 output?: {
28 statusCode?: number | string;
29 };
30}
31type ExpressMiddleware = (req: http.IncomingMessage, res: http.ServerResponse, next: () => void) => void;
32type ExpressErrorMiddleware = (error: MiddlewareError, req: http.IncomingMessage, res: http.ServerResponse, next: (error: MiddlewareError) => void) => void;
33interface ExpressHandlerOptions {
34 /**
35 * Callback method deciding whether error should be captured and sent to Sentry
36 * @param error Captured middleware error
37 */
38 shouldHandleError?(this: void, error: MiddlewareError): boolean;
39}
40/**
41 * An Express-compatible error handler.
42 */
43export declare function expressErrorHandler(options?: ExpressHandlerOptions): ExpressErrorMiddleware;
44/**
45 * Add an Express error handler to capture errors to Sentry.
46 *
47 * The error handler must be before any other middleware and after all controllers.
48 *
49 * @param app The Express instances
50 * @param options {ExpressHandlerOptions} Configuration options for the handler
51 *
52 * @example
53 * ```javascript
54 * const Sentry = require('@sentry/node');
55 * const express = require("express");
56 *
57 * const app = express();
58 *
59 * // Add your routes, etc.
60 *
61 * // Add this after all routes,
62 * // but before any and other error-handling middlewares are defined
63 * Sentry.setupExpressErrorHandler(app);
64 *
65 * app.listen(3000);
66 * ```
67 */
68export declare function setupExpressErrorHandler(app: {
69 use: (middleware: ExpressMiddleware | ExpressErrorMiddleware) => unknown;
70}, options?: ExpressHandlerOptions): void;
71export {};
72//# sourceMappingURL=express.d.ts.map
\No newline at end of file