app.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import type Logger from 'bunyan';
  2. import { initInstrumentation, setupAdditionalResourceAttributes, startOpenTelemetry } from '~/features/opentelemetry/server';
  3. import loggerFactory from '~/utils/logger';
  4. import { hasProcessFlag } from '~/utils/process-utils';
  5. const logger: Logger = loggerFactory('growi');
  6. /** **********************************
  7. * Main Process
  8. ********************************** */
  9. process.on('uncaughtException', (err?: Error) => {
  10. logger.error('Uncaught Exception: ', err);
  11. });
  12. process.on('unhandledRejection', (reason, p) => {
  13. logger.error('Unhandled Rejection: Promise:', p, 'Reason:', reason);
  14. });
  15. async function main() {
  16. try {
  17. // Initialize OpenTelemetry
  18. await initInstrumentation();
  19. const Crowi = (await import('./crowi')).default;
  20. const growi = new Crowi();
  21. const server = await growi.start();
  22. // Start OpenTelemetry
  23. await setupAdditionalResourceAttributes();
  24. startOpenTelemetry();
  25. if (hasProcessFlag('ci')) {
  26. logger.info('"--ci" flag is detected. Exit process.');
  27. server.close(() => {
  28. process.exit();
  29. });
  30. }
  31. }
  32. catch (err) {
  33. logger.error('An error occurred, unable to start the server');
  34. logger.error(err);
  35. process.exit(1);
  36. }
  37. }
  38. main();