Merge pull request #415 from TeamPiped/sentry-extra-data

Add some sentry extra data.
This commit is contained in:
Kavin 2022-10-31 01:17:20 +00:00 committed by GitHub
commit 12bcc6bc0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 9 deletions

View file

@ -1,6 +1,7 @@
package me.kavin.piped.server.handlers; package me.kavin.piped.server.handlers;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import io.sentry.Sentry;
import me.kavin.piped.consts.Constants; import me.kavin.piped.consts.Constants;
import me.kavin.piped.ipfs.IPFS; import me.kavin.piped.ipfs.IPFS;
import me.kavin.piped.utils.*; import me.kavin.piped.utils.*;
@ -32,6 +33,8 @@ import static me.kavin.piped.utils.URLUtils.rewriteURL;
public class ChannelHandlers { public class ChannelHandlers {
public static byte[] channelResponse(String channelPath) throws Exception { public static byte[] channelResponse(String channelPath) throws Exception {
Sentry.setExtra("channelPath", channelPath);
final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath); final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath);
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems()); 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.feed.synd.SyndFeedImpl;
import com.rometools.rome.io.FeedException; import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedOutput; import com.rometools.rome.io.SyndFeedOutput;
import io.sentry.Sentry;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import me.kavin.piped.consts.Constants; import me.kavin.piped.consts.Constants;
import me.kavin.piped.server.handlers.auth.AuthPlaylistHandlers; import me.kavin.piped.server.handlers.auth.AuthPlaylistHandlers;
@ -47,6 +48,8 @@ public class PlaylistHandlers {
private static byte[] playlistYouTubeResponse(String playlistId) private static byte[] playlistYouTubeResponse(String playlistId)
throws IOException, ExtractionException { throws IOException, ExtractionException {
Sentry.setExtra("playlistId", playlistId);
final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId); final PlaylistInfo info = PlaylistInfo.getInfo("https://www.youtube.com/playlist?list=" + playlistId);
final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems()); final List<ContentItem> relatedStreams = collectRelatedItems(info.getRelatedItems());

View file

@ -1,5 +1,6 @@
package me.kavin.piped.server.handlers; package me.kavin.piped.server.handlers;
import io.sentry.Sentry;
import me.kavin.piped.utils.ExceptionHandler; import me.kavin.piped.utils.ExceptionHandler;
import me.kavin.piped.utils.obj.ContentItem; import me.kavin.piped.utils.obj.ContentItem;
import me.kavin.piped.utils.obj.SearchResults; import me.kavin.piped.utils.obj.SearchResults;
@ -47,6 +48,8 @@ public class SearchHandlers {
public static byte[] searchResponse(String q, String filter) public static byte[] searchResponse(String q, String filter)
throws IOException, ExtractionException { throws IOException, ExtractionException {
Sentry.setExtra("query", q);
final SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE, final SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE,
YOUTUBE_SERVICE.getSearchQHFactory().fromQuery(q, Collections.singletonList(filter), null)); 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.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE; 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 class StreamHandlers {
public static byte[] streamsResponse(String videoId) throws Exception { public static byte[] streamsResponse(String videoId) throws Exception {
Sentry.configureScope(scope -> { Sentry.setExtra("videoId", videoId);
scope.setContexts("videoId", videoId);
});
final var futureStream = Multithreading.supplyAsync(() -> { final var futureStream = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("StreamInfo fetch", "fetch"); ITransaction transaction = Sentry.startTransaction("StreamInfo fetch", "fetch");
try { try {
return StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId); return StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
} catch (Exception e) { } catch (Exception e) {
transaction.setThrowable(e);
ExceptionUtils.rethrow(e); ExceptionUtils.rethrow(e);
} finally { } finally {
transaction.finish(); transaction.finish();
@ -54,6 +55,7 @@ public class StreamHandlers {
}); });
final var futureLbryId = Multithreading.supplyAsync(() -> { final var futureLbryId = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
try { try {
return LbryHelper.getLBRYId(videoId); return LbryHelper.getLBRYId(videoId);
} catch (Exception e) { } catch (Exception e) {
@ -63,13 +65,16 @@ public class StreamHandlers {
}); });
final var futureLBRY = Multithreading.supplyAsync(() -> { final var futureLBRY = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("LBRY Stream fetch", "fetch"); ITransaction transaction = Sentry.startTransaction("LBRY Stream fetch", "fetch");
try { try {
var childTask = transaction.startChild("fetch", "LBRY ID fetch"); var childTask = transaction.startChild("fetch", "LBRY ID fetch");
String lbryId = futureLbryId.get(2, TimeUnit.SECONDS); String lbryId = futureLbryId.get(2, TimeUnit.SECONDS);
Sentry.setExtra("lbryId", lbryId);
childTask.finish(); childTask.finish();
return LbryHelper.getLBRYStreamURL(lbryId); return LbryHelper.getLBRYStreamURL(lbryId);
} catch (TimeoutException ignored) {
} catch (Exception e) { } catch (Exception e) {
ExceptionHandler.handle(e); ExceptionHandler.handle(e);
} finally { } finally {
@ -79,6 +84,7 @@ public class StreamHandlers {
}); });
final var futureDislikeRating = Multithreading.supplyAsync(() -> { final var futureDislikeRating = Multithreading.supplyAsync(() -> {
Sentry.setExtra("videoId", videoId);
ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch"); ITransaction transaction = Sentry.startTransaction("Dislike Rating", "fetch");
try { try {
return RydHelper.getDislikeRating(videoId); return RydHelper.getDislikeRating(videoId);
@ -195,9 +201,7 @@ public class StreamHandlers {
public static byte[] commentsResponse(String videoId) throws Exception { public static byte[] commentsResponse(String videoId) throws Exception {
Sentry.configureScope(scope -> { Sentry.setExtra("videoId", videoId);
scope.setContexts("videoId", videoId);
});
CommentsInfo info = CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + 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 java.io.IOException;
import static me.kavin.piped.consts.Constants.mapper;
import static me.kavin.piped.utils.RequestUtils.sendGet;
public class RydHelper { public class RydHelper {
public static double getDislikeRating(String videoId) throws IOException { public static double getDislikeRating(String videoId) throws IOException {
if (Constants.DISABLE_RYD) if (Constants.DISABLE_RYD)
return -1; return -1;
return Constants.mapper.readTree(RequestUtils.sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId)) var value = mapper.readTree(sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId))
.get("rating") .get("rating");
.asDouble(-1);
return value == null ? -1 : value.asDouble(-1);
} }
} }