Skip to content

Commit

Permalink
Add Sentry error logging to Audius query C-2800 (#3656)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikki Kang <kangaroo233@gmail.com>
  • Loading branch information
nicoback2 and nicoback authored Jun 27, 2023
1 parent 79213de commit 6a2f008
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/common/src/audius-query/AudiusQueryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { AudiusSdk } from '@audius/sdk'
import type { AudiusAPIClient } from 'services/audius-api-client'
import { AudiusBackend } from 'services/index'

import { ReportToSentryArgs } from '../models'

export type AudiusQueryContextType = {
apiClient: AudiusAPIClient
audiusSdk: () => Promise<AudiusSdk>
audiusBackend: AudiusBackend
reportToSentry: (args: ReportToSentryArgs) => void
}

export const AudiusQueryContext = createContext<AudiusQueryContextType | null>(
Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/audius-query/createApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useDispatch, useSelector } from 'react-redux'
import { Dispatch } from 'redux'

import { useProxySelector } from 'hooks/useProxySelector'
import { ErrorLevel } from 'models/ErrorReporting'
import { Kind } from 'models/Kind'
import { Status } from 'models/Status'
import { getCollection } from 'store/cache/collections/selectors'
Expand Down Expand Up @@ -39,6 +40,7 @@ import {
QueryHookResults
} from './types'
import { capitalize, getKeyFromFetchArgs, selectCommonEntityMap } from './utils'

const { addEntries } = cacheActions

export const createApi = <
Expand Down Expand Up @@ -296,6 +298,14 @@ const fetchData = async <Args, Data>(

endpoint.onQuerySuccess?.(data, fetchArgs, { dispatch })
} catch (e) {
context.reportToSentry({
error: e as Error,
level: ErrorLevel.Error,
additionalInfo: { fetchArgs, endpoint },
name: `${
endpoint.options?.type === 'mutation' ? 'Mutate' : 'Query'
} ${capitalize(endpointName)} error`
})
dispatch(
// @ts-ignore
actions[`fetch${capitalize(endpointName)}Error`]({
Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
forceRefreshConnectivity,
subscribeToNetworkStatusUpdates
} from 'app/utils/reachability'
import { reportToSentry } from 'app/utils/reportToSentry'

import { Drawers } from './Drawers'
import ErrorBoundary from './ErrorBoundary'
Expand Down Expand Up @@ -87,7 +88,8 @@ const App = () => {
value={{
apiClient,
audiusSdk,
audiusBackend: audiusBackendInstance
audiusBackend: audiusBackendInstance,
reportToSentry
}}
>
<PersistGate loading={null} persistor={persistor}>
Expand Down
8 changes: 7 additions & 1 deletion packages/web/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { audiusSdk } from 'services/audius-sdk/audiusSdk'
import history from 'utils/history'

import { store } from './store/configureStore'
import { reportToSentry } from './store/errors/reportToSentry'

import './services/webVitals'
import './index.css'
Expand All @@ -27,7 +28,12 @@ const AudiusApp = () => {
return (
<Provider store={store}>
<AudiusQueryContext.Provider
value={{ apiClient, audiusBackend: audiusBackendInstance, audiusSdk }}
value={{
apiClient,
audiusBackend: audiusBackendInstance,
audiusSdk,
reportToSentry
}}
>
<ConnectedRouter history={history}>
<LastLocationProvider>
Expand Down

0 comments on commit 6a2f008

Please sign in to comment.