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了,即說明第一步接入已經成功.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容