设置 Sentry.io 时出现问题。没有发送到哨兵面板

Ali*_*ali 6 android sentry

我打算将 Sentry 用于我正在处理的 Android 项目。我的公司正在使用自托管的 Sentry,版本 9.0.0

我遵循了Sentry.io 安装指南

这些权限已添加到清单中:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Run Code Online (Sandbox Code Playgroud)

这是我的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
}
Run Code Online (Sandbox Code Playgroud)

这是我的顶级项目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
}
Run Code Online (Sandbox Code Playgroud)

这是主要活动:

@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!");
    ...
}
Run Code Online (Sandbox Code Playgroud)

但没有发送到哨兵面板。有什么问题?

有任何想法吗?

Ali*_*ali 5

这不是我需要的答案,但说起来也不错

最后我找到了一个使用这个类将日志发送到 Sentry 面板的解决方案:Sentry.class

然而它需要一些改变才能工作,但现在它就像一个魅力。唯一让我担心的是,当我在 Sentry 面板中打开一个事件时,此警告将显示在页面底部:

此事件是使用旧版本的 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));
Run Code Online (Sandbox Code Playgroud)

并替换BuildConfig.SENTRY_ANDROID_VERSION为包含哨兵库版本的字符串。例如,我在app/build.gradle 中添加了这个依赖

implementation 'io.sentry:sentry-android:1.7.10'
Run Code Online (Sandbox Code Playgroud)

现在我应该替换BuildConfig.SENTRY_ANDROID_VERSION"1.7.10"

并替换此行中的字符串:

conn.setRequestProperty("User-Agent", "sentry-android/" + BuildConfig.SENTRY_ANDROID_VERSION);
Run Code Online (Sandbox Code Playgroud)

并在评论中删除这一行:

* @see com.joshdholtz.sentry.Sentry#addHttpBreadcrumb(String, String, int)
Run Code Online (Sandbox Code Playgroud)

现在只需要通过将这行代码添加到 MainActivity 来添加 initialize Sentry:

SentryLog.init(this, yourDSN);
Run Code Online (Sandbox Code Playgroud)

SentryLog 是包含 Sentry.class 代码的新类的名称。

注意:您必须添加已弃用的更长的 DSN。

现在您可以通过添加以下行来测试它:

SentryLog.captureMessage("This Message Captured by Alireza Noorali.");
Run Code Online (Sandbox Code Playgroud)

但我会很高兴得到更好的解决方案。