-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
25 lines (23 loc) · 933 Bytes
/
instrumentation.ts
File metadata and controls
25 lines (23 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
const { runStartupTasks } = await import('./lib/startup/index')
const { loggers } = await import('./lib/logger')
const logger = loggers.startup
await runStartupTasks()
logger.debug('Startup tasks completed via instrumentation hook')
// Monitor memory usage in production
if (process.env.NODE_ENV === 'production') {
setInterval(() => {
const memUsage = process.memoryUsage()
if (memUsage.heapUsed > 1024 * 1024 * 1024) {
// 1GB threshold
logger.warn('High memory usage detected', {
heapUsed: Math.round(memUsage.heapUsed / 1024 / 1024) + 'MB',
heapTotal: Math.round(memUsage.heapTotal / 1024 / 1024) + 'MB',
external: Math.round(memUsage.external / 1024 / 1024) + 'MB',
})
}
}, 60000) // Check every minute
}
}
}