Skip to content

Commit

Permalink
ref: Remove circular dependency in @sentry/node (#3335)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkalliom authored Mar 29, 2021
1 parent defce67 commit 5339751
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
34 changes: 1 addition & 33 deletions packages/node/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
import { extractTraceparentData, Span } from '@sentry/tracing';
import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
import { forget, isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
import * as cookie from 'cookie';
import * as domain from 'domain';
import * as http from 'http';
import * as os from 'os';
import * as url from 'url';

import { NodeClient } from './client';
import { flush } from './sdk';

const DEFAULT_SHUTDOWN_TIMEOUT = 2000;

export interface ExpressRequest {
baseUrl?: string;
connection?: {
Expand Down Expand Up @@ -471,32 +468,3 @@ export function errorHandler(options?: {
next(error);
};
}

/**
* @hidden
*/
export function logAndExitProcess(error: Error): void {
// eslint-disable-next-line no-console
console.error(error && error.stack ? error.stack : error);

const client = getCurrentHub().getClient<NodeClient>();

if (client === undefined) {
logger.warn('No NodeClient was defined, we are exiting the process now.');
global.process.exit(1);
return;
}

const options = client.getOptions();
const timeout =
(options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
DEFAULT_SHUTDOWN_TIMEOUT;
forget(
client.close(timeout).then((result: boolean) => {
if (!result) {
logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
}
global.process.exit(1);
}),
);
}
2 changes: 1 addition & 1 deletion packages/node/src/integrations/onuncaughtexception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Integration, Severity } from '@sentry/types';
import { logger } from '@sentry/utils';

import { NodeClient } from '../client';
import { logAndExitProcess } from '../handlers';
import { logAndExitProcess } from './utils/errorhandling';

/** Global Promise Rejection handler */
export class OnUncaughtException implements Integration {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/integrations/onunhandledrejection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getCurrentHub, Scope } from '@sentry/core';
import { Integration } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';

import { logAndExitProcess } from '../handlers';
import { logAndExitProcess } from './utils/errorhandling';

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

Expand Down
35 changes: 35 additions & 0 deletions packages/node/src/integrations/utils/errorhandling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getCurrentHub } from '@sentry/core';
import { forget, logger } from '@sentry/utils';

import { NodeClient } from '../../client';

const DEFAULT_SHUTDOWN_TIMEOUT = 2000;

/**
* @hidden
*/
export function logAndExitProcess(error: Error): void {
// eslint-disable-next-line no-console
console.error(error && error.stack ? error.stack : error);

const client = getCurrentHub().getClient<NodeClient>();

if (client === undefined) {
logger.warn('No NodeClient was defined, we are exiting the process now.');
global.process.exit(1);
return;
}

const options = client.getOptions();
const timeout =
(options && options.shutdownTimeout && options.shutdownTimeout > 0 && options.shutdownTimeout) ||
DEFAULT_SHUTDOWN_TIMEOUT;
forget(
client.close(timeout).then((result: boolean) => {
if (!result) {
logger.warn('We reached the timeout for emptying the request buffer, still exiting now!');
}
global.process.exit(1);
}),
);
}

0 comments on commit 5339751

Please sign in to comment.