Add some sentry extra data.

And fix potential NPE in RydHelper.
This commit is contained in:
Kavin 2022-10-31 01:15:46 +00:00
parent 9a143f67b5
commit 405e0d3bb3
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
5 changed files with 26 additions and 9 deletions

View file

@ -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<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());

View file

@ -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<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());

View file

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

View file

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

View file

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