@@ -14,6 +14,7 @@ import {
1414 validatePerformanceMetric ,
1515 validateSessionId ,
1616} from "../utils/validation" ;
17+ import { logger } from "./logger" ;
1718import { sendEvent , sendEventBatch } from "./producer" ;
1819import { checkDuplicate } from "./security" ;
1920
@@ -86,11 +87,11 @@ export async function insertError(
8687
8788 try {
8889 sendEvent ( "analytics-errors" , errorEvent ) ;
89- } catch ( err ) {
90- console . error ( "Failed to queue error event" , {
91- error : err as Error ,
92- eventId ,
93- } ) ;
90+ } catch ( error ) {
91+ logger . error (
92+ { error, eventId } ,
93+ "Failed to queue error event"
94+ ) ;
9495 }
9596}
9697
@@ -152,11 +153,11 @@ export async function insertWebVitals(
152153
153154 try {
154155 sendEvent ( "analytics-web-vitals" , webVitalsEvent ) ;
155- } catch ( err ) {
156- console . error ( "Failed to queue web vitals event" , {
157- error : err as Error ,
158- eventId ,
159- } ) ;
156+ } catch ( error ) {
157+ logger . error (
158+ { error, eventId } ,
159+ "Failed to queue web vitals event"
160+ ) ;
160161 // Don't throw - event is buffered or sent async
161162 }
162163}
@@ -206,11 +207,11 @@ export async function insertCustomEvent(
206207
207208 try {
208209 sendEvent ( "analytics-custom-events" , customEvent ) ;
209- } catch ( err ) {
210- console . error ( "Failed to queue custom event" , {
211- error : err as Error ,
212- eventId ,
213- } ) ;
210+ } catch ( error ) {
211+ logger . error (
212+ { error, eventId } ,
213+ "Failed to queue custom event"
214+ ) ;
214215 // Don't throw - event is buffered or sent async
215216 }
216217}
@@ -258,11 +259,11 @@ export async function insertOutgoingLink(
258259
259260 try {
260261 sendEvent ( "analytics-outgoing-links" , outgoingLinkEvent ) ;
261- } catch ( err ) {
262- console . error ( "Failed to queue outgoing link event" , {
263- error : err as Error ,
264- eventId ,
265- } ) ;
262+ } catch ( error ) {
263+ logger . error (
264+ { error, eventId } ,
265+ "Failed to queue outgoing link event"
266+ ) ;
266267 }
267268}
268269
@@ -380,11 +381,11 @@ export async function insertTrackEvent(
380381
381382 try {
382383 sendEvent ( "analytics-events" , trackEvent ) ;
383- } catch ( err ) {
384- console . error ( "Failed to queue track event" , {
385- error : err as Error ,
386- eventId ,
387- } ) ;
384+ } catch ( error ) {
385+ logger . error (
386+ { error, eventId } ,
387+ "Failed to queue track event"
388+ ) ;
388389 }
389390}
390391
@@ -397,12 +398,11 @@ export async function insertTrackEventsBatch(
397398
398399 try {
399400 await sendEventBatch ( "analytics-events" , events ) ;
400- } catch ( err ) {
401- console . error ( "Failed to queue track events batch" , {
402- error : err as Error ,
403- count : events . length ,
404- } ) ;
405- // Don't throw - events are buffered
401+ } catch ( error ) {
402+ logger . error (
403+ { error, count : events . length } ,
404+ "Failed to queue track events batch"
405+ ) ;
406406 }
407407}
408408
@@ -413,11 +413,11 @@ export async function insertErrorsBatch(events: ErrorEvent[]): Promise<void> {
413413
414414 try {
415415 await sendEventBatch ( "analytics-errors" , events ) ;
416- } catch ( err ) {
417- console . error ( "Failed to queue errors batch" , {
418- error : err as Error ,
419- count : events . length ,
420- } ) ;
416+ } catch ( error ) {
417+ logger . error (
418+ { error, count : events . length } ,
419+ "Failed to queue errors batch"
420+ ) ;
421421 }
422422}
423423
@@ -430,11 +430,11 @@ export async function insertWebVitalsBatch(
430430
431431 try {
432432 await sendEventBatch ( "analytics-web-vitals" , events ) ;
433- } catch ( err ) {
434- console . error ( "Failed to queue web vitals batch" , {
435- error : err as Error ,
436- count : events . length ,
437- } ) ;
433+ } catch ( error ) {
434+ logger . error (
435+ { error, count : events . length } ,
436+ "Failed to queue web vitals batch"
437+ ) ;
438438 }
439439}
440440
@@ -447,11 +447,11 @@ export async function insertCustomEventsBatch(
447447
448448 try {
449449 await sendEventBatch ( "analytics-custom-events" , events ) ;
450- } catch ( err ) {
451- console . error ( "Failed to queue custom events batch" , {
452- error : err as Error ,
453- count : events . length ,
454- } ) ;
450+ } catch ( error ) {
451+ logger . error (
452+ { error, count : events . length } ,
453+ "Failed to queue custom events batch"
454+ ) ;
455455 }
456456}
457457
@@ -464,10 +464,10 @@ export async function insertOutgoingLinksBatch(
464464
465465 try {
466466 await sendEventBatch ( "analytics-outgoing-links" , events ) ;
467- } catch ( err ) {
468- console . error ( "Failed to queue outgoing links batch" , {
469- error : err as Error ,
470- count : events . length ,
471- } ) ;
467+ } catch ( error ) {
468+ logger . error (
469+ { error, count : events . length } ,
470+ "Failed to queue outgoing links batch"
471+ ) ;
472472 }
473473}
0 commit comments