Edge Runtime
Lightweight logging in Edge Functions and Middleware. Vestig automatically adapts to the edge environment with reduced bundle size.
UUnknownClient
Runtime Detection
Vestig automatically detects the edge environment
Result
Runtime: unknown
Is Edge: false
Request ID: 8bb5fd57-0ce7-4326-87c5-6f0fcc046625
Trace ID: 42d00112261d5d862ea237d0c0bbd58c
Runtime Capabilities
APIs available in the current edge environment
Result
AsyncLocalStorage
Process
Performance
Console
Crypto
Edge Middleware
How to use vestig in Next.js Edge Middleware
typescript
// middleware.ts
import { createVestigMiddleware } from '@vestig/next/middleware'
export const middleware = createVestigMiddleware({
// Skip static assets and API routes
skipPaths: ['/_next', '/favicon.ico', '/api/health'],
// Custom request ID header
requestIdHeader: 'x-request-id',
// Log levels for requests/responses
requestLogLevel: 'debug',
responseLogLevel: 'info',
})
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
}Edge API Route
Logging in Edge API routes with correlation
typescript
// app/api/edge-example/route.ts
import { withVestig } from '@vestig/next'
export const runtime = 'edge'
export const GET = withVestig(
async (request, { log, ctx }) => {
log.info('Edge API request received', {
requestId: ctx.requestId,
geo: request.geo, // Vercel Edge geo data
})
// Your edge logic here
const data = await fetchFromEdgeCache()
log.debug('Response ready', { cached: !!data })
return Response.json(data)
},
{ namespace: 'api:edge-example' }
)! Edge Considerations
- ›No File System — FileTransport is not available in edge runtime
- ›Limited APIs — Some Node.js APIs like process.env may be restricted
- ›Global Context — Uses global context manager instead of AsyncLocalStorage
- ›Bundle Size — Vestig automatically tree-shakes unused features
— Key Features
- ›Zero Config — Works automatically in Vercel Edge and Cloudflare Workers
- ›Auto Detection — Vestig detects edge runtime and adapts accordingly
- ›Correlation IDs — Request correlation works across edge and origin
- ›Minimal Bundle — Tree-shakeable design keeps edge bundles small
- ›Same API — Use the same logging API as server and client