feat: Normalized server logging (#2567)
* feat: Normalize logging * Remove scattered console.error + Sentry.captureException * Remove mention of debug * cleanup dev output * Edge cases, docs * Refactor: Move logger, metrics, sentry under 'logging' folder. Trying to reduce the amount of things under generic 'utils' * cleanup, last few console calls
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
import Queue from "bull";
|
||||
import Redis from "ioredis";
|
||||
import { snakeCase } from "lodash";
|
||||
import Metrics from "../logging/metrics";
|
||||
import { client, subscriber } from "../redis";
|
||||
import * as metrics from "../utils/metrics";
|
||||
import Sentry from "./sentry";
|
||||
|
||||
export function createQueue(name: string) {
|
||||
const prefix = `queue.${snakeCase(name)}`;
|
||||
@@ -26,29 +25,24 @@ export function createQueue(name: string) {
|
||||
});
|
||||
|
||||
queue.on("stalled", () => {
|
||||
metrics.increment(`${prefix}.jobs.stalled`);
|
||||
Metrics.increment(`${prefix}.jobs.stalled`);
|
||||
});
|
||||
|
||||
queue.on("completed", () => {
|
||||
metrics.increment(`${prefix}.jobs.completed`);
|
||||
Metrics.increment(`${prefix}.jobs.completed`);
|
||||
});
|
||||
|
||||
queue.on("error", (err) => {
|
||||
if (process.env.SENTRY_DSN) {
|
||||
Sentry.captureException(err);
|
||||
} else {
|
||||
console.error(err);
|
||||
}
|
||||
metrics.increment(`${prefix}.jobs.errored`);
|
||||
Metrics.increment(`${prefix}.jobs.errored`);
|
||||
});
|
||||
|
||||
queue.on("failed", () => {
|
||||
metrics.increment(`${prefix}.jobs.failed`);
|
||||
Metrics.increment(`${prefix}.jobs.failed`);
|
||||
});
|
||||
|
||||
setInterval(async () => {
|
||||
metrics.gauge(`${prefix}.count`, await queue.count());
|
||||
metrics.gauge(`${prefix}.delayed_count`, await queue.getDelayedCount());
|
||||
Metrics.gauge(`${prefix}.count`, await queue.count());
|
||||
Metrics.gauge(`${prefix}.delayed_count`, await queue.getDelayedCount());
|
||||
}, 5 * 1000);
|
||||
|
||||
return queue;
|
||||
|
||||
Reference in New Issue
Block a user