@@ -6,7 +6,6 @@ import type {
66 ErrorEvent ,
77 WebVitalsEvent ,
88} from "@databuddy/db" ;
9- import { record , setAttributes } from "@elysiajs/opentelemetry" ;
109import { getGeo } from "../utils/ip-geo" ;
1110import { parseUserAgent } from "../utils/user-agent" ;
1211import {
@@ -18,6 +17,7 @@ import {
1817import { logger } from "./logger" ;
1918import { sendEvent , sendEventBatch } from "./producer" ;
2019import { checkDuplicate , getDailySalt , saltAnonymousId } from "./security" ;
20+ import { record , setAttributes } from "./tracing" ;
2121
2222/**
2323 * Insert an error event into the database
@@ -70,7 +70,8 @@ export function insertError(
7070 VALIDATION_LIMITS . SHORT_STRING_MAX_LENGTH
7171 ) ,
7272 session_id : validateSessionId ( payload . sessionId ) ,
73- timestamp : typeof payload . timestamp === "number" ? payload . timestamp : now ,
73+ timestamp :
74+ typeof payload . timestamp === "number" ? payload . timestamp : now ,
7475 path : sanitizeString ( payload . path , VALIDATION_LIMITS . STRING_MAX_LENGTH ) ,
7576 message : sanitizeString (
7677 payload . message ,
@@ -108,10 +109,7 @@ export function insertError(
108109 try {
109110 sendEvent ( "analytics-errors" , errorEvent ) ;
110111 } catch ( error ) {
111- logger . error (
112- { error, eventId } ,
113- "Failed to queue error event"
114- ) ;
112+ logger . error ( { error, eventId } , "Failed to queue error event" ) ;
115113 }
116114 } ) ;
117115}
@@ -175,10 +173,7 @@ export async function insertWebVitals(
175173 try {
176174 sendEvent ( "analytics-web-vitals" , webVitalsEvent ) ;
177175 } catch ( error ) {
178- logger . error (
179- { error, eventId } ,
180- "Failed to queue web vitals event"
181- ) ;
176+ logger . error ( { error, eventId } , "Failed to queue web vitals event" ) ;
182177 // Don't throw - event is buffered or sent async
183178 }
184179}
@@ -229,10 +224,7 @@ export async function insertCustomEvent(
229224 try {
230225 sendEvent ( "analytics-custom-events" , customEvent ) ;
231226 } catch ( error ) {
232- logger . error (
233- { error, eventId } ,
234- "Failed to queue custom event"
235- ) ;
227+ logger . error ( { error, eventId } , "Failed to queue custom event" ) ;
236228 // Don't throw - event is buffered or sent async
237229 }
238230}
@@ -281,10 +273,7 @@ export async function insertOutgoingLink(
281273 try {
282274 sendEvent ( "analytics-outgoing-links" , outgoingLinkEvent ) ;
283275 } catch ( error ) {
284- logger . error (
285- { error, eventId } ,
286- "Failed to queue outgoing link event"
287- ) ;
276+ logger . error ( { error, eventId } , "Failed to queue outgoing link event" ) ;
288277 }
289278}
290279
@@ -370,7 +359,10 @@ export function insertTrackEvent(
370359 ) ,
371360 url : sanitizeString ( trackData . path , VALIDATION_LIMITS . STRING_MAX_LENGTH ) ,
372361 path : sanitizeString ( trackData . path , VALIDATION_LIMITS . STRING_MAX_LENGTH ) ,
373- title : sanitizeString ( trackData . title , VALIDATION_LIMITS . STRING_MAX_LENGTH ) ,
362+ title : sanitizeString (
363+ trackData . title ,
364+ VALIDATION_LIMITS . STRING_MAX_LENGTH
365+ ) ,
374366
375367 ip : anonymizedIP || "" ,
376368 user_agent : "" ,
@@ -412,7 +404,9 @@ export function insertTrackEvent(
412404 connection_time : validatePerformanceMetric ( trackData . connection_time ) ,
413405 render_time : validatePerformanceMetric ( trackData . render_time ) ,
414406 redirect_time : validatePerformanceMetric ( trackData . redirect_time ) ,
415- domain_lookup_time : validatePerformanceMetric ( trackData . domain_lookup_time ) ,
407+ domain_lookup_time : validatePerformanceMetric (
408+ trackData . domain_lookup_time
409+ ) ,
416410
417411 properties : trackData . properties
418412 ? JSON . stringify ( trackData . properties )
@@ -431,10 +425,7 @@ export function insertTrackEvent(
431425 try {
432426 sendEvent ( "analytics-events" , trackEvent ) ;
433427 } catch ( error ) {
434- logger . error (
435- { error, eventId } ,
436- "Failed to queue track event"
437- ) ;
428+ logger . error ( { error, eventId } , "Failed to queue track event" ) ;
438429 }
439430 } ) ;
440431}
@@ -485,9 +476,7 @@ export function insertErrorsBatch(events: ErrorEvent[]): Promise<void> {
485476 } ) ;
486477}
487478
488- export function insertWebVitalsBatch (
489- events : WebVitalsEvent [ ]
490- ) : Promise < void > {
479+ export function insertWebVitalsBatch ( events : WebVitalsEvent [ ] ) : Promise < void > {
491480 return record ( "insertWebVitalsBatch" , async ( ) => {
492481 if ( events . length === 0 ) {
493482 return ;
@@ -509,9 +498,7 @@ export function insertWebVitalsBatch(
509498 } ) ;
510499}
511500
512- export function insertCustomEventsBatch (
513- events : CustomEvent [ ]
514- ) : Promise < void > {
501+ export function insertCustomEventsBatch ( events : CustomEvent [ ] ) : Promise < void > {
515502 return record ( "insertCustomEventsBatch" , async ( ) => {
516503 if ( events . length === 0 ) {
517504 return ;
0 commit comments