app.ts 1.2 KB

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