📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: error alerts are sent every X minutes (ignoring lastTriggered date)
Blue Mouseaa4582869354
diff --git a/backend/apps/cloud/src/alert/entity/alert.entity.ts b/backend/apps/cloud/src/alert/entity/alert.entity.tsindex a2724ea4e..a5c0bda08 100644--- a/backend/apps/cloud/src/alert/entity/alert.entity.ts+++ b/backend/apps/cloud/src/alert/entity/alert.entity.ts@@ -35,7 +35,7 @@ export class Alert {@ApiProperty()@Column({- type: 'date',+ type: 'datetime',nullable: true,default: null,})diff --git a/backend/apps/cloud/src/task-manager/task-manager.service.ts b/backend/apps/cloud/src/task-manager/task-manager.service.tsindex cfe735afd..04753608b 100644--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts@@ -1011,10 +1011,9 @@ export class TaskManagerService {})}- // @Cron(CronExpression.EVERY_5_MINUTES)- @Cron(CronExpression.EVERY_MINUTE)+ @Cron(CronExpression.EVERY_5_MINUTES)async checkMetricAlerts() {- const CRON_INTERVAL_SECONDS = 60+ const CRON_INTERVAL_SECONDS = 300const projects = await this.projectService.find({where: {@@ -1071,7 +1070,8 @@ export class TaskManagerService {if (alert.queryMetric === QueryMetric.ERRORS) {if (alert.alertOnNewErrorsOnly) {query = `- SELECT count()+ SELECT+ count()FROM (SELECT eid, min(created) as first_seenFROM errors@@ -1081,7 +1081,14 @@ export class TaskManagerService {WHERE first_seen >= now() - ${subtractSecondsTimeframe}`} else {- query = `SELECT count() FROM errors WHERE pid = {pid:FixedString(12)} AND created >= now() - ${subtractSecondsTimeframe}`+ query = `+ SELECT+ count()+ FROM errors+ WHERE+ pid = {pid:FixedString(12)}+ AND created >= now() - ${subtractSecondsTimeframe}+ `}} else if (alert.queryMetric === QueryMetric.CUSTOM_EVENTS) {query = `@@ -1164,7 +1171,9 @@ export class TaskManagerService {detailQuery = `SELECT eid, name, message, lineno, colno, filenameFROM errors- WHERE pid = {pid:FixedString(12)} AND created >= now() - ${subtractSecondsTimeframe}+ WHERE+ pid = {pid:FixedString(12)}+ AND created >= now() - ${subtractSecondsTimeframe}ORDER BY created DESCLIMIT 1`@@ -1183,8 +1192,6 @@ export class TaskManagerService {}}- console.log('errorDetails', errorDetails)-// @ts-expect-errorawait this.alertService.update(alert.id, {lastTriggered: new Date(),@@ -1429,7 +1436,6 @@ export class TaskManagerService {const messages = await this.telegramService.getMessages()messages.forEach(async message => {- console.log('message', message)try {await this.telegramService.sendMessage(message.id,diff --git a/backend/migrations/mysql/2025_05_10.sql b/backend/migrations/mysql/2025_05_10.sqlnew file mode 100644index 000000000..babee1504--- /dev/null+++ b/backend/migrations/mysql/2025_05_10.sql@@ -0,0 +1,15 @@+ALTER TABLE alert ADD COLUMN `alert_on_new_errors_only` tinyint NOT NULL DEFAULT '1';++-- Change lastTriggered from DATE to DATETIME, preserving the date and setting time to 00:00:00+-- Step 1: Add a new temporary DATETIME column+ALTER TABLE alert ADD COLUMN `lastTriggered_temp_dt` DATETIME DEFAULT NULL;++-- Step 2: Populate the temporary column, converting existing DATE values to DATETIME+-- This will set the time part to 00:00:00 for non-NULL dates+UPDATE alert SET `lastTriggered_temp_dt` = CAST(`lastTriggered` AS DATETIME) WHERE `lastTriggered` IS NOT NULL;++-- Step 3: Remove the old lastTriggered column (which was DATE type)+ALTER TABLE alert DROP COLUMN `lastTriggered`;++-- Step 4: Rename the temporary column to the final name 'lastTriggered'+ALTER TABLE alert CHANGE COLUMN `lastTriggered_temp_dt` `lastTriggered` DATETIME DEFAULT NULL;