forked from elastic/apm-agent-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-next.js
29 lines (24 loc) · 914 Bytes
/
start-next.js
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
26
27
28
29
/*
* Copyright Elasticsearch B.V. and other contributors where applicable.
* Licensed under the BSD 2-Clause License; you may not use this file except in
* compliance with the BSD 2-Clause License.
*/
'use strict';
// Use this module via `node --require=elastic-apm-node/start-next.js ...`
// to monitor a Next.js app with Elastic APM.
const apm = require('./start.js');
if (apm.isStarted()) {
// Flush APM data on server process termination.
// https://nextjs.org/docs/deployment#manual-graceful-shutdowns
// Note: Support for NEXT_MANUAL_SIG_HANDLE was added in [email protected],
// so this `apm.flush()` will only happen in that and later versions.
process.env.NEXT_MANUAL_SIG_HANDLE = 1;
const flushApmAndExit = () => {
apm.flush(() => {
process.exit(0);
});
};
process.on('SIGTERM', flushApmAndExit);
process.on('SIGINT', flushApmAndExit);
}
module.exports = apm;