React Native集成Sentry之附加配置

这些是您可以在javascript代码中调用的函数:

import {
  Sentry,
  SentrySeverity,
  SentryLog
} from 'react-native-sentry';

// disable stacktrace merging
Sentry.config("https://<key>:<secret>@sentry.io/<project>", {
  deactivateStacktraceMerging: false, // default: true | Deactivates the stacktrace merging feature
  logLevel: SentryLog.Debug, // default SentryLog.None | Possible values:  .None, .Error, .Debug, .Verbose
  disableNativeIntegration: false, // default: false | Deactivates the native integration and only uses raven-js
  handlePromiseRejection: true // default: true | Handle unhandled promise rejections
  // sampleRate: 0.5 // default: 1.0 | Only set this if you don't want to send every event so e.g.: 0.5 will send 50% of all events
  // These two options will only be considered if stacktrace merging is active
  // Here you can add modules that should be ignored or exclude modules
  // that should no longer be ignored from stacktrace merging
  // ignoreModulesExclude: ["I18nManager"], // default: [] | Exclude is always stronger than include
  // ignoreModulesInclude: ["RNSentry"], // default: [] | Include modules that should be ignored too
  // ---------------------------------
}).install();

// set a callback after an event was successfully sentry
// its only guaranteed that this event contains `event_id` & `level`
Sentry.setEventSentSuccessfully((event) => {
  // can also be called outside this block but maybe null
  // Sentry.lastEventId(); -> returns the last event_id after the first successfully sent event
  // Sentry.lastException(); -> returns the last event after the first successfully sent event
});

Sentry.setShouldSendCallback((event) => {
  return true; // if return false, event will not be sent
});

// Sentry.lastException(); // Will return the last sent error event
// Sentry.lastEventId(); // Will return the last event id

// export an extra context
Sentry.setExtraContext({
  "a_thing": 3,
  "some_things": {"green": "red"},
  "foobar": ["a", "b", "c"],
  "react": true,
  "float": 2.43
});

// set the tag context
Sentry.setTagsContext({
  "environment": "production",
  "react": true
});

// set the user context
Sentry.setUserContext({
  email: "john@apple.com",
  userID: "12341",
  username: "username",
  extra: {
    "is_admin": false
  }
});

// set a custom message
Sentry.captureMessage("TEST message", {
  level: SentrySeverity.Warning
}); // Default SentrySeverity.Error

// capture an exception
Sentry.captureException(new Error('Oops!'), {
  logger: 'my.module'
});

// capture a breadcrumb
Sentry.captureBreadcrumb({
  message: 'Item added to shopping cart',
  category: 'action',
  data: {
     isbn: '978-1617290541',
     cartSize: '3'
  }
});

// This will trigger a crash in the native sentry client
//Sentry.nativeCrash();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值