📈 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
Updated errors lookup by relative timestamp
Blue Mouseade8ecbadaf7
diff --git a/backend/apps/cloud/src/task-manager/task-manager.service.ts b/backend/apps/cloud/src/task-manager/task-manager.service.tsindex b5b1d3ecb..3922b032f 100644--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts@@ -1053,22 +1053,19 @@ export class TaskManagerService {let query: stringconst queryParams: Record<string, any> = { pid: project.id }- let startTimestampForQuery: string+ const nowUnix = dayjs.utc().unix()+ let errorSubtractSeconds = 0+if (alert.lastTriggered) {- startTimestampForQuery = dayjs- .utc(alert.lastTriggered)- .format('YYYY-MM-DD HH:mm:ss')+ errorSubtractSeconds = nowUnix - dayjs.utc(alert.lastTriggered).unix()} else {- startTimestampForQuery = dayjs- .utc()- .subtract(CRON_INTERVAL_SECONDS, 'second')- .format('YYYY-MM-DD HH:mm:ss')+ errorSubtractSeconds =+ nowUnix - dayjs.utc().subtract(CRON_INTERVAL_SECONDS, 'second').unix()}- queryParams.startTimestampVal = startTimestampForQuery- const timeToUseForOtherMetrics =+ const subtractSecondsTimeframe =alert.queryMetric === QueryMetric.ERRORS- ? CRON_INTERVAL_SECONDS+ ? errorSubtractSeconds: getQueryTime(alert.queryTime as QueryTime)if (alert.queryMetric === QueryMetric.ERRORS) {@@ -1081,10 +1078,10 @@ export class TaskManagerService {WHERE pid = {pid:FixedString(12)}GROUP BY eid)- WHERE first_seen >= toDateTime({startTimestampVal:String})+ WHERE first_seen >= now() - ${subtractSecondsTimeframe}`} else {- query = `SELECT count() FROM errors WHERE pid = {pid:FixedString(12)} AND created >= toDateTime({startTimestampVal:String})`+ query = `SELECT count() FROM errors WHERE pid = {pid:FixedString(12)} AND created >= now() - ${subtractSecondsTimeframe}`}} else if (alert.queryMetric === QueryMetric.CUSTOM_EVENTS) {query = `@@ -1094,7 +1091,7 @@ export class TaskManagerService {WHEREpid = {pid:FixedString(12)}AND ev = {ev:String}- AND created >= now() - ${timeToUseForOtherMetrics}+ AND created >= now() - ${subtractSecondsTimeframe}`queryParams.ev = alert.queryCustomEvent} else {@@ -1105,7 +1102,7 @@ export class TaskManagerService {FROM analyticsWHEREpid = {pid:FixedString(12)}- AND created >= now() - ${timeToUseForOtherMetrics}+ AND created >= now() - ${subtractSecondsTimeframe}`}@@ -1143,23 +1140,22 @@ export class TaskManagerService {if (alert.queryMetric === QueryMetric.ERRORS && count > 0) {let detailQuery: stringconst detailQueryParams: Record<string, any> = {- pid_val: project.id,- startTimestampVal: queryParams.startTimestampVal,+ pid: project.id,}if (alert.alertOnNewErrorsOnly) {detailQuery = `SELECT eid, name, message, lineno, colno, filenameFROM errors- WHERE pid = {pid_val:FixedString(12)} AND eid IN (+ WHERE pid = {pid:FixedString(12)} AND eid IN (SELECT eidFROM (SELECT eid, min(created) AS first_seen_for_eidFROM errors- WHERE pid = {pid_val:FixedString(12)}+ WHERE pid = {pid:FixedString(12)}GROUP BY eid)- WHERE first_seen_for_eid >= toDateTime({startTimestampVal:String})+ WHERE first_seen_for_eid >= now() - ${subtractSecondsTimeframe})ORDER BY created DESCLIMIT 1@@ -1168,7 +1164,7 @@ export class TaskManagerService {detailQuery = `SELECT eid, name, message, lineno, colno, filenameFROM errors- WHERE pid = {pid_val:FixedString(12)} AND created >= toDateTime({startTimestampVal:String})+ WHERE pid = {pid:FixedString(12)} AND created >= now() - ${subtractSecondsTimeframe}ORDER BY created DESCLIMIT 1`