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?
There are two categories of issues: error issues and performance issues. An error issue is a grouping of error events; a performance issue is a grouping of transactions that are performing poorly.
In your browser, launch the local Django app in the following endpoint to trigger an unhandled error: http://localhost:8000/unhandled . If you've set up an alert rule, you should be notified about the error. Otherwise, open the Issues page in your Sentry account.
Go to your email and open the notification from Sentry. Click "View on Sentry" to view the full details and context of this error in your Sentry account. Note that Sentry aggregates similar errors (events) into one issue. In your account, scroll down to the "Exception" stack trace.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With