diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 38359ba39f83..e2361d7f6d3a 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -3,10 +3,11 @@ import { getHubFromCarrier, Scope } from '@sentry/hub'; import { SentryEvent, Severity } from '@sentry/types'; import { forget } from '@sentry/utils/async'; import { serialize } from '@sentry/utils/object'; -import { parse as parseCookie } from 'cookie'; +import * as cookie from 'cookie'; import * as domain from 'domain'; -import { hostname } from 'os'; -import { parse as parseUrl } from 'url'; +import * as http from 'http'; +import * as os from 'os'; +import * as url from 'url'; import { NodeClient } from './client'; import { getCurrentHub } from './hub'; @@ -45,10 +46,10 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin // query string: // node: req.url (raw) // express, koa: req.query - const query = req.query || parseUrl(originalUrl || '', true).query; + const query = req.query || url.parse(originalUrl || '', true).query; // cookies: // node, express, koa: req.headers.cookie - const cookies = parseCookie(headers.cookie || ''); + const cookies = cookie.parse(headers.cookie || ''); // body data: // node, express, koa: req.body let data = req.body; @@ -121,7 +122,7 @@ function parseRequest( ...event.request, ...extractRequestData(req), }, - server_name: global.process.env.SENTRY_NAME || hostname(), + server_name: global.process.env.SENTRY_NAME || os.hostname(), }; if (req.user) { @@ -135,8 +136,8 @@ function parseRequest( } /** JSDoc */ -export function requestHandler(): (req: Request, res: Response, next: () => void) => void { - return function sentryRequestMiddleware(req: Request, _res: Response, next: () => void): void { +export function requestHandler(): (req: http.ClientRequest, res: http.ServerResponse, next: () => void) => void { + return function sentryRequestMiddleware(req: http.ClientRequest, _res: http.ServerResponse, next: () => void): void { const local = domain.create(); const hub = getHubFromCarrier(req); hub.bindClient(getCurrentHub().getClient()); @@ -168,14 +169,14 @@ function getStatusCodeFromResponse(error: MiddlewareError): number { /** JSDoc */ export function errorHandler(): ( error: MiddlewareError, - req: Request, - res: Response, + req: http.ClientRequest, + res: http.ServerResponse, next: (error: MiddlewareError) => void, ) => void { return function sentryErrorMiddleware( error: MiddlewareError, - req: Request, - _res: Response, + req: http.ClientRequest, + _res: http.ServerResponse, next: (error: MiddlewareError) => void, ): void { const status = getStatusCodeFromResponse(error); diff --git a/packages/node/src/integrations/console.ts b/packages/node/src/integrations/console.ts index fe91ddd0de17..e11d99c06bef 100644 --- a/packages/node/src/integrations/console.ts +++ b/packages/node/src/integrations/console.ts @@ -1,6 +1,6 @@ import { Integration, Severity } from '@sentry/types'; import { fill } from '@sentry/utils/object'; -import { format } from 'util'; +import * as util from 'util'; import { getCurrentHub } from '../hub'; /** @@ -59,7 +59,7 @@ function consoleWrapper(originalModule: any): any { { category: 'console', level: sentryLevel, - message: format.apply(undefined, arguments), + message: util.format.apply(undefined, arguments), }, { input: [...arguments], diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index ff34a82f8b66..21ca3783eb19 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -1,16 +1,16 @@ import { Integration } from '@sentry/types'; import { fill } from '@sentry/utils/object'; -import { ClientRequest, ClientRequestArgs, ServerResponse } from 'http'; -import { inherits } from 'util'; +import * as http from 'http'; +import * as util from 'util'; import { getCurrentHub } from '../hub'; -let lastResponse: ServerResponse | undefined; +let lastResponse: http.ServerResponse | undefined; /** * Request interface which can carry around unified url * independently of used framework */ -interface SentryRequest extends Request { +interface SentryRequest extends http.IncomingMessage { __ravenBreadcrumbUrl?: string; } @@ -20,7 +20,7 @@ interface SentryRequest extends Request { * @param options url that should be returned or an object containing it's parts. * @returns constructed url */ -function createBreadcrumbUrl(options: string | ClientRequestArgs): string { +function createBreadcrumbUrl(options: string | http.ClientRequestArgs): string { // We could just always reconstruct this from this.agent, this._headers, this.path, etc // but certain other http-instrumenting libraries (like nock, which we use for tests) fail to // maintain the guarantee that after calling origClientRequest, those fields will be populated @@ -54,7 +54,7 @@ function loadWrapper(nativeModule: any): any { const origClientRequest = originalModule.ClientRequest; const clientRequest = function( this: SentryRequest, - options: ClientRequestArgs | string, + options: http.ClientRequestArgs | string, callback: () => void, ): any { // Note: this won't capture a breadcrumb if a response never comes @@ -68,7 +68,7 @@ function loadWrapper(nativeModule: any): any { this.__ravenBreadcrumbUrl = createBreadcrumbUrl(options); }; - inherits(clientRequest, origClientRequest); + util.inherits(clientRequest, origClientRequest); fill(clientRequest.prototype, 'emit', emitWrapper); @@ -80,13 +80,13 @@ function loadWrapper(nativeModule: any): any { // it still points at orig ClientRequest after our monkeypatch; these reimpls // just get that reference updated to use our new ClientRequest fill(originalModule, 'request', function(): any { - return function(options: ClientRequestArgs, callback: () => void): any { - return new originalModule.ClientRequest(options, callback) as ClientRequest; + return function(options: http.ClientRequestArgs, callback: () => void): any { + return new originalModule.ClientRequest(options, callback) as http.ClientRequest; }; }); fill(originalModule, 'get', function(): any { - return function(options: ClientRequestArgs, callback: () => void): any { + return function(options: http.ClientRequestArgs, callback: () => void): any { const req = originalModule.request(options, callback); req.end(); return req; @@ -101,8 +101,8 @@ function loadWrapper(nativeModule: any): any { /** * Wrapper function for request's `emit` calls */ -function emitWrapper(origEmit: EventListener): (event: string, response: ServerResponse) => EventListener { - return function(this: SentryRequest, event: string, response: ServerResponse): any { +function emitWrapper(origEmit: EventListener): (event: string, response: http.ServerResponse) => EventListener { + return function(this: SentryRequest, event: string, response: http.ServerResponse): any { // I'm not sure why but Node.js (at least in v8.X) // is emitting all events twice :| if (lastResponse === undefined || lastResponse !== response) { diff --git a/packages/node/src/parsers.ts b/packages/node/src/parsers.ts index 4d049026aff9..842c19833732 100644 --- a/packages/node/src/parsers.ts +++ b/packages/node/src/parsers.ts @@ -1,7 +1,7 @@ import { SentryEvent, SentryException, StackFrame } from '@sentry/types'; import { readFileAsync } from '@sentry/utils/fs'; import { snipLine } from '@sentry/utils/string'; -import { basename, dirname } from 'path'; +import * as path from 'path'; import * as stacktrace from 'stack-trace'; const LINES_OF_CONTEXT: number = 7; @@ -30,7 +30,7 @@ function getTransaction(frame: StackFrame): string { return frame.module || frame.function ? `${frame.module || '?'} at ${frame.function || '?'}` : ''; } -const mainModule: string = `${(require.main && require.main.filename && dirname(require.main.filename)) || +const mainModule: string = `${(require.main && require.main.filename && path.dirname(require.main.filename)) || global.process.cwd()}/`; /** JSDoc */ @@ -40,8 +40,8 @@ function getModule(filename: string, base?: string): string { } // It's specifically a module - const file = basename(filename, '.js'); - filename = dirname(filename); // tslint:disable-line:no-parameter-reassignment + const file = path.basename(filename, '.js'); + filename = path.dirname(filename); // tslint:disable-line:no-parameter-reassignment let n = filename.lastIndexOf('/node_modules/'); if (n > -1) { // /node_modules/ is 14 chars diff --git a/packages/node/src/transports/base.ts b/packages/node/src/transports/base.ts index ac533000bba5..d609f9dab1c1 100644 --- a/packages/node/src/transports/base.ts +++ b/packages/node/src/transports/base.ts @@ -3,12 +3,13 @@ import { SentryEvent, SentryResponse, Status, Transport, TransportOptions } from import { serialize } from '@sentry/utils/object'; import * as http from 'http'; import * as https from 'https'; +import * as url from 'url'; import { SDK_NAME, SDK_VERSION } from '../version'; /** Internal used interface for typescript */ export interface HTTPRequest { request( - options: http.RequestOptions | string | URL, + options: http.RequestOptions | https.RequestOptions | string | url.URL, callback?: (res: http.IncomingMessage) => void, ): http.ClientRequest; } @@ -27,7 +28,7 @@ export abstract class BaseTransport implements Transport { } /** Returns a build request option object used by request */ - protected getRequestOptions(): http.RequestOptions { + protected getRequestOptions(): http.RequestOptions | https.RequestOptions { const headers = { ...this.api.getRequestHeaders(SDK_NAME, SDK_VERSION), ...this.options.headers,