From e3c84f6146e3ae89219df5f8378a7aa278852a46 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Tue, 4 Jan 2022 09:09:45 +0100 Subject: [PATCH] Sampling API error report rate --- .github/workflows/build.yml | 2 +- src/api/general.ts | 10 +++++++--- src/api/instance.ts | 10 ++++++++++ src/api/tooot.ts | 10 +++++++--- src/utils/slices/instances/push/register.ts | 3 +-- src/utils/slices/instances/push/unregister.ts | 3 +-- src/utils/slices/instances/updatePushDecode.ts | 15 +++++++-------- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a76119ff..fd94bf46 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: - name: -- Step 3 -- Use Expo action uses: expo/expo-github-action@v6 with: - expo-version: 4.x + expo-version: 5.x username: ${{ secrets.EXPO_USERNAME }} token: ${{ secrets.EXPO_TOKEN }} - name: -- Step 4 -- Install node dependencies diff --git a/src/api/general.ts b/src/api/general.ts index 19ef755a..57298d47 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -24,7 +24,7 @@ const apiGeneral = async ({ params, headers, body, - sentry = false + sentry = true }: Params): Promise<{ body: T }> => { console.log( ctx.bgGreen.bold(' API general ') + @@ -58,8 +58,12 @@ const apiGeneral = async ({ }) }) .catch(error => { - if (sentry) { - Sentry.Native.setExtras(error.response || error.request) + if (sentry && Math.random() < 0.001) { + Sentry.Native.setExtras({ + API: 'instance', + ...(error.response && { response: error.response }), + ...(error.request && { request: error.request }) + }) Sentry.Native.captureException(error) } diff --git a/src/api/instance.ts b/src/api/instance.ts index 6805e160..81236aeb 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -3,6 +3,7 @@ import axios, { AxiosRequestConfig } from 'axios' import chalk from 'chalk' import Constants from 'expo-constants' import li from 'li' +import * as Sentry from 'sentry-expo' const ctx = new chalk.Instance({ level: 3 }) @@ -97,6 +98,15 @@ const apiInstance = async ({ }) }) .catch(error => { + if (Math.random() < 0.001) { + Sentry.Native.setExtras({ + API: 'instance', + ...(error.response && { response: error.response }), + ...(error.request && { request: error.request }) + }) + Sentry.Native.captureException(error) + } + if (error.response) { // The request was made and the server responded with a status code // that falls out of the range of 2xx diff --git a/src/api/tooot.ts b/src/api/tooot.ts index 713d2a6c..a199915f 100644 --- a/src/api/tooot.ts +++ b/src/api/tooot.ts @@ -29,7 +29,7 @@ const apiTooot = async ({ params, headers, body, - sentry = false + sentry = true }: Params): Promise<{ body: T }> => { console.log( ctx.bgGreen.bold(' API tooot ') + @@ -61,8 +61,12 @@ const apiTooot = async ({ }) }) .catch(error => { - if (sentry) { - Sentry.Native.setExtras(error.response || error.request) + if (sentry && Math.random() < 0.005) { + Sentry.Native.setExtras({ + API: 'tooot', + ...(error.response && { response: error.response }), + ...(error.request && { request: error.request }) + }) Sentry.Native.captureException(error) } diff --git a/src/utils/slices/instances/push/register.ts b/src/utils/slices/instances/push/register.ts index c34a5ba0..67e184fd 100644 --- a/src/utils/slices/instances/push/register.ts +++ b/src/utils/slices/instances/push/register.ts @@ -28,8 +28,7 @@ const subscribe = async ({ return apiTooot({ method: 'post', url: `/push/subscribe/${expoToken}/${instanceUrl}/${accountId}`, - body: { accountFull, serverKey, auth }, - sentry: true + body: { accountFull, serverKey, auth } }) } diff --git a/src/utils/slices/instances/push/unregister.ts b/src/utils/slices/instances/push/unregister.ts index 18d95e9a..30dc5ac1 100644 --- a/src/utils/slices/instances/push/unregister.ts +++ b/src/utils/slices/instances/push/unregister.ts @@ -21,8 +21,7 @@ const pushUnregister = async (state: RootState, expoToken: string) => { await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({ method: 'delete', - url: `/push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}`, - sentry: true + url: `/push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}` }) if (Platform.OS === 'android') { diff --git a/src/utils/slices/instances/updatePushDecode.ts b/src/utils/slices/instances/updatePushDecode.ts index 928a4157..d8f18804 100644 --- a/src/utils/slices/instances/updatePushDecode.ts +++ b/src/utils/slices/instances/updatePushDecode.ts @@ -21,20 +21,19 @@ export const updateInstancePushDecode = createAsyncThunk( } const expoToken = isDevelopment - ? 'DEVELOPMENT_TOKEN_1' - : ( - await Notifications.getExpoPushTokenAsync({ - experienceId: '@xmflsct/tooot' - }) - ).data + ? 'DEVELOPMENT_TOKEN_1' + : ( + await Notifications.getExpoPushTokenAsync({ + experienceId: '@xmflsct/tooot' + }) + ).data await apiTooot({ method: 'put', url: `/push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`, body: { auth: !disable ? null : instance.push.keys.auth - }, - sentry: true + } }) if (Platform.OS === 'android') {