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

[QUICK-FIX] - Added an ID for console errors #1659

Closed
wants to merge 2 commits into from
Closed
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 src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { elapsedTimeMetrics } from "config/statsd";
import sslify from "express-sslify";
import helmet from "helmet";
import { RootRouter } from "routes/router";
import { v4 as newUUID } from "uuid";

export const getFrontendApp = (octokitApp: App): Express => {
const app = express();
Expand All @@ -27,6 +28,15 @@ export const getFrontendApp = (octokitApp: App): Express => {
// Add github client middleware which uses the octokit app
app.use(getGithubClientMiddleware(octokitApp));

//Error handling
// eslint-disable-next-line @typescript-eslint/no-unused-vars
app.use((err, req, res, _next) => {
const traceId = newUUID();
req.log.error({ err }, "Failed: " + err.message);
res.status(500).send("Failed: ", traceId);
});


// Add all routes
app.use(RootRouter);

Expand Down
2 changes: 2 additions & 0 deletions src/config/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Logger, { createLogger, LogLevel, Serializers, Stream } from "bunyan";
import { isArray, isString, merge, omit } from "lodash";
import { SafeRawLogStream, UnsafeRawLogStream } from "utils/logger-utils";
import { v4 as newUUID } from "uuid";

function censorUrl(url) {
if (!url) {
Expand Down Expand Up @@ -110,6 +111,7 @@ interface LoggerOptions {
export const getLogger = (name: string, options: LoggerOptions = {}): Logger => {
return createLogger(merge<Logger.LoggerOptions, LoggerOptions>({
name,
id: newUUID(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not needed because we add one in frontend-middleware-logger, don't we?

streams: [
loggerStreamSafe(),
loggerStreamUnsafe()
Expand Down