11/* This file is inspired by https://github.com/getsentry/sentry-javascript/blob/9.4.0/packages/node/src/sdk/index.ts */
22
3- import type {
4- Client ,
5- ServerRuntimeClientOptions ,
6- Transport ,
7- } from "@sentry/core" ;
3+ import type { ServerRuntimeClientOptions , Transport } from "@sentry/core" ;
84
95import os from "node:os" ;
106import path from "node:path" ;
@@ -18,15 +14,12 @@ import {
1814 ServerRuntimeClient ,
1915 stackParserFromStackParserOptions ,
2016} from "@sentry/core" ;
21- import debug from "debug" ;
2217
2318import { GENERIC_SERVER_NAME } from "./constants.js" ;
2419import { nodeContextIntegration } from "./vendor/integrations/context.js" ;
2520import { contextLinesIntegration } from "./vendor/integrations/contextlines.js" ;
2621import { createGetModuleFromFilename } from "./vendor/utils/module.js" ;
2722
28- const log = debug ( "hardhat:core:sentry:init" ) ;
29-
3023interface GlobalCustomSentryReporterOptions {
3124 /**
3225 * Sentry's DSN
@@ -49,12 +42,6 @@ interface GlobalCustomSentryReporterOptions {
4942 * See the transport module for the different options.
5043 */
5144 transport : Transport ;
52-
53- /**
54- * If `true`, the global unhandled rejection and uncaught exception handlers
55- * will be installed.
56- */
57- installGlobalHandlers ?: boolean ;
5845}
5946
6047/**
@@ -72,12 +59,9 @@ interface GlobalCustomSentryReporterOptions {
7259 * The reason that this uses the global instance of sentry (by calling
7360 * initAndBind), is that using the client directly doesn't work with the linked
7461 * errors integration.
75- *
76- * Calling `init` also has an option to set global unhandled rejection and
77- * uncaught exception handlers.
7862 */
7963export function init ( options : GlobalCustomSentryReporterOptions ) : void {
80- const client = initAndBind < ServerRuntimeClient , ServerRuntimeClientOptions > (
64+ initAndBind < ServerRuntimeClient , ServerRuntimeClientOptions > (
8165 ServerRuntimeClient ,
8266 {
8367 dsn : options . dsn ,
@@ -113,48 +97,4 @@ export function init(options: GlobalCustomSentryReporterOptions): void {
11397 ) ,
11498 } ,
11599 ) ;
116-
117- setupGlobalUnhandledErrorHandlers ( client ) ;
118- }
119-
120- function createUnhandledErrorListener (
121- client : Client ,
122- isPromiseRejection : boolean ,
123- ) {
124- const description = isPromiseRejection
125- ? "Unhandled promise rejection"
126- : "Uncaught exception" ;
127-
128- async function listener ( error : Error | unknown ) {
129- log ( description , error ) ;
130-
131- client . captureException ( error , {
132- captureContext : {
133- level : "fatal" ,
134- } ,
135- mechanism : {
136- handled : false ,
137- type : "onuncaughtexception" ,
138- } ,
139- } ) ;
140-
141- await client . flush ( 100 ) ;
142- await client . close ( 100 ) ;
143-
144- console . error ( ) ;
145- console . error ( `${ description } :` ) ;
146- console . error ( ) ;
147- console . error ( error ) ;
148-
149- process . exit ( 1 ) ;
150- }
151-
152- return listener ;
153- }
154-
155- function setupGlobalUnhandledErrorHandlers ( client : Client ) {
156- log ( "Setting up global unhandled error handlers" ) ;
157-
158- process . on ( "uncaughtException" , createUnhandledErrorListener ( client , false ) ) ;
159- process . on ( "unhandledRejection" , createUnhandledErrorListener ( client , true ) ) ;
160100}
0 commit comments