设置Sentry.io时出现问题。什么都没有发送到哨兵小组

时间:2018-11-13 09:13:07

标签: android sentry

我将使用Sentry进行我的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
}

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

,但没有任何内容发送到哨兵小组。有什么问题吗?

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

这不是我需要回答的问题

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

并在注释中删除此行:

* @see com.joshdholtz.sentry.Sentry#addHttpBreadcrumb(String, String, int)

现在,您只需要通过将以下代码行添加到MainActivity中来添加初始化Sentry:

SentryLog.init(this, yourDSN);

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

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

现在您可以通过添加以下行对其进行测试:

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

但是我很高兴获得更好的解决方案。