On this page
Error tracking
Last updated
Capture server-side exceptions as $exception events with normalized type, message and stack trace.
Capture errors from your backend as $exception events. The error is normalized into $exception_type, $exception_message, and $exception_stack_trace_raw.
#captureException
try {
await processPayment(order)
} catch (err) {
vtilt.captureException(err, {
distinctId: 'user_123',
properties: { order_id: order.id },
})
}typescript
distinctId is optional but recommended so the exception is attributed to a person. Non-Error values (strings, objects) are accepted and coerced into a message.
In serverless / edge handlers, use captureExceptionImmediate() to send before the runtime is frozen:
export default {
async fetch(req, env, ctx) {
try {
return await handle(req)
} catch (err) {
await vtilt.captureExceptionImmediate(err)
throw err
}
},
}typescript
#Forwarding end-user context
If your handler knows the end user's IP / User-Agent, forward them so the exception is geolocated and attributed the same way a captured event would be:
vtilt.captureException(err, {
distinctId: 'user_123',
ip: req.ip,
userAgent: req.headers['user-agent'],
})typescript