From c5c7a860c29cb41b6a403226c5b0bd756f9909cf Mon Sep 17 00:00:00 2001 From: mrkarimoff Date: Thu, 25 Jan 2024 14:27:07 +0500 Subject: [PATCH 1/3] update analytics error tracking to add metadata --- .../dashboard/interviews/_actions/export.ts | 7 +++--- app/(interview)/onboard/[protocolId]/route.ts | 12 ++++----- app/api/trpc/[trpc]/route.ts | 5 ++-- components/Error.tsx | 5 ++-- components/ProtocolImport/JobReducer.ts | 7 +++--- package.json | 2 +- pnpm-lock.yaml | 25 ++++++++++--------- server/routers/interview.ts | 5 ++-- 8 files changed, 31 insertions(+), 37 deletions(-) diff --git a/app/(dashboard)/dashboard/interviews/_actions/export.ts b/app/(dashboard)/dashboard/interviews/_actions/export.ts index e5e9ec0e..986f8f83 100644 --- a/app/(dashboard)/dashboard/interviews/_actions/export.ts +++ b/app/(dashboard)/dashboard/interviews/_actions/export.ts @@ -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 ?? '', }, }); diff --git a/app/(interview)/onboard/[protocolId]/route.ts b/app/(interview)/onboard/[protocolId]/route.ts index f58a6f3d..6f17899c 100644 --- a/app/(interview)/onboard/[protocolId]/route.ts +++ b/app/(interview)/onboard/[protocolId]/route.ts @@ -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: '', }, }); @@ -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: '', }, }); diff --git a/app/api/trpc/[trpc]/route.ts b/app/api/trpc/[trpc]/route.ts index 64a80892..8c490c54 100644 --- a/app/api/trpc/[trpc]/route.ts +++ b/app/api/trpc/[trpc]/route.ts @@ -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', }, }); diff --git a/components/Error.tsx b/components/Error.tsx index ad4e9b49..7fadbfd6 100644 --- a/components/Error.tsx +++ b/components/Error.tsx @@ -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, }, }); diff --git a/components/ProtocolImport/JobReducer.ts b/components/ProtocolImport/JobReducer.ts index e763793e..e1eeeb88 100644 --- a/components/ProtocolImport/JobReducer.ts +++ b/components/ProtocolImport/JobReducer.ts @@ -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', }, }); diff --git a/package.json b/package.json index f84ccd59..b1c19dd5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f01b1050..ad709f92 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@codaco/analytics': - specifier: ^2.1.1 - version: 2.1.1(@maxmind/geoip2-node@5.0.0)(next@14.1.0) + specifier: link:..\error-analytics-microservice\packages\analytics + version: link:../error-analytics-microservice/packages/analytics '@codaco/protocol-validation': specifier: 3.0.0-alpha.4 version: 3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0) @@ -1806,16 +1806,6 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true - /@codaco/analytics@2.1.1(@maxmind/geoip2-node@5.0.0)(next@14.1.0): - resolution: {integrity: sha512-x7gQt+IL2BiEALNX+28HUIhl4z0eQ60zjJQD++pnCrTixYSK2+TXLjTr9QcLG9K4WSBA7UgDkHVLXnPoC3nZOA==} - peerDependencies: - '@maxmind/geoip2-node': ^5.0.0 - next: 13 || 14 - dependencies: - '@maxmind/geoip2-node': 5.0.0 - next: 14.1.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)(sass@1.69.4) - dev: false - /@codaco/protocol-validation@3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0): resolution: {integrity: sha512-2vV5Tga/zco/vrdDwkmirkiEqvwq+pduV4U4bHJhIgivxFSxswy6Ae7VLsbgOsFRaypx/SMrh7kF9wmU30liLQ==} dependencies: @@ -2482,6 +2472,7 @@ packages: dependencies: ip6addr: 0.2.5 maxmind: 4.3.18 + dev: true /@mdx-js/react@2.3.0(react@18.2.0): resolution: {integrity: sha512-zQH//gdOmuu7nt2oJR29vFhDv88oGPmVw6BggmrHeMI+xgEkp1B2dX9/bMBSYtK0dyLX/aOmesKS09g222K1/g==} @@ -6324,6 +6315,7 @@ packages: /assert-plus@1.0.0: resolution: {integrity: sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==} engines: {node: '>=0.8'} + dev: true /assert@2.1.0: resolution: {integrity: sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==} @@ -7252,6 +7244,7 @@ packages: /core-util-is@1.0.2: resolution: {integrity: sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==} + dev: true /core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -8606,6 +8599,7 @@ packages: /extsprintf@1.3.0: resolution: {integrity: sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==} engines: {'0': node >=0.6.0} + dev: true /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -9608,6 +9602,7 @@ packages: dependencies: assert-plus: 1.0.0 jsprim: 2.0.2 + dev: true /ip@2.0.0: resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==} @@ -10536,6 +10531,7 @@ packages: /json-schema@0.4.0: resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==} + dev: true /json-stable-stringify-without-jsonify@1.0.1: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} @@ -10568,6 +10564,7 @@ packages: extsprintf: 1.3.0 json-schema: 0.4.0 verror: 1.10.0 + dev: true /jssha@3.3.1: resolution: {integrity: sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==} @@ -10841,6 +10838,7 @@ packages: dependencies: mmdb-lib: 2.1.0 tiny-lru: 11.2.5 + dev: true /md5.js@1.3.5: resolution: {integrity: sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==} @@ -11320,6 +11318,7 @@ packages: /mmdb-lib@2.1.0: resolution: {integrity: sha512-tdDTZmnI5G4UoSctv2KxM/3VQt2XRj4CmR5R4VsAWsOUcS3LysHR34wtixWm/pXxXdkBDuN92auxkC0T2+qd1Q==} engines: {node: '>=10', npm: '>=6'} + dev: true /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -14059,6 +14058,7 @@ packages: /tiny-lru@11.2.5: resolution: {integrity: sha512-JpqM0K33lG6iQGKiigcwuURAKZlq6rHXfrgeL4/I8/REoyJTGU+tEMszvT/oTRVHG2OiylhGDjqPp1jWMlr3bw==} engines: {node: '>=12'} + dev: true /tinyqueue@2.0.3: resolution: {integrity: sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==} @@ -14631,6 +14631,7 @@ packages: assert-plus: 1.0.0 core-util-is: 1.0.2 extsprintf: 1.3.0 + dev: true /vfile-location@5.0.2: resolution: {integrity: sha512-NXPYyxyBSH7zB5U6+3uDdd6Nybz6o6/od9rk8bp9H8GR3L+cm/fC0uUTbqBmUTnMCUDslAGBOIKNfvvb+gGlDg==} diff --git a/server/routers/interview.ts b/server/routers/interview.ts index 0f31763c..7e3c651b 100644 --- a/server/routers/interview.ts +++ b/server/routers/interview.ts @@ -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 ?? '', }, }); From 2ddcdede527525b4175fc8702558ce957d0c54df Mon Sep 17 00:00:00 2001 From: mrkarimoff Date: Thu, 25 Jan 2024 16:09:13 +0500 Subject: [PATCH 2/3] install latest version of @codaco/analytics --- package.json | 2 +- pnpm-lock.yaml | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index b1c19dd5..ccf4edf9 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "seed": "tsx prisma/seed.ts" }, "dependencies": { - "@codaco/analytics": "link:..\\error-analytics-microservice\\packages\\analytics", + "@codaco/analytics": "^3.0.0", "@codaco/protocol-validation": "3.0.0-alpha.4", "@codaco/shared-consts": "^0.0.2", "@headlessui/react": "^1.7.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad709f92..5132aefc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@codaco/analytics': - specifier: link:..\error-analytics-microservice\packages\analytics - version: link:../error-analytics-microservice/packages/analytics + specifier: ^3.0.0 + version: 3.0.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0) '@codaco/protocol-validation': specifier: 3.0.0-alpha.4 version: 3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0) @@ -1806,6 +1806,16 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@codaco/analytics@3.0.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0): + resolution: {integrity: sha512-KfXvABSwGz/0d7GbOwoHUXMrsJB9OxQXJwN96Uc2N8DNc25NcFZ5fOpfW+M2C5lN3CJ150YTNXKGlDm/b7Y6UQ==} + peerDependencies: + '@maxmind/geoip2-node': ^5.0.0 + next: 13 || 14 + dependencies: + '@maxmind/geoip2-node': 5.0.0 + next: 14.1.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)(sass@1.69.4) + dev: false + /@codaco/protocol-validation@3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0): resolution: {integrity: sha512-2vV5Tga/zco/vrdDwkmirkiEqvwq+pduV4U4bHJhIgivxFSxswy6Ae7VLsbgOsFRaypx/SMrh7kF9wmU30liLQ==} dependencies: @@ -2472,7 +2482,6 @@ packages: dependencies: ip6addr: 0.2.5 maxmind: 4.3.18 - dev: true /@mdx-js/react@2.3.0(react@18.2.0): resolution: {integrity: sha512-zQH//gdOmuu7nt2oJR29vFhDv88oGPmVw6BggmrHeMI+xgEkp1B2dX9/bMBSYtK0dyLX/aOmesKS09g222K1/g==} @@ -6315,7 +6324,6 @@ packages: /assert-plus@1.0.0: resolution: {integrity: sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==} engines: {node: '>=0.8'} - dev: true /assert@2.1.0: resolution: {integrity: sha512-eLHpSK/Y4nhMJ07gDaAzoX/XAKS8PSaojml3M0DM4JpV1LAi5JOJ/p6H/XWrl8L+DzVEvVCW1z3vWAaB9oTsQw==} @@ -7244,7 +7252,6 @@ packages: /core-util-is@1.0.2: resolution: {integrity: sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==} - dev: true /core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -8599,7 +8606,6 @@ packages: /extsprintf@1.3.0: resolution: {integrity: sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==} engines: {'0': node >=0.6.0} - dev: true /fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} @@ -9602,7 +9608,6 @@ packages: dependencies: assert-plus: 1.0.0 jsprim: 2.0.2 - dev: true /ip@2.0.0: resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==} @@ -10531,7 +10536,6 @@ packages: /json-schema@0.4.0: resolution: {integrity: sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==} - dev: true /json-stable-stringify-without-jsonify@1.0.1: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} @@ -10564,7 +10568,6 @@ packages: extsprintf: 1.3.0 json-schema: 0.4.0 verror: 1.10.0 - dev: true /jssha@3.3.1: resolution: {integrity: sha512-VCMZj12FCFMQYcFLPRm/0lOBbLi8uM2BhXPTqw3U4YAfs4AZfiApOoBLoN8cQE60Z50m1MYMTQVCfgF/KaCVhQ==} @@ -10838,7 +10841,6 @@ packages: dependencies: mmdb-lib: 2.1.0 tiny-lru: 11.2.5 - dev: true /md5.js@1.3.5: resolution: {integrity: sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==} @@ -11318,7 +11320,6 @@ packages: /mmdb-lib@2.1.0: resolution: {integrity: sha512-tdDTZmnI5G4UoSctv2KxM/3VQt2XRj4CmR5R4VsAWsOUcS3LysHR34wtixWm/pXxXdkBDuN92auxkC0T2+qd1Q==} engines: {node: '>=10', npm: '>=6'} - dev: true /mri@1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -14058,7 +14059,6 @@ packages: /tiny-lru@11.2.5: resolution: {integrity: sha512-JpqM0K33lG6iQGKiigcwuURAKZlq6rHXfrgeL4/I8/REoyJTGU+tEMszvT/oTRVHG2OiylhGDjqPp1jWMlr3bw==} engines: {node: '>=12'} - dev: true /tinyqueue@2.0.3: resolution: {integrity: sha512-ppJZNDuKGgxzkHihX8v9v9G5f+18gzaTfrukGrq6ueg0lmH4nqVnA2IPG0AEH3jKEk2GRJCUhDoqpoiw3PHLBA==} @@ -14631,7 +14631,6 @@ packages: assert-plus: 1.0.0 core-util-is: 1.0.2 extsprintf: 1.3.0 - dev: true /vfile-location@5.0.2: resolution: {integrity: sha512-NXPYyxyBSH7zB5U6+3uDdd6Nybz6o6/od9rk8bp9H8GR3L+cm/fC0uUTbqBmUTnMCUDslAGBOIKNfvvb+gGlDg==} From 0e9686d823e93be881905e99a766e4d66861bcdc Mon Sep 17 00:00:00 2001 From: mrkarimoff Date: Wed, 31 Jan 2024 18:10:47 +0500 Subject: [PATCH 3/3] Update @codaco/analytics to version 3.1.0 --- package.json | 2 +- pnpm-lock.yaml | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index ccf4edf9..0e185473 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "seed": "tsx prisma/seed.ts" }, "dependencies": { - "@codaco/analytics": "^3.0.0", + "@codaco/analytics": "^3.1.0", "@codaco/protocol-validation": "3.0.0-alpha.4", "@codaco/shared-consts": "^0.0.2", "@headlessui/react": "^1.7.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5132aefc..b301ee4b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@codaco/analytics': - specifier: ^3.0.0 - version: 3.0.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0) + specifier: ^3.1.0 + version: 3.1.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0) '@codaco/protocol-validation': specifier: 3.0.0-alpha.4 version: 3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0) @@ -1806,14 +1806,15 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true - /@codaco/analytics@3.0.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0): - resolution: {integrity: sha512-KfXvABSwGz/0d7GbOwoHUXMrsJB9OxQXJwN96Uc2N8DNc25NcFZ5fOpfW+M2C5lN3CJ150YTNXKGlDm/b7Y6UQ==} + /@codaco/analytics@3.1.0(@maxmind/geoip2-node@5.0.0)(next@14.1.0): + resolution: {integrity: sha512-wDGm7nMrDHlJ8inY66+lkK/fzc1kC/LL/drI5d8BXyc9sF7+FzB2iL8w093hNL5sKTOubJWWccKwIaX95EUJYQ==} peerDependencies: '@maxmind/geoip2-node': ^5.0.0 next: 13 || 14 dependencies: '@maxmind/geoip2-node': 5.0.0 next: 14.1.0(@babel/core@7.23.2)(react-dom@18.2.0)(react@18.2.0)(sass@1.69.4) + zod: 3.22.4 dev: false /@codaco/protocol-validation@3.0.0-alpha.4(@types/eslint@8.44.6)(eslint-config-prettier@9.0.0)(eslint@8.52.0):