@exodus/sentry-客户端
API客户端用于对Sentry.io进行消毒并发送出错.
使用量
import createSentryClient from '@exodus/sentry-client'
import { safeString } from '@exodus/safe-string'
const client = createSentryClient({
fetchival,
config: {
// get this from your sentry project page at https://xxxxxx.sentry.io/settings/projects/node/keys/
// strip the project ID url path from the url they provide
dsnUrl: 'https://<publicKey>@<someId>.ingest.sentry.io',
publicKey: '<publicKey>',
projectId: '<projectId>',
environment: 'staging',
// optional
os: 'ios',
osVersion: '1.2.3',
platform: 'test',
appVersion: '3.2.1',
jsEngine: 'hermes', // or 'jsc'
},
})
// Note: all error messages must be safe for logging and should never expose sensitive data.
// Use the `safeString` tag to sanitize any dynamic values (e.g., PII, secrets etc.).
client.captureError({
// Will be sanitized to: "Failed to send recovery email: <redacted>"
error: new Error(safeString`Failed to send recovery email: ${email}`),
})
链接错误
错误 cause 链条(深度可达5级)自动被捕获并送往哨兵
作为连锁例外的链条,所以在抛出错误的同时保留了根源.
client.captureError({
error: new Error(safeString`Failed to sync wallet`, {
cause: new Error(safeString`Network request failed`),
}),
})