Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Log instance id from render instead of random id and catch unhandled #3433

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/server/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ import { refreshConnectionsCron } from './refreshConnections.js';
const { NANGO_MIGRATE_AT_START = 'true' } = process.env;
const logger = getLogger('Server');

process.on('unhandledRejection', (reason) => {
logger.error('Received unhandledRejection...', reason);
// not closing on purpose
});

process.on('uncaughtException', (e) => {
logger.error('Received uncaughtException...', e);
// not closing on purpose
});

const app = express();
app.disable('x-powered-by');
app.set('trust proxy', 1);
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { serializeError } from 'serialize-error';
* Transform any Error or primitive to a json object
*/
export function errorToObject(err: unknown) {
return serializeError(err);
return serializeError(err, { maxDepth: 5 });
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/utils/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import winston from 'winston';
import type { Logform, Logger } from 'winston';
import colors from '@colors/colors';
import { isCloud, isEnterprise, isTest } from './environment/detection.js';
import { nanoid } from 'nanoid';

const SPLAT = Symbol.for('splat');
const level = process.env['LOG_LEVEL'] ? process.env['LOG_LEVEL'] : isTest ? 'error' : 'info';
Expand Down Expand Up @@ -42,7 +41,7 @@ if (!isCloud && !isEnterprise) {
})
];
} else {
const instanceId = isCloud ? ` ${nanoid(6)}` : '';
const instanceId = isCloud && process.env['RENDER_INSTANCE_ID'] ? ` ${process.env['RENDER_INSTANCE_ID']}` : '';

formatters = [
winston.format.printf((info) => {
Expand Down
Loading