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

标签 android sentry

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

我关注了Sentry.io Installation Guide .

这些权限已添加到 list 中:

<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
}

这是 MainActivity:

@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 面板。有什么问题?

有什么想法吗?

最佳答案

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

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

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

This event was reported with an old version of the 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));

并将 BuildConfig.SENTRY_ANDROID_VERSION 替换为包含 Sentry 库版本的字符串。例如,我在我的 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)

现在您只需要通过将这行代码添加到您的 MainActivity 来添加初始化 Sentry:

SentryLog.init(this, yourDSN);

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

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

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

SentryLog.captureMessage("This Message Captured by Alireza Noorali.");

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

关于android - 设置 Sentry.io 时出现问题。没有发送到 Sentry 面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53277487/

相关文章:

android - 如何在 Android 中以编程方式创建与 Sim 的联系

java - 让用户保持登录状态,在 Android 上是一个 android 应用程序

go - 有没有办法将 Sentry 消息输出到控制台

python - Sentry - 清理局部变量敏感数据

logging - Celery Worker – 删除警告消息 `[WARNING/MainProcess] celery@localhost ready`

android - 在长按主页按钮菜单中隐藏安卓应用程序

android - 你如何安装和早期版本的 Android 工具和平台工具?

android - 当应用程序在后台运行时使用挂起的 Intent 启动 Activity

sentry - 防止根本原因消息在 Sentry 中被截断(过多)

reactjs - 如何在 React 项目中自动创建 Sentry 版本并将源映射上传到 Sentry?