Merge pull request #410 from TeamPiped/sentry-dsn

Allow using sentry to log errors.
This commit is contained in:
Kavin 2022-10-30 19:58:31 +00:00 committed by GitHub
commit 8e1d2c4a7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 11 deletions

View file

@ -39,8 +39,9 @@ dependencies {
implementation 'org.springframework.security:spring-security-crypto:5.7.4' implementation 'org.springframework.security:spring-security-crypto:5.7.4'
implementation 'commons-logging:commons-logging:1.2' implementation 'commons-logging:commons-logging:1.2'
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0")) implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))
implementation("com.squareup.okhttp3:okhttp") implementation 'com.squareup.okhttp3:okhttp'
implementation("com.squareup.okhttp3:okhttp-brotli") implementation 'com.squareup.okhttp3:okhttp-brotli'
implementation 'io.sentry:sentry:6.6.0'
} }
shadowJar { shadowJar {

View file

@ -34,6 +34,9 @@ DISABLE_SERVER:false
DISABLE_LBRY:false DISABLE_LBRY:false
# How long should unauthenticated subscriptions last for # How long should unauthenticated subscriptions last for
SUBSCRIPTIONS_EXPIRY:30 SUBSCRIPTIONS_EXPIRY:30
# Sentry DSN
# Use Sentry to log errors and trace performance
#SENTRY_DSN:INSERT_HERE
# Hibernate properties # Hibernate properties
hibernate.connection.url:jdbc:postgresql://postgres:5432/piped hibernate.connection.url:jdbc:postgresql://postgres:5432/piped
hibernate.connection.driver_class:org.postgresql.Driver hibernate.connection.driver_class:org.postgresql.Driver

View file

@ -1,6 +1,7 @@
package me.kavin.piped; package me.kavin.piped;
import io.activej.inject.Injector; import io.activej.inject.Injector;
import io.sentry.Sentry;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import me.kavin.piped.consts.Constants; import me.kavin.piped.consts.Constants;
import me.kavin.piped.server.ServerLauncher; import me.kavin.piped.server.ServerLauncher;
@ -28,17 +29,15 @@ public class Main {
YoutubeStreamExtractor.forceFetchAndroidClient(true); YoutubeStreamExtractor.forceFetchAndroidClient(true);
YoutubeStreamExtractor.forceFetchIosClient(true); YoutubeStreamExtractor.forceFetchIosClient(true);
Sentry.init(Constants.SENTRY_DSN);
Injector.useSpecializer(); Injector.useSpecializer();
new Timer().scheduleAtFixedRate(new TimerTask() { new Timer().scheduleAtFixedRate(new TimerTask() {
@Override @Override
public void run() { public void run() {
try { System.out.printf("ThrottlingCache: %o entries%n", YoutubeThrottlingDecrypter.getCacheSize());
System.out.printf("ThrottlingCache: %o entries%n", YoutubeThrottlingDecrypter.getCacheSize()); YoutubeThrottlingDecrypter.clearCache();
YoutubeThrottlingDecrypter.clearCache();
} catch (Exception e) {
e.printStackTrace();
}
} }
}, 0, TimeUnit.MINUTES.toMillis(60)); }, 0, TimeUnit.MINUTES.toMillis(60));

View file

@ -68,6 +68,8 @@ public class Constants {
public static final int SUBSCRIPTIONS_EXPIRY; public static final int SUBSCRIPTIONS_EXPIRY;
public static final String SENTRY_DSN;
public static final String VERSION; public static final String VERSION;
public static final ObjectMapper mapper = JsonMapper.builder() public static final ObjectMapper mapper = JsonMapper.builder()
@ -107,6 +109,7 @@ public class Constants {
DISABLE_SERVER = Boolean.parseBoolean(getProperty(prop, "DISABLE_SERVER", "false")); DISABLE_SERVER = Boolean.parseBoolean(getProperty(prop, "DISABLE_SERVER", "false"));
DISABLE_LBRY = Boolean.parseBoolean(getProperty(prop, "DISABLE_LBRY", "false")); DISABLE_LBRY = Boolean.parseBoolean(getProperty(prop, "DISABLE_LBRY", "false"));
SUBSCRIPTIONS_EXPIRY = Integer.parseInt(getProperty(prop, "SUBSCRIPTIONS_EXPIRY", "30")); SUBSCRIPTIONS_EXPIRY = Integer.parseInt(getProperty(prop, "SUBSCRIPTIONS_EXPIRY", "30"));
SENTRY_DSN = getProperty(prop, "SENTRY_DSN", "");
System.getenv().forEach((key, value) -> { System.getenv().forEach((key, value) -> {
if (key.startsWith("hibernate")) if (key.startsWith("hibernate"))
hibernateProperties.put(key, value); hibernateProperties.put(key, value);

View file

@ -1,5 +1,7 @@
package me.kavin.piped.utils; package me.kavin.piped.utils;
import io.sentry.Sentry;
import me.kavin.piped.consts.Constants;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
@ -17,9 +19,12 @@ public class ExceptionHandler {
e = (Exception) e.getCause(); e = (Exception) e.getCause();
if (!(e instanceof ContentNotAvailableException)) { if (!(e instanceof ContentNotAvailableException)) {
if (path != null) Sentry.captureException(e);
System.err.println("An error occoured in the path: " + path); if (Constants.SENTRY_DSN.isEmpty()) {
e.printStackTrace(); if (path != null)
System.err.println("An error occoured in the path: " + path);
e.printStackTrace();
}
} }
return e; return e;