Skip to content

Commit 59ed50f

Browse files
committed
fix: error tracking
1 parent b6f9b80 commit 59ed50f

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

apps/api/src/query/builders/errors.ts

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,76 @@ export const ErrorsBuilders: Record<string, SimpleQueryConfig> = {
100100
},
101101

102102
error_summary: {
103-
table: Analytics.errors,
104-
fields: [
105-
'COUNT(*) as totalErrors',
106-
'uniq(message) as uniqueErrorTypes',
107-
'uniq(anonymous_id) as affectedUsers',
108-
'uniq(session_id) as affectedSessions',
109-
'0 as errorRate',
110-
],
111-
where: ["message != ''"],
103+
meta: {
104+
title: 'Error Summary',
105+
description: 'Overview of errors with calculated error rate',
106+
version: '1.0',
107+
},
108+
customSql: (
109+
websiteId: string,
110+
startDate: string,
111+
endDate: string,
112+
_filters?: unknown[],
113+
_granularity?: unknown,
114+
_limit?: number,
115+
_offset?: number,
116+
_timezone?: string,
117+
filterConditions?: string[],
118+
filterParams?: Record<string, unknown>
119+
) => {
120+
const combinedWhereClause = filterConditions?.length
121+
? `AND ${filterConditions.join(' AND ')}`
122+
: '';
123+
124+
return {
125+
sql: `
126+
WITH total_sessions AS (
127+
SELECT uniq(session_id) as total
128+
FROM analytics.events
129+
WHERE client_id = {websiteId:String}
130+
AND time >= parseDateTimeBestEffort({startDate:String})
131+
AND time <= parseDateTimeBestEffort(concat({endDate:String}, ' 23:59:59'))
132+
),
133+
error_sessions AS (
134+
SELECT uniq(session_id) as error_count
135+
FROM analytics.errors
136+
WHERE client_id = {websiteId:String}
137+
AND timestamp >= parseDateTimeBestEffort({startDate:String})
138+
AND timestamp <= parseDateTimeBestEffort(concat({endDate:String}, ' 23:59:59'))
139+
AND message != ''
140+
${combinedWhereClause}
141+
),
142+
error_stats AS (
143+
SELECT
144+
COUNT(*) as totalErrors,
145+
uniq(message) as uniqueErrorTypes,
146+
uniq(anonymous_id) as affectedUsers,
147+
uniq(session_id) as affectedSessions
148+
FROM analytics.errors
149+
WHERE client_id = {websiteId:String}
150+
AND timestamp >= parseDateTimeBestEffort({startDate:String})
151+
AND timestamp <= parseDateTimeBestEffort(concat({endDate:String}, ' 23:59:59'))
152+
AND message != ''
153+
${combinedWhereClause}
154+
)
155+
SELECT
156+
es.totalErrors,
157+
es.uniqueErrorTypes,
158+
es.affectedUsers,
159+
es.affectedSessions,
160+
ROUND((err.error_count / ts.total) * 100, 2) as errorRate
161+
FROM error_stats es
162+
CROSS JOIN total_sessions ts
163+
CROSS JOIN error_sessions err
164+
`,
165+
params: {
166+
websiteId,
167+
startDate,
168+
endDate,
169+
...filterParams,
170+
},
171+
};
172+
},
112173
timeField: 'timestamp',
113174
allowedFilters: ['message', 'path', 'browser_name', 'country'],
114175
customizable: true,

apps/basket/src/utils/event-schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export {
22
analyticsEventSchema,
33
customEventSchema,
44
errorEventSchema,
5-
observabilityEventSchema,
65
outgoingLinkSchema,
76
webVitalsEventSchema,
87
} from '@databuddy/validation';

apps/dashboard/public/databuddy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@
857857
return;
858858
}
859859

860-
if (this.isBot()) {
860+
if (this.isLikelyBot) {
861861
return;
862862
}
863863

packages/validation/src/schemas/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './batch';
33
export * from './custom-events';
44
export * from './email';
55
export * from './errors';
6-
export * from './observability';
76
export * from './organizations';
87
export * from './web-vitals';
98
export * from './websites';

0 commit comments

Comments
 (0)