MCPcopy Index your code
hub / github.com/simstudioai/sim / sendToProfound

Function sendToProfound

apps/sim/lib/analytics/profound.ts:89–122  ·  view source on GitHub ↗
(request: Request, statusCode: number)

Source from the content-addressed store, hash-verified

87 * Queues a request log entry for the next batch flush to Profound.
88 */
89export function sendToProfound(request: Request, statusCode: number): void {
90 if (!isProfoundEnabled()) return
91
92 try {
93 const url = new URL(request.url)
94 const queryParams: Record<string, string> = {}
95 url.searchParams.forEach((value, key) => {
96 queryParams[key] = value
97 })
98
99 buffer.push({
100 timestamp: new Date().toISOString(),
101 method: request.method,
102 host: getBaseDomain(),
103 path: url.pathname,
104 status_code: statusCode,
105 ip: (() => {
106 const resolved = getClientIp(request)
107 return resolved === 'unknown' ? '0.0.0.0' : resolved
108 })(),
109 user_agent: request.headers.get('user-agent') || '',
110 ...(Object.keys(queryParams).length > 0 && { query_params: queryParams }),
111 ...(request.headers.get('referer') && { referer: request.headers.get('referer')! }),
112 })
113
114 ensureFlushTimer()
115
116 if (buffer.length >= MAX_BATCH_SIZE) {
117 flush().catch(() => {})
118 }
119 } catch (error) {
120 logger.error('Failed to enqueue log entry', error)
121 }
122}

Callers 1

trackFunction · 0.90

Calls 8

getBaseDomainFunction · 0.90
getClientIpFunction · 0.90
isProfoundEnabledFunction · 0.85
ensureFlushTimerFunction · 0.85
errorMethod · 0.80
flushFunction · 0.70
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected