Add Sentry

This commit is contained in:
Michel Roux 2023-01-05 00:49:54 +01:00
parent ce78aa7e55
commit 54a36adebf
6 changed files with 40 additions and 6 deletions

16
poetry.lock generated
View File

@ -131,6 +131,18 @@ d = ["aiohttp (>=3.7.4)"]
jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"]
uvloop = ["uvloop (>=0.15.2)"]
[[package]]
name = "blinker"
version = "1.5"
description = "Fast, simple object-to-object and broadcast signaling"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
files = [
{file = "blinker-1.5-py2.py3-none-any.whl", hash = "sha256:1eb563df6fdbc39eeddc177d953203f99f097e9bf0e2b8f9f3cf18b6ca425e36"},
{file = "blinker-1.5.tar.gz", hash = "sha256:923e5e2f69c155f2cc42dafbbd70e16e3fde24d2d4aa2ab72fbe386238892462"},
]
[[package]]
name = "certifi"
version = "2022.12.7"
@ -1308,7 +1320,9 @@ files = [
]
[package.dependencies]
blinker = {version = ">=1.1", optional = true, markers = "extra == \"flask\""}
certifi = "*"
flask = {version = ">=0.11", optional = true, markers = "extra == \"flask\""}
urllib3 = {version = ">=1.26.11", markers = "python_version >= \"3.6\""}
[package.extras]
@ -1707,4 +1721,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
[metadata]
lock-version = "2.0"
python-versions = "^3.7"
content-hash = "e3031b5c16ad6cf25f786cf4d14f0871d0abace95d3380c1a6b14b7e1ab37756"
content-hash = "ea1fd278a3dc000ed3d374c9006b959014cf8f67c62c99bc4b15aeeca2e64311"

View File

@ -1,5 +1,6 @@
import asyncio
from datetime import datetime
from os import getenv
from secrets import token_hex
from flask import Flask, redirect, render_template, request, url_for
@ -8,6 +9,25 @@ from pynyaata.bridge import search_all
from pynyaata.forms import SearchForm
from pynyaata.translations import current_lang, i18n
from sentry_sdk import init
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
SENTRY_DNS = getenv("SENTRY_DSN")
if SENTRY_DNS:
init(
SENTRY_DNS,
integrations=[
AsyncioIntegration(),
FlaskIntegration(),
RedisIntegration(),
SqlalchemyIntegration(),
],
)
app = Flask(__name__)
app.config["SECRET_KEY"] = token_hex()

View File

@ -22,4 +22,4 @@ async def search_all(query: str = "", page: int = 1) -> List[RemoteFile]:
for bridge in BRIDGES:
tasks.append(create_task(bridge.search(query, page)))
return await gather(*tasks)
return await gather(*tasks, return_exceptions=True)

View File

@ -27,7 +27,7 @@ class AnimeUltime(Bridge):
return parse_obj_as(
HttpUrl,
(
f"{self.base_url}"
f"{self.base_url}/"
f"{'search' if query else 'history'}-0-1/"
f"{page_date.strftime('%m%Y') if query else ''}"
),

View File

@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
from datetime import datetime
from enum import Enum
from functools import wraps
from logging import error
from logging import exception
from typing import List, Optional
from pydantic import BaseModel, ByteSize, HttpUrl
@ -72,7 +72,7 @@ def log_async(f):
try:
return await f(*args, **kwargs)
except Exception as e:
error(e)
exception(e)
raise e
return wrapper

View File

@ -27,7 +27,7 @@ pydantic = "1.10.4"
pymysql = "1.0.2"
redis = "4.4.0"
requests = "2.28.1"
sentry-sdk = "1.12.1"
sentry-sdk = {extras = ["flask"], version = "1.12.1"}
[tool.poetry.group.dev.dependencies]