add sentry sdk

This commit is contained in:
Jeremy Yin 2024-03-15 18:44:06 +08:00
parent 8edf8f9fd6
commit cd33a36e28
4 changed files with 57 additions and 3 deletions

View File

@ -1,3 +1,4 @@
MONGO_USERNAME=
MONGO_PASSWORD=
OPENROUTER_API_KEY=
SENTRY_DSN=

View File

@ -5,7 +5,7 @@
groups = ["default"]
strategy = ["cross_platform", "inherit_metadata"]
lock_version = "4.4.1"
content_hash = "sha256:7722c3d89cc1895a68d1ca6e1fc303c8cd178fa8fca91410deb7ecb53027a9ac"
content_hash = "sha256:e5b52083ef7f859b75eea32132ef301095ac77b239a08c49229d4a37474b980b"
[[package]]
name = "annotated-types"
@ -178,6 +178,20 @@ files = [
{file = "loguru-0.7.2.tar.gz", hash = "sha256:e671a53522515f34fd406340ee968cb9ecafbc4b36c679da03c18fd8d0bd51ac"},
]
[[package]]
name = "motor"
version = "3.3.2"
requires_python = ">=3.7"
summary = "Non-blocking MongoDB driver for Tornado or asyncio"
groups = ["default"]
dependencies = [
"pymongo<5,>=4.5",
]
files = [
{file = "motor-3.3.2-py3-none-any.whl", hash = "sha256:6fe7e6f0c4f430b9e030b9d22549b732f7c2226af3ab71ecc309e4a1b7d19953"},
{file = "motor-3.3.2.tar.gz", hash = "sha256:d2fc38de15f1c8058f389c1a44a4d4105c0405c48c061cd492a654496f7bc26a"},
]
[[package]]
name = "openai"
version = "1.14.0"
@ -288,6 +302,20 @@ files = [
{file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"},
]
[[package]]
name = "sentry-sdk"
version = "1.42.0"
summary = "Python client for Sentry (https://sentry.io)"
groups = ["default"]
dependencies = [
"certifi",
"urllib3>=1.26.11; python_version >= \"3.6\"",
]
files = [
{file = "sentry-sdk-1.42.0.tar.gz", hash = "sha256:4a8364b8f7edbf47f95f7163e48334c96100d9c098f0ae6606e2e18183c223e6"},
{file = "sentry_sdk-1.42.0-py2.py3-none-any.whl", hash = "sha256:a654ee7e497a3f5f6368b36d4f04baeab1fe92b3105f7f6965d6ef0de35a9ba4"},
]
[[package]]
name = "sniffio"
version = "1.3.1"
@ -338,6 +366,18 @@ files = [
{file = "typing_extensions-4.10.0.tar.gz", hash = "sha256:b0abd7c89e8fb96f98db18d86106ff1d90ab692004eb746cf6eda2682f91b3cb"},
]
[[package]]
name = "urllib3"
version = "2.2.1"
requires_python = ">=3.8"
summary = "HTTP library with thread-safe connection pooling, file post, and more."
groups = ["default"]
marker = "python_version >= \"3.6\""
files = [
{file = "urllib3-2.2.1-py3-none-any.whl", hash = "sha256:450b20ec296a467077128bff42b73080516e71b56ff59a60a02bef2232c4fa9d"},
{file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"},
]
[[package]]
name = "uvicorn"
version = "0.28.0"

View File

@ -7,12 +7,13 @@ authors = [
]
dependencies = [
"fastapi>=0.110.0",
"pymongo>=4.6.2",
"httpx>=0.27.0",
"uvicorn>=0.28.0",
"openai>=1.14.0",
"loguru>=0.7.2",
"python-dotenv>=1.0.1",
"motor>=3.3.2",
"sentry-sdk>=1.42.0",
]
requires-python = "==3.12.*"
readme = "README.md"

View File

@ -1,5 +1,7 @@
import os
from typing import Union
import sentry_sdk
from fastapi import FastAPI, Request
from dotenv import load_dotenv
from starlette.responses import JSONResponse
@ -15,6 +17,16 @@ from simplylab.providers import Providers
from simplylab.services import Services
load_dotenv()
sentry_sdk.init(
dsn=os.getenv("SENTRY_DSN"),
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)
app = FastAPI()