6

I'm going to use Sentry for My Android project I’m working on. My company is using a self hosted Sentry, version 9.0.0

I followed Sentry.io Installation Guide.

These permissions were added in Manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

This is my app/build.gradle file:

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
}

This is my top level project 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
}

This is 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!");
    ...
}

but nothing sent to Sentry Panel. What's the problem?

Any Ideas?

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80

1 Answers1

5

THIS IS NOT THE ANSWER I NEED BUT IT'S NOT BAD TO SAY

Finally I found a solution to send Logs to Sentry panel using this class: Sentry.class

however it needed some changes to work, but now it works like a charm. The only thing that worries me is that when I open an event in Sentry panel this warning will be displayed at the bottom of the page:

This event was reported with an old version of the java SDK.

To initialize and capture logs using that Sentry.class copy its codes to a new class which you created in your project and find the below piece of code:

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));

and replace BuildConfig.SENTRY_ANDROID_VERSION with a string which contains sentry library version. for example I added this dependency in my app/build.gradle:

implementation 'io.sentry:sentry-android:1.7.10'

now I should replace BuildConfig.SENTRY_ANDROID_VERSION with "1.7.10"

and also replace the string in this line:

conn.setRequestProperty("User-Agent", "sentry-android/" + BuildConfig.SENTRY_ANDROID_VERSION);

and delete this line in comments:

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

Now just you need to add initialize Sentry by adding this line of code to your MainActivity:

SentryLog.init(this, yourDSN);

SentryLog is the name of my new class that contains Sentry.class codes.

Pay attention: you have to add deprecated DSN which is longer.

now you can test it by adding this line:

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

But I'll be glad to get better solutions.

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80