Skip to content

Commit 976edc1

Browse files
committed
ref: prefix all external and native modules with package name
1 parent 866be27 commit 976edc1

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

packages/node/src/handlers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { getHubFromCarrier, Scope } from '@sentry/hub';
33
import { SentryEvent, Severity } from '@sentry/types';
44
import { forget } from '@sentry/utils/async';
55
import { serialize } from '@sentry/utils/object';
6-
import { parse as parseCookie } from 'cookie';
6+
import * as cookie from 'cookie';
77
import * as domain from 'domain';
88
import * as http from 'http';
9-
import { hostname } from 'os';
10-
import { parse as parseUrl } from 'url';
9+
import * as os from 'os';
10+
import * as url from 'url';
1111
import { NodeClient } from './client';
1212
import { getCurrentHub } from './hub';
1313

@@ -46,10 +46,10 @@ function extractRequestData(req: { [key: string]: any }): { [key: string]: strin
4646
// query string:
4747
// node: req.url (raw)
4848
// express, koa: req.query
49-
const query = req.query || parseUrl(originalUrl || '', true).query;
49+
const query = req.query || url.parse(originalUrl || '', true).query;
5050
// cookies:
5151
// node, express, koa: req.headers.cookie
52-
const cookies = parseCookie(headers.cookie || '');
52+
const cookies = cookie.parse(headers.cookie || '');
5353
// body data:
5454
// node, express, koa: req.body
5555
let data = req.body;
@@ -122,7 +122,7 @@ function parseRequest(
122122
...event.request,
123123
...extractRequestData(req),
124124
},
125-
server_name: global.process.env.SENTRY_NAME || hostname(),
125+
server_name: global.process.env.SENTRY_NAME || os.hostname(),
126126
};
127127

128128
if (req.user) {

packages/node/src/integrations/console.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Integration, Severity } from '@sentry/types';
22
import { fill } from '@sentry/utils/object';
3-
import { format } from 'util';
3+
import * as util from 'util';
44
import { getCurrentHub } from '../hub';
55

66
/**
@@ -59,7 +59,7 @@ function consoleWrapper(originalModule: any): any {
5959
{
6060
category: 'console',
6161
level: sentryLevel,
62-
message: format.apply(undefined, arguments),
62+
message: util.format.apply(undefined, arguments),
6363
},
6464
{
6565
input: [...arguments],

packages/node/src/integrations/http.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Integration } from '@sentry/types';
22
import { fill } from '@sentry/utils/object';
3-
import { ClientRequest, ClientRequestArgs, IncomingMessage, ServerResponse } from 'http';
4-
import { inherits } from 'util';
3+
import * as http from 'http';
4+
import * as util from 'util';
55
import { getCurrentHub } from '../hub';
66

7-
let lastResponse: ServerResponse | undefined;
7+
let lastResponse: http.ServerResponse | undefined;
88

99
/**
1010
* Request interface which can carry around unified url
1111
* independently of used framework
1212
*/
13-
interface SentryRequest extends IncomingMessage {
13+
interface SentryRequest extends http.IncomingMessage {
1414
__ravenBreadcrumbUrl?: string;
1515
}
1616

@@ -20,7 +20,7 @@ interface SentryRequest extends IncomingMessage {
2020
* @param options url that should be returned or an object containing it's parts.
2121
* @returns constructed url
2222
*/
23-
function createBreadcrumbUrl(options: string | ClientRequestArgs): string {
23+
function createBreadcrumbUrl(options: string | http.ClientRequestArgs): string {
2424
// We could just always reconstruct this from this.agent, this._headers, this.path, etc
2525
// but certain other http-instrumenting libraries (like nock, which we use for tests) fail to
2626
// maintain the guarantee that after calling origClientRequest, those fields will be populated
@@ -54,7 +54,7 @@ function loadWrapper(nativeModule: any): any {
5454
const origClientRequest = originalModule.ClientRequest;
5555
const clientRequest = function(
5656
this: SentryRequest,
57-
options: ClientRequestArgs | string,
57+
options: http.ClientRequestArgs | string,
5858
callback: () => void,
5959
): any {
6060
// Note: this won't capture a breadcrumb if a response never comes
@@ -68,7 +68,7 @@ function loadWrapper(nativeModule: any): any {
6868
this.__ravenBreadcrumbUrl = createBreadcrumbUrl(options);
6969
};
7070

71-
inherits(clientRequest, origClientRequest);
71+
util.inherits(clientRequest, origClientRequest);
7272

7373
fill(clientRequest.prototype, 'emit', emitWrapper);
7474

@@ -80,13 +80,13 @@ function loadWrapper(nativeModule: any): any {
8080
// it still points at orig ClientRequest after our monkeypatch; these reimpls
8181
// just get that reference updated to use our new ClientRequest
8282
fill(originalModule, 'request', function(): any {
83-
return function(options: ClientRequestArgs, callback: () => void): any {
84-
return new originalModule.ClientRequest(options, callback) as ClientRequest;
83+
return function(options: http.ClientRequestArgs, callback: () => void): any {
84+
return new originalModule.ClientRequest(options, callback) as http.ClientRequest;
8585
};
8686
});
8787

8888
fill(originalModule, 'get', function(): any {
89-
return function(options: ClientRequestArgs, callback: () => void): any {
89+
return function(options: http.ClientRequestArgs, callback: () => void): any {
9090
const req = originalModule.request(options, callback);
9191
req.end();
9292
return req;
@@ -101,8 +101,8 @@ function loadWrapper(nativeModule: any): any {
101101
/**
102102
* Wrapper function for request's `emit` calls
103103
*/
104-
function emitWrapper(origEmit: EventListener): (event: string, response: ServerResponse) => EventListener {
105-
return function(this: SentryRequest, event: string, response: ServerResponse): any {
104+
function emitWrapper(origEmit: EventListener): (event: string, response: http.ServerResponse) => EventListener {
105+
return function(this: SentryRequest, event: string, response: http.ServerResponse): any {
106106
// I'm not sure why but Node.js (at least in v8.X)
107107
// is emitting all events twice :|
108108
if (lastResponse === undefined || lastResponse !== response) {

packages/node/src/parsers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SentryEvent, SentryException, StackFrame } from '@sentry/types';
22
import { readFileAsync } from '@sentry/utils/fs';
33
import { snipLine } from '@sentry/utils/string';
4-
import { basename, dirname } from 'path';
4+
import * as path from 'path';
55
import * as stacktrace from 'stack-trace';
66

77
const LINES_OF_CONTEXT: number = 7;
@@ -30,7 +30,7 @@ function getTransaction(frame: StackFrame): string {
3030
return frame.module || frame.function ? `${frame.module || '?'} at ${frame.function || '?'}` : '<unknown>';
3131
}
3232

33-
const mainModule: string = `${(require.main && require.main.filename && dirname(require.main.filename)) ||
33+
const mainModule: string = `${(require.main && require.main.filename && path.dirname(require.main.filename)) ||
3434
global.process.cwd()}/`;
3535

3636
/** JSDoc */
@@ -40,8 +40,8 @@ function getModule(filename: string, base?: string): string {
4040
}
4141

4242
// It's specifically a module
43-
const file = basename(filename, '.js');
44-
filename = dirname(filename); // tslint:disable-line:no-parameter-reassignment
43+
const file = path.basename(filename, '.js');
44+
filename = path.dirname(filename); // tslint:disable-line:no-parameter-reassignment
4545
let n = filename.lastIndexOf('/node_modules/');
4646
if (n > -1) {
4747
// /node_modules/ is 14 chars

0 commit comments

Comments
 (0)