From 405e0d3bb39c92562dce178704cfb8ab7f8cf256 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 31 Oct 2022 01:15:46 +0000 Subject: [PATCH] Add some sentry extra data. And fix potential NPE in RydHelper. --- .../piped/server/handlers/ChannelHandlers.java | 3 +++ .../piped/server/handlers/PlaylistHandlers.java | 3 +++ .../piped/server/handlers/SearchHandlers.java | 3 +++ .../piped/server/handlers/StreamHandlers.java | 16 ++++++++++------ .../java/me/kavin/piped/utils/RydHelper.java | 10 +++++++--- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java index e767bda..4099edd 100644 --- a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java @@ -1,6 +1,7 @@ package me.kavin.piped.server.handlers; import com.fasterxml.jackson.core.JsonProcessingException; +import io.sentry.Sentry; import me.kavin.piped.consts.Constants; import me.kavin.piped.ipfs.IPFS; import me.kavin.piped.utils.*; @@ -32,6 +33,8 @@ import static me.kavin.piped.utils.URLUtils.rewriteURL; public class ChannelHandlers { public static byte[] channelResponse(String channelPath) throws Exception { + Sentry.setExtra("channelPath", channelPath); + final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath); final List relatedStreams = collectRelatedItems(info.getRelatedItems()); diff --git a/src/main/java/me/kavin/piped/server/handlers/PlaylistHandlers.java b/src/main/java/me/kavin/piped/server/handlers/PlaylistHandlers.java index 0a8a88d..658962a 100644 --- a/src/main/java/me/kavin/piped/server/handlers/PlaylistHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/PlaylistHandlers.java @@ -6,6 +6,7 @@ import com.rometools.rome.feed.synd.SyndFeed; import com.rometools.rome.feed.synd.SyndFeedImpl; import com.rometools.rome.io.FeedException; import com.rometools.rome.io.SyndFeedOutput; +import io.sentry.Sentry; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import me.kavin.piped.consts.Constants; import me.kavin.piped.server.handlers.auth.AuthPlaylistHandlers; @@ -47,6 +48,8 @@ public class PlaylistHandlers { private static byte[] playlistYouTubeResponse(String playlistId) throws IOException, ExtractionException { + Sentry.setExtra("playlistId", playlistId); + final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId); final List relatedStreams = collectRelatedItems(info.getRelatedItems()); diff --git a/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java b/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java index 5c33783..4df9149 100644 --- a/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java @@ -1,5 +1,6 @@ package me.kavin.piped.server.handlers; +import io.sentry.Sentry; import me.kavin.piped.utils.ExceptionHandler; import me.kavin.piped.utils.obj.ContentItem; import me.kavin.piped.utils.obj.SearchResults; @@ -47,6 +48,8 @@ public class SearchHandlers { public static byte[] searchResponse(String q, String filter) throws IOException, ExtractionException { + Sentry.setExtra("query", q); + final SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE, YOUTUBE_SERVICE.getSearchQHFactory().fromQuery(q, Collections.singletonList(filter), null)); diff --git a/src/main/java/me/kavin/piped/server/handlers/StreamHandlers.java b/src/main/java/me/kavin/piped/server/handlers/StreamHandlers.java index 2c3e23c..5197379 100644 --- a/src/main/java/me/kavin/piped/server/handlers/StreamHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/StreamHandlers.java @@ -23,6 +23,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import static java.nio.charset.StandardCharsets.UTF_8; import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE; @@ -37,15 +38,15 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper public class StreamHandlers { public static byte[] streamsResponse(String videoId) throws Exception { - Sentry.configureScope(scope -> { - scope.setContexts("videoId", videoId); - }); + Sentry.setExtra("videoId", videoId); final var futureStream = Multithreading.supplyAsync(() -> { + Sentry.setExtra("videoId", videoId); ITransaction transaction = Sentry.startTransaction("StreamInfo fetch", "fetch"); try { return StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId); } catch (Exception e) { + transaction.setThrowable(e); ExceptionUtils.rethrow(e); } finally { transaction.finish(); @@ -54,6 +55,7 @@ public class StreamHandlers { }); final var futureLbryId = Multithreading.supplyAsync(() -> { + Sentry.setExtra("videoId", videoId); try { return LbryHelper.getLBRYId(videoId); } catch (Exception e) { @@ -63,13 +65,16 @@ public class StreamHandlers { }); final var futureLBRY = Multithreading.supplyAsync(() -> { + Sentry.setExtra("videoId", videoId); ITransaction transaction = Sentry.startTransaction("LBRY Stream fetch", "fetch"); try { var childTask = transaction.startChild("fetch", "LBRY ID fetch"); String lbryId = futureLbryId.get(2, TimeUnit.SECONDS); + Sentry.setExtra("lbryId", lbryId); childTask.finish(); return LbryHelper.getLBRYStreamURL(lbryId); + } catch (TimeoutException ignored) { } catch (Exception e) { ExceptionHandler.handle(e); } finally { @@ -79,6 +84,7 @@ public class StreamHandlers { }); final var futureDislikeRating = Multithreading.supplyAsync(() -> { + Sentry.setExtra("videoId", videoId); ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch"); try { return RydHelper.getDislikeRating(videoId); @@ -195,9 +201,7 @@ public class StreamHandlers { public static byte[] commentsResponse(String videoId) throws Exception { - Sentry.configureScope(scope -> { - scope.setContexts("videoId", videoId); - }); + Sentry.setExtra("videoId", videoId); CommentsInfo info = CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + videoId); diff --git a/src/main/java/me/kavin/piped/utils/RydHelper.java b/src/main/java/me/kavin/piped/utils/RydHelper.java index e10ec98..dfa4375 100644 --- a/src/main/java/me/kavin/piped/utils/RydHelper.java +++ b/src/main/java/me/kavin/piped/utils/RydHelper.java @@ -5,14 +5,18 @@ import me.kavin.piped.consts.Constants; import java.io.IOException; +import static me.kavin.piped.consts.Constants.mapper; +import static me.kavin.piped.utils.RequestUtils.sendGet; + public class RydHelper { public static double getDislikeRating(String videoId) throws IOException { if (Constants.DISABLE_RYD) return -1; - return Constants.mapper.readTree(RequestUtils.sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId)) - .get("rating") - .asDouble(-1); + var value = mapper.readTree(sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId)) + .get("rating"); + + return value == null ? -1 : value.asDouble(-1); } }