Skip to content

Commit

Permalink
Add manual error and breadcrumb tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed May 30, 2024
1 parent 27ab0b0 commit 4c5e3f9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
8 changes: 8 additions & 0 deletions jestSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ require('react-native-reanimated/src/reanimated2/jestUtils').setUpTests()

const mockReanimated = jest.requireMock('react-native-reanimated')

jest.mock('@sentry/react-native', () => {
return {
captureException: () => false,
addBreadcrumb: () => {},
wrap: x => x
}
})

jest.mock('@react-native-clipboard/clipboard', () => mockClipboard)

jest.mock('disklet', () => {
Expand Down
11 changes: 5 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,11 @@ const realFetch = fetch
fetch = async (...args: any) => {
// @ts-expect-error
return await realFetch(...args).catch(e => {
// TODO: leaveBreadcrumb('realFetchError', {
// url: args[0],
// errorName: e.name,
// errorMsg: e.message
// })
console.log(`realFetchError: ${args[0]} ${e.name} ${e.message}`)
Sentry.addBreadcrumb({
event_id: e.name,
message: e.message,
data: args[0]
})
throw e
})
}
Expand Down
15 changes: 8 additions & 7 deletions src/components/services/AirshipInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react'
import { ActivityIndicator } from 'react-native'
import { makeAirship } from 'react-native-airship'

import { trackError } from '../../util/tracking'
import { makeErrorLog, translateError } from '../../util/translateError'
import { AirshipToast } from '../common/AirshipToast'
import { AlertDropdown } from '../navigation/AlertDropdown'
Expand All @@ -17,17 +18,17 @@ export interface ShowErrorWarningOptions {
* Used when some user-requested operation fails.
*/
export function showError(error: unknown, options: ShowErrorWarningOptions = {}): void {
const { trackError = true, tag } = options
const { trackError: doTrackError = true, tag } = options
const tagMessage = tag == null ? '' : ` Tag: ${tag}.`
const translatedMessage = translateError(error) + tagMessage
if (trackError) {
if (doTrackError) {
if (error instanceof Error) {
// Log error with stack trace and a translated message to bug tracker
error.message = translatedMessage
// TODO: Add bug tracker notify method with 'error'
trackError(error)
} else {
// Any other types we just send the translated message to bug tracker
// TODO: Add bug tracker notify method with 'translatedMessage'
trackError(translatedMessage)
}
}
console.log(redText('Showing error drop-down alert: ' + makeErrorLog(error)))
Expand All @@ -41,10 +42,10 @@ export function showError(error: unknown, options: ShowErrorWarningOptions = {})
* Used when some user-requested operation succeeds but with a warning.
*/
export function showWarning(error: unknown, options: ShowErrorWarningOptions = {}): void {
const { trackError = true, tag } = options
const { trackError: doTrackError = true, tag } = options
const translatedError = tag ? `Tag: ${tag}. ` + translateError(error) : translateError(error)
if (trackError) {
// TODO: Add bug tracker notify method with `showWarning: ${translatedError}`
if (doTrackError) {
trackError(`showWarning: ${translatedError}`)
}
console.log(yellowText('Showing warning drop-down alert: ' + makeErrorLog(error)))
Airship.show(bridge => <AlertDropdown bridge={bridge} message={translatedError} warning />).catch(err => console.error(err))
Expand Down
10 changes: 8 additions & 2 deletions src/components/services/EdgeCoreManager.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { addBreadcrumb, captureException } from '@sentry/react-native'
import detectBundler from 'detect-bundler'
import { EdgeContext, EdgeContextOptions, EdgeCrashReporter, EdgeFakeWorld, EdgeNativeIo, MakeEdgeContext, MakeFakeEdgeWorld } from 'edge-core-js'
import { debugUri as accountbasedDebugUri, makePluginIo as makeAccountbasedIo, pluginUri as accountbasedUri } from 'edge-currency-accountbased'
Expand Down Expand Up @@ -57,10 +58,15 @@ const nativeIo: EdgeNativeIo = detectBundler.isReactNative

const crashReporter: EdgeCrashReporter = {
logBreadcrumb(event) {
// TODO: Add bug tracker `leaveBreadcrumb(event.message, event.metadata)`
addBreadcrumb({
type: event.source,
message: event.message,
data: event.metadata,
timestamp: event.time.getTime() / 1000
})
},
logCrash(event) {
// TODO: Add bug tracker `notify(event.error, report => report.addMetadata(event.source, event.metadata))`
captureException(event, { level: 'fatal' })
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/util/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import analytics from '@react-native-firebase/analytics'
import { captureException } from '@sentry/react-native'
import { TrackingEventName as LoginTrackingEventName, TrackingValues as LoginTrackingValues } from 'edge-login-ui-rn'
import PostHog from 'posthog-react-native'
import { getBuildNumber, getUniqueId, getVersion } from 'react-native-device-info'
Expand Down Expand Up @@ -157,11 +158,9 @@ export function trackError(
}

if (tag == null) {
// TODO: Add bug tracker notify method
console.log('Error:', err)
captureException(err)
} else {
// TODO: Add bug tracker notify method with metadata
console.log('Error:', err, 'Tag:', tag, 'Metadata:', String(metadata))
captureException(err, { event_id: tag, data: metadata })
}
}

Expand Down

0 comments on commit 4c5e3f9

Please sign in to comment.