Skip to content

Commit

Permalink
add simple URLs to try app monitoring tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanprytula committed Dec 17, 2024
1 parent 82f3ce5 commit cb3470b
Show file tree
Hide file tree
Showing 6 changed files with 925 additions and 7 deletions.
12 changes: 11 additions & 1 deletion microservices/backend/app/api/routes/private.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from fastapi import APIRouter
from fastapi import APIRouter, Request
from pydantic import BaseModel

from app.api.deps import SessionDep
Expand All @@ -25,6 +25,16 @@ def read_root():
return {"message": "Hello from FastAPI"}


@router.get("/highlight-io-check/")
async def root(request: Request):
return {"message": f"This might not be a great idea {5 / 0}"}


@router.get("/sentry-debug/")
async def trigger_error():
division_by_zero = 1 / 0 # noqa: F841


@router.post("/users/", response_model=UserPublic)
def create_user(user_in: PrivateUserCreate, session: SessionDep) -> Any:
"""
Expand Down
5 changes: 3 additions & 2 deletions microservices/backend/app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import (
AnyUrl,
BeforeValidator,
# HttpUrl,
HttpUrl,
PostgresDsn,
computed_field,
model_validator,
Expand Down Expand Up @@ -44,7 +44,8 @@ def all_cors_origins(self) -> list[str]:
return [str(origin).rstrip("/") for origin in self.BACKEND_CORS_ORIGINS] + [self.FRONTEND_HOST]

PROJECT_NAME: str
# SENTRY_DSN: HttpUrl | None = None
HIGHLIGHTIO_PROJECT_ID: str
SENTRY_DSN: HttpUrl | None = None
POSTGRES_SERVER: str
POSTGRES_PORT: int = 5432
POSTGRES_USER: str
Expand Down
38 changes: 35 additions & 3 deletions microservices/backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# import sentry_sdk
import highlight_io
import sentry_sdk
from fastapi import FastAPI
from fastapi.routing import APIRoute
from highlight_io.integrations.fastapi import FastAPIMiddleware
from starlette.middleware.cors import CORSMiddleware

from app.api.main import api_router
Expand All @@ -11,15 +13,45 @@ def custom_generate_unique_id(route: APIRoute) -> str:
return f"{route.tags[0]}-{route.name}"


# if settings.SENTRY_DSN and settings.ENVIRONMENT != "local":
# sentry_sdk.init(dsn=str(settings.SENTRY_DSN), enable_tracing=True)
if settings.SENTRY_DSN and settings.ENVIRONMENT != "local":
sentry_sdk.init(
dsn=str(settings.SENTRY_DSN),
environment=settings.ENVIRONMENT,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
traces_sample_rate=1.0,
_experiments={
# Set continuous_profiling_auto_start to True
# to automatically start the profiler on when
# possible.
"continuous_profiling_auto_start": True,
},
enable_tracing=True,
)

app = FastAPI(
title=settings.PROJECT_NAME,
openapi_url=f"{settings.API_V1_STR}/openapi.json",
generate_unique_id_function=custom_generate_unique_id,
)

if settings.HIGHLIGHTIO_PROJECT_ID and settings.ENVIRONMENT != "local":
import subprocess

# Get the current Git SHA commit
git_sha = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip()

# `instrument_logging=True` sets up logging instrumentation.
# if you do not want to send logs or are using `loguru`, pass `instrument_logging=False`
H = highlight_io.H(
settings.HIGHLIGHTIO_PROJECT_ID,
instrument_logging=True,
service_name="backend-fastapi",
service_version=git_sha,
environment=settings.ENVIRONMENT,
)
app.add_middleware(FastAPIMiddleware)

# Set all CORS enabled origins
if settings.all_cors_origins:
app.add_middleware(
Expand Down
2 changes: 1 addition & 1 deletion microservices/backend/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ services:

healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/api/v1/utils/health-check/"]
interval: 10s
interval: 30s
timeout: 5s
retries: 5

Expand Down
3 changes: 3 additions & 0 deletions microservices/backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ dependencies = [
"bcrypt==4.0.1",
"emails>=0.6,<1.0",
"fastapi[standard]>=0.115.6",
"highlight-io>=0.9.0",
"passlib[bcrypt]>=1.7.4,<2.0.0",
"psycopg[binary]>=3.2.3",
"pydantic-settings>=2.2.1,<3.0.0",
"pydantic[email]>=2.10.3",
"pyjwt>=2.10.1",
"python-multipart>=0.0.7,<1.0.0",
"sentry-sdk[fastapi]>=2.19.2",
"sqlmodel>=0.0.22,<1.0.0",
"tenacity>=9.0.0",
]

[dependency-groups]
dev = [
"coverage>=7.6.9",
"ipython>=8.30.0",
"pytest>=8.3.4",
]
Loading

0 comments on commit cb3470b

Please sign in to comment.