【问题标题】:Problem in setting up Sentry.io . Nothing sent to Sentry Panel设置 Sentry.io 时出现问题。没有发送到哨兵小组
【发布时间】:2019-04-16 01:53:12
【问题描述】:

我将在我正在处理的 Android 项目中使用 Sentry。 我的公司正在使用自托管的 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
}

这是 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!");
    ...
}

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

有什么想法吗?

【问题讨论】:

标签: android sentry


【解决方案1】:

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

最后我找到了使用此类将日志发送到 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));

并用包含哨兵库版本的字符串替换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);

并在 cmets 中删除这一行:

* @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.");

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多