我将在我的android项目中使用sentry。
我的公司正在使用一个自我托管的哨兵,版本9.0.0
我跟踪了Sentry.io Installation Guide
这些权限已添加到清单中:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

这是我的app/build.gradle文件:
dependencies {
    ...
    implementation 'io.sentry:sentry-android:1.7.10'
    implementation 'org.slf4j:slf4j-nop:1.7.25'
}

apply plugin: 'io.sentry.android.gradle'

sentry {
    autoProguardConfig true
    autoUpload true
}

这是我的顶级项目build.gradle:
dependencies {
    ...
    classpath 'io.sentry:sentry-android-gradle-plugin:1.7.10'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

这是主要活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Context ctx = this.getApplicationContext();
    String sentryDsn = "https://MyPublicKey:MySecretKey...";
    Sentry.init(sentryDsn, new AndroidSentryClientFactory(ctx));

    setContentView(R.layout.activity_main);

    Sentry.capture("This Is My First Log!");
    ...
}

但没有任何东西送到岗哨小组。怎么了?
有什么想法吗?

最佳答案

这不是我需要的答案,但说出来也不错
最后我找到了一个使用这个类将日志发送到岗哨面板的解决方案:Sentry.class
不过,它需要一些改变才能发挥作用,但现在它发挥了魅力。
唯一让我担心的是,当我在岗哨面板中打开事件时,此警告将显示在页面底部:
用JAVA SDK的旧版本报告了这个事件。
要使用Sentry.class初始化和捕获日志,请将其代码复制到您在项目中创建的新类中,并找到以下代码:

header.append("Sentry ")
        .append(String.format("sentry_version=%s,", sentryVersion))
        .append(String.format("sentry_client=sentry-android/%s,", BuildConfig.SENTRY_ANDROID_VERSION))
        .append(String.format("sentry_key=%s,", publicKey))
        .append(String.format("sentry_secret=%s", secretKey));

并用包含sentry库版本的字符串替换BuildConfig.SENTRY_ANDROID_VERSION。例如,我在app/build.gradle中添加了此依赖项:
implementation 'io.sentry:sentry-android:1.7.10'

现在我应该用BuildConfig.SENTRY_ANDROID_VERSION替换"1.7.10"
并替换此行中的字符串:
conn.setRequestProperty("User-Agent", "sentry-android/" + BuildConfig.SENTRY_ANDROID_VERSION);

并删除注释中的这一行:
* @see com.joshdholtz.sentry.Sentry#addHttpBreadcrumb(String, String, int)

现在您只需要将这一行代码添加到您的主活动中来添加initialize sentry:
SentryLog.init(this, yourDSN);

sentryLog是包含sentry.class代码的新类的名称。
注意:您必须添加不推荐的DSN,该DSN较长。
现在您可以通过添加以下行来测试它:
SentryLog.captureMessage("This Message Captured by Alireza Noorali.");

但我很乐意找到更好的解决方案。

07-24 09:38
查看更多