Android Sentry 系列技术贴,第一个模块入门接入

安装

Sentry 通过在您的应用程序运行时中使用 SDK 来捕获数据。

dependencies {

implementation'io.sentry:sentry-android:6.17.0'

}

配置

配置是通过应用程序完成的AndroidManifest.xml这是一个示例配置,可以帮助您入门:

<application>

<!-- 设置手动初始化-->

    android:name="io.sentry.auto-init"

    android:value="false" />

<!-- enable automatic breadcrumbs for user interactions (clicks, swipes, scrolls) 为用户交互(点击、滑动、滚动)启用自动面包屑 -->

    android:name="io.sentry.traces.user-interaction.enable"

    android:value="true" />

<!-- enable screenshot for crashes  附件屏幕开关-->

    android:name="io.sentry.attach-screenshot"

    android:value="true" />

<!-- enable view hierarchy for crashes  为崩溃启用视图层次结构-->

    android:name="io.sentry.attach-view-hierarchy"

    android:value="true" />

<!-- enable the performance API by setting a sample-rate, adjust in production env  通过设置采样率启用性能API,在生产环境中进行调整-->

    android:name="io.sentry.traces.sample-rate"

    android:value="1.0" />

<!-- enable profiling when starting transactions, adjust in production env 启动事务时启用分析,在生产环境中进行调整-->

    android:name="io.sentry.traces.profiling.sample-rate"

    android:value="1.0" />

</application>



验证

此代码段包含一个故意错误,因此您可以在设置后立即测试一切是否正常:

import io.sentry.SentryLevel;

import io.sentry.android.core.SentryAndroid;

import android.app.Application;

public class MyApplication extends Application {

  public void onCreate() {

    super.onCreate();

    SentryAndroid.init(this, options -> {

      options.setDsn("填入你自己项目在sentry的dsn,在我的 - 项目中找");

      // Add a callback that will be used before the event is sent to Sentry.

      // With this callback, you can modify the event or, when returning null, also discard the event.

      options.setBeforeSend((event, hint) -> {

        if (SentryLevel.DEBUG.equals(event.getLevel()))

          return null;

        else

          return event;

      });

    });

  }

}


如果看错误上报到Sentry了,即说明第一步接入已经成功.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容