Sampling API error report rate

This commit is contained in:
Zhiyuan Zheng 2022-01-04 09:09:45 +01:00
parent 65d54f73ec
commit e3c84f6146
7 changed files with 34 additions and 19 deletions

View File

@ -22,7 +22,7 @@ jobs:
- name: -- Step 3 -- Use Expo action - name: -- Step 3 -- Use Expo action
uses: expo/expo-github-action@v6 uses: expo/expo-github-action@v6
with: with:
expo-version: 4.x expo-version: 5.x
username: ${{ secrets.EXPO_USERNAME }} username: ${{ secrets.EXPO_USERNAME }}
token: ${{ secrets.EXPO_TOKEN }} token: ${{ secrets.EXPO_TOKEN }}
- name: -- Step 4 -- Install node dependencies - name: -- Step 4 -- Install node dependencies

View File

@ -24,7 +24,7 @@ const apiGeneral = async <T = unknown>({
params, params,
headers, headers,
body, body,
sentry = false sentry = true
}: Params): Promise<{ body: T }> => { }: Params): Promise<{ body: T }> => {
console.log( console.log(
ctx.bgGreen.bold(' API general ') + ctx.bgGreen.bold(' API general ') +
@ -58,8 +58,12 @@ const apiGeneral = async <T = unknown>({
}) })
}) })
.catch(error => { .catch(error => {
if (sentry) { if (sentry && Math.random() < 0.001) {
Sentry.Native.setExtras(error.response || error.request) Sentry.Native.setExtras({
API: 'instance',
...(error.response && { response: error.response }),
...(error.request && { request: error.request })
})
Sentry.Native.captureException(error) Sentry.Native.captureException(error)
} }

View File

@ -3,6 +3,7 @@ import axios, { AxiosRequestConfig } from 'axios'
import chalk from 'chalk' import chalk from 'chalk'
import Constants from 'expo-constants' import Constants from 'expo-constants'
import li from 'li' import li from 'li'
import * as Sentry from 'sentry-expo'
const ctx = new chalk.Instance({ level: 3 }) const ctx = new chalk.Instance({ level: 3 })
@ -97,6 +98,15 @@ const apiInstance = async <T = unknown>({
}) })
}) })
.catch(error => { .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) { if (error.response) {
// The request was made and the server responded with a status code // The request was made and the server responded with a status code
// that falls out of the range of 2xx // that falls out of the range of 2xx

View File

@ -29,7 +29,7 @@ const apiTooot = async <T = unknown>({
params, params,
headers, headers,
body, body,
sentry = false sentry = true
}: Params): Promise<{ body: T }> => { }: Params): Promise<{ body: T }> => {
console.log( console.log(
ctx.bgGreen.bold(' API tooot ') + ctx.bgGreen.bold(' API tooot ') +
@ -61,8 +61,12 @@ const apiTooot = async <T = unknown>({
}) })
}) })
.catch(error => { .catch(error => {
if (sentry) { if (sentry && Math.random() < 0.005) {
Sentry.Native.setExtras(error.response || error.request) Sentry.Native.setExtras({
API: 'tooot',
...(error.response && { response: error.response }),
...(error.request && { request: error.request })
})
Sentry.Native.captureException(error) Sentry.Native.captureException(error)
} }

View File

@ -28,8 +28,7 @@ const subscribe = async ({
return apiTooot({ return apiTooot({
method: 'post', method: 'post',
url: `/push/subscribe/${expoToken}/${instanceUrl}/${accountId}`, url: `/push/subscribe/${expoToken}/${instanceUrl}/${accountId}`,
body: { accountFull, serverKey, auth }, body: { accountFull, serverKey, auth }
sentry: true
}) })
} }

View File

@ -21,8 +21,7 @@ const pushUnregister = async (state: RootState, expoToken: string) => {
await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({ await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({
method: 'delete', method: 'delete',
url: `/push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}`, url: `/push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}`
sentry: true
}) })
if (Platform.OS === 'android') { if (Platform.OS === 'android') {

View File

@ -21,20 +21,19 @@ export const updateInstancePushDecode = createAsyncThunk(
} }
const expoToken = isDevelopment const expoToken = isDevelopment
? 'DEVELOPMENT_TOKEN_1' ? 'DEVELOPMENT_TOKEN_1'
: ( : (
await Notifications.getExpoPushTokenAsync({ await Notifications.getExpoPushTokenAsync({
experienceId: '@xmflsct/tooot' experienceId: '@xmflsct/tooot'
}) })
).data ).data
await apiTooot({ await apiTooot({
method: 'put', method: 'put',
url: `/push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`, url: `/push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`,
body: { body: {
auth: !disable ? null : instance.push.keys.auth auth: !disable ? null : instance.push.keys.auth
}, }
sentry: true
}) })
if (Platform.OS === 'android') { if (Platform.OS === 'android') {