-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Remove circular dependency in @sentry/node (#3335)
- Loading branch information
Showing
4 changed files
with
38 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}), | ||
); | ||
} |