Skip to content

Commit

Permalink
Log traffic and errors to Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 2, 2025
1 parent 1e7eb02 commit 1a9321e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Next version

### 🚀 New

* Log traffic and errors to Sentry.


## 0.2.5 - 2025-01-01

### 🚀 New
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies = [
"fastapi-cache2>=0.2.2",
"python3-nmap>=1.9.1",
"typing-extensions>=4.12.2",
"sentry-sdk[fastapi]>=2.19.2",
]

[project.urls]
Expand Down Expand Up @@ -68,6 +69,7 @@ default-groups = ["dev"]
shell = "fastapi dev --host 0.0.0.0 --port $port --reload src/lvmapi/app.py"
env.LVMAPI_PASSWORD = "$2b$12$doiNxsJiL/lGdBMu/zLv5em4GVsUVH7e.YK3EAqxu1NU8qzXxKrti" # "12345"
env.SECRET_KEY = "33744caf930b8c695ec39221dd158e9c5fda13d0d19d1417ec71cf189aad6508"
env.LVMAPI_ENVIRONMENT = "development"
args = [
{ name = "port", default = "8888" }
]
Expand Down
30 changes: 28 additions & 2 deletions src/lvmapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from typing import AsyncIterator

import sentry_sdk
import taskiq_fastapi
from fastapi import FastAPI, HTTPException, Request
from fastapi_cache import FastAPICache
Expand All @@ -22,7 +23,7 @@

from lvmopstools.kubernetes import Kubernetes

from lvmapi import auth, config
from lvmapi import __version__, auth, config
from lvmapi.broker import broker, broker_shutdown, broker_startup
from lvmapi.cache import valis_cache_key_builder
from lvmapi.routers import (
Expand Down Expand Up @@ -69,6 +70,21 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
await broker_shutdown()


sentry_sdk.init(
dsn=os.getenv("LVMAPI_SENTRY_DSN", None),
# 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,
},
release=f"lvmapi@{__version__}",
environment=os.getenv("LVMAPI_ENVIRONMENT", "production"),
)

app = FastAPI(swagger_ui_parameters={"tagsSorter": "alpha"}, lifespan=lifespan)

app.include_router(auth.router)
Expand Down Expand Up @@ -171,5 +187,15 @@ async def route_get_get_fake_state(state: str):


@app.get("/")
def root(request: Request):
def root():
return {}


@app.get("/test")
def test():
return {"result": True}


@app.get("/sentry-debug")
async def trigger_error():
return 1 / 0
20 changes: 20 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1a9321e

Please sign in to comment.