@@ -16,9 +16,11 @@ export interface ErrorReporter {
1616
1717class HttpErrorReporter implements ErrorReporter {
1818 private readonly url : string ;
19+ private readonly apiKey : string ;
1920
20- constructor ( url : string ) {
21+ constructor ( url : string , apiKey : string ) {
2122 this . url = url ;
23+ this . apiKey = apiKey ;
2224 }
2325
2426 async reportError ( {
@@ -45,8 +47,8 @@ class HttpErrorReporter implements ErrorReporter {
4547
4648 try {
4749 await axios . post ( this . url , body , {
48- headers : { 'Content-Type' : 'application/json' } ,
49- timeout : 3000 ,
50+ headers : { 'Content-Type' : 'application/json' , 'x-api-key' : this . apiKey } ,
51+ timeout : 30000 ,
5052 } ) ;
5153 } catch {
5254 // Swallow errors to avoid breaking the app or creating log loops
@@ -56,12 +58,24 @@ class HttpErrorReporter implements ErrorReporter {
5658
5759export function initializeErrorMonitoring ( ) : void {
5860 const monitoringUrl = process . env . MONITORING_URL ?. trim ( ) ;
59- if ( ! monitoringUrl ) return ; // Monitoring disabled; keep local logging only
61+ const instance = process . env . INSTANCE_NAME ?. trim ( ) ;
62+ const apiKey = process . env . ERROR_REPORT_API_KEY ?. trim ( ) ;
63+
64+ if ( ! monitoringUrl || ! instance || ! apiKey ) {
65+ const missing = [
66+ ! monitoringUrl ? 'MONITORING_URL' : null ,
67+ ! instance ? 'INSTANCE_NAME' : null ,
68+ ! apiKey ? 'ERROR_REPORT_API_KEY' : null ,
69+ ]
70+ . filter ( Boolean )
71+ . join ( ', ' ) ;
72+ console . warn ( `[WARN][MONITORING] Monitoring not initialized. Missing env: ${ missing } ` ) ;
73+ return ; // Monitoring disabled; keep local logging only
74+ }
6075
6176 const endpoint = `http://localhost:${ process . env . KADENA_GRAPHQL_API_PORT ?? '3001' } /graphql` ;
62- const instance = process . env . INSTANCE_NAME ?. trim ( ) ;
6377
64- const reporter = new HttpErrorReporter ( monitoringUrl ) ;
78+ const reporter = new HttpErrorReporter ( monitoringUrl , apiKey ) ;
6579 const originalConsoleError = console . error . bind ( console ) ;
6680
6781 const classifySeverity = ( message : string , extra : unknown ) : 'major' | 'degraded' | 'minimal' => {
0 commit comments