-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (41 loc) · 1.22 KB
/
main.py
File metadata and controls
55 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from fastapi import FastAPI, Depends, HTTPException
import os
import sentry_sdk
from sentry_sdk.integrations.starlette import StarletteIntegration
from sentry_sdk.integrations.fastapi import FastApiIntegration
failed_request_status_codes = [range(400, 600)]
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN"),
environment=os.environ.get("ENV", "test"),
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
debug=True,
integrations=[
StarletteIntegration(failed_request_status_codes=failed_request_status_codes),
FastApiIntegration(failed_request_status_codes=failed_request_status_codes),
],
)
app = FastAPI()
def get_user():
user = {
"id": "testuser"
}
sentry_sdk.set_user(user)
return user
@app.middleware("http")
async def test_middleware(request, call_next):
print("middleware")
return await call_next(request)
@app.get("/error")
def endpoint(user = Depends(get_user)):
raise ValueError("help! an error!")
@app.post("/post")
def main(user):
return user
@app.get("/")
def endpoint():
return {
"hello": "world!",
"errors-are-here": "http://localhost:5000/error",
"http-exception": "http://localhost:5000/http-exception",
}