代码之家  ›  专栏  ›  技术社区  ›  Alireza Noorali Pedro Gonzalez

设置Sentry.io时出现问题。没有发送到岗哨小组

  •  4
  • Alireza Noorali Pedro Gonzalez  · 技术社区  · 7 年前

    我将使用哨兵我的安卓项目我正在工作。 我的公司正在使用一个自我托管的哨兵,版本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!");
        ...
    }
    

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

    1 回复  |  直到 7 年前
        1
  •  4
  •   Alireza Noorali Pedro Gonzalez    7 年前

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

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

    不过,它需要一些改变才能发挥作用,但现在它发挥了魅力。 唯一让我担心的是,当我在岗哨面板中打开一个事件时,此警告将显示在页面底部:

    此事件是用旧版本的java SDK报告的。

    岗哨班 将其代码复制到您在项目中创建的新类中,并找到以下代码:

    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_版本 具有 "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);
    

    注意:您必须添加不推荐的DSN,该DSN较长。

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

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

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

    推荐文章