Skip to content

Commit

Permalink
Enabled Telementry
Browse files Browse the repository at this point in the history
  • Loading branch information
jontyms committed Aug 31, 2024
1 parent 23af2c2 commit 6164041
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
# Import options
from app.util.settings import Settings

if Settings().telemetry.enable:
import sentry_sdk

# Init Logger
logging.basicConfig(
level=logging.INFO,
Expand All @@ -60,6 +63,19 @@
templates = Jinja2Templates(directory="app/templates")
app.mount("/static", StaticFiles(directory="./app/static"), name="static")

if Settings().telemetry.enable:
sentry_sdk.init(
dsn=Settings().telemetry.url,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=0.3,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=0.3,
environment=Settings().telemetry.env,
)

# Import endpoints from ./routes
app.include_router(api.router)
app.include_router(admin.router)
Expand Down
5 changes: 5 additions & 0 deletions app/util/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
from app.util.errors import Errors
from app.util.settings import Settings

if Settings().telemetry.enable:
from sentry_sdk import set_user


class Authentication:
def __init__(self):
Expand Down Expand Up @@ -125,6 +128,8 @@ async def wrapper_member(
"Session expired.",
essay="Sessions last for about fifteen weeks. You need to re-log-in between semesters.",
)
if Settings().telemetry.enable:
set_user({"id": user_jwt["id"]})

return await func(request, token, payload, *args, **kwargs)

Expand Down

0 comments on commit 6164041

Please sign in to comment.