Skip to content

Commit

Permalink
update analytics error tracking to add metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkarimoff committed Jan 25, 2024
1 parent e3d1456 commit c5c7a86
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
7 changes: 3 additions & 4 deletions app/(dashboard)/dashboard/interviews/_actions/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ export const exportSessions = async (
const e = ensureError(error);
await trackEvent({
type: 'Error',
error: {
message: e.name,
details: e.message,
error: e,
metadata: {
details: 'Server-side Error',
path: '/(dashboard)/dashboard/interviews/_actions/export.ts',
stacktrace: e.stack ?? '',
},
});

Expand Down
12 changes: 5 additions & 7 deletions app/(interview)/onboard/[protocolId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ const handler = async (
if (!protocolId || protocolId === 'undefined') {
void trackEvent({
type: 'Error',
error: {
error: new Error('No protocol ID provided.'),
metadata: {
details: 'No protocol ID provided',
message: 'No protocol ID provided',
path: '/onboard/[protocolId]/route.ts',
stacktrace: '',
},
});

Expand Down Expand Up @@ -48,11 +47,10 @@ const handler = async (
if (error) {
void trackEvent({
type: 'Error',
error: {
details: error,
message: 'Failed to create interview',
error: new Error(error),
metadata: {
details: 'Failed to create interview',
path: '/onboard/[protocolId]/route.ts',
stacktrace: '',
},
});

Expand Down
5 changes: 2 additions & 3 deletions app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ const handler = (req: Request) =>

void trackEvent({
type: 'Error',
error: {
message: error.message,
error: new Error(error.message),
metadata: {
details: type,
path: path ?? 'unknown',
stacktrace: 'unknown',
},
});

Expand Down
5 changes: 2 additions & 3 deletions components/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ export default function Error({
try {
await trackEvent({
type: 'Error',
error: {
message: error.message,
error,
metadata: {
details: heading ?? '',
stacktrace: error.stack ?? '',
path: window.location.pathname,
},
});
Expand Down
7 changes: 3 additions & 4 deletions components/ProtocolImport/JobReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,10 @@ export function jobReducer(state: ImportJob[], action: Action) {

void trackEvent({
type: 'Error',
error: {
error: rawError,
metadata: {
details: 'Protocol import error',
message: rawError.message,
stacktrace: rawError.stack ?? '',
path: '',
path: 'components/ProtocolImport/JobReducer.ts',
},
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"seed": "tsx prisma/seed.ts"
},
"dependencies": {
"@codaco/analytics": "^2.1.1",
"@codaco/analytics": "link:..\\error-analytics-microservice\\packages\\analytics",
"@codaco/protocol-validation": "3.0.0-alpha.4",
"@codaco/shared-consts": "^0.0.2",
"@headlessui/react": "^1.7.17",
Expand Down
25 changes: 13 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions server/routers/interview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ export const interviewRouter = router({

void trackEvent({
type: 'Error',
error: {
message: e.name,
error: e,
metadata: {
details: e.message,
path: '/routers/interview.ts',
stacktrace: e.stack ?? '',
},
});

Expand Down

0 comments on commit c5c7a86

Please sign in to comment.