Skip to content

Commit 5339751

Browse files
authored
ref: Remove circular dependency in @sentry/node (#3335)
1 parent defce67 commit 5339751

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

packages/node/src/handlers.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@
33
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
44
import { extractTraceparentData, Span } from '@sentry/tracing';
55
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
6-
import { forget, isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
6+
import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
77
import * as cookie from 'cookie';
88
import * as domain from 'domain';
99
import * as http from 'http';
1010
import * as os from 'os';
1111
import * as url from 'url';
1212

13-
import { NodeClient } from './client';
1413
import { flush } from './sdk';
1514

16-
const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
17-
1815
export interface ExpressRequest {
1916
baseUrl?: string;
2017
connection?: {
@@ -471,32 +468,3 @@ export function errorHandler(options?: {
471468
next(error);
472469
};
473470
}
474-
475-
/**
476-
* @hidden
477-
*/
478-
export function logAndExitProcess(error: Error): void {
479-
// eslint-disable-next-line no-console
480-
console.error(error && error.stack ? error.stack : error);
481-
482-
const client = getCurrentHub().getClient<NodeClient>();
483-
484-
if (client === undefined) {
485-
logger.warn('No NodeClient was defined, we are exiting the process now.');
486-
global.process.exit(1);
487-
return;
488-
}
489-
490-
const options = client.getOptions();
491-
const timeout =
492-
(options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
493-
DEFAULT_SHUTDOWN_TIMEOUT;
494-
forget(
495-
client.close(timeout).then((result: boolean) => {
496-
if (!result) {
497-
logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
498-
}
499-
global.process.exit(1);
500-
}),
501-
);
502-
}

packages/node/src/integrations/onuncaughtexception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Integration, Severity } from '@sentry/types';
33
import { logger } from '@sentry/utils';
44

55
import { NodeClient } from '../client';
6-
import { logAndExitProcess } from '../handlers';
6+
import { logAndExitProcess } from './utils/errorhandling';
77

88
/** Global Promise Rejection handler */
99
export class OnUncaughtException implements Integration {

packages/node/src/integrations/onunhandledrejection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getCurrentHub, Scope } from '@sentry/core';
22
import { Integration } from '@sentry/types';
33
import { consoleSandbox } from '@sentry/utils';
44

5-
import { logAndExitProcess } from '../handlers';
5+
import { logAndExitProcess } from './utils/errorhandling';
66

77
type UnhandledRejectionMode = 'none' | 'warn' | 'strict';
88

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { getCurrentHub } from '@sentry/core';
2+
import { forget, logger } from '@sentry/utils';
3+
4+
import { NodeClient } from '../../client';
5+
6+
const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
7+
8+
/**
9+
* @hidden
10+
*/
11+
export function logAndExitProcess(error: Error): void {
12+
// eslint-disable-next-line no-console
13+
console.error(error && error.stack ? error.stack : error);
14+
15+
const client = getCurrentHub().getClient<NodeClient>();
16+
17+
if (client === undefined) {
18+
logger.warn('No NodeClient was defined, we are exiting the process now.');
19+
global.process.exit(1);
20+
return;
21+
}
22+
23+
const options = client.getOptions();
24+
const timeout =
25+
(options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
26+
DEFAULT_SHUTDOWN_TIMEOUT;
27+
forget(
28+
client.close(timeout).then((result: boolean) => {
29+
if (!result) {
30+
logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
31+
}
32+
global.process.exit(1);
33+
}),
34+
);
35+
}

0 commit comments

Comments
 (0)