File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,9 @@ async def post_predict(
23
23
response = await client .get ("https://www.bing.com" )
24
24
logger .info (f"Received response status code: { response .status_code } " )
25
25
26
- with httpx .Client () as client :
27
- response = client .get ("https://www.google.com" )
28
- response = httpx .get ("https://www.google.de" )
26
+ # with httpx.Client() as client:
27
+ # response = client.get("https://www.google.com")
28
+ # response = httpx.get("https://www.google.de")
29
29
30
30
# tracer_attributes = {"http.client_ip": x_forwarded_for}
31
31
# with tracer.start_as_current_span(
Original file line number Diff line number Diff line change
1
+ from contextlib import asynccontextmanager
2
+
1
3
from fastapi import FastAPI
2
4
from fastapp .api .v1 .api_v1 import api_v1_router
3
5
from fastapp .core .config import settings
4
6
from fastapp .utils import setup_opentelemetry
5
7
6
8
7
- def get_app () -> FastAPI :
9
+ def get_app (lifespan ) -> FastAPI :
8
10
"""Setup the Fast API server.
9
11
10
12
RETURNS (FastAPI): The FastAPI object to start the server.
11
13
"""
12
14
app = FastAPI (
13
15
title = settings .PROJECT_NAME ,
16
+ description = "" ,
14
17
version = settings .APP_VERSION ,
15
18
openapi_url = "/openapi.json" ,
16
19
debug = settings .DEBUG ,
20
+ lifespan = lifespan ,
17
21
)
18
22
app .include_router (api_v1_router , prefix = settings .API_V1_STR )
19
23
return app
20
24
21
25
22
- app = get_app ()
23
-
24
-
25
- @app .on_event ("startup" )
26
- async def startup_event ():
26
+ @asynccontextmanager
27
+ async def lifespan (app : FastAPI ) -> None :
27
28
"""Gracefully start the application before the server reports readiness."""
28
29
setup_opentelemetry (app = app )
30
+ yield
31
+ pass
29
32
30
33
31
- @app .on_event ("shutdown" )
32
- async def shutdown_event ():
33
- """Gracefully close connections before shutdown of the server."""
34
- pass
34
+ app = get_app (lifespan = lifespan )
Original file line number Diff line number Diff line change 4
4
from opentelemetry .context import attach , detach
5
5
from opentelemetry .trace .propagation .tracecontext import TraceContextTextMapPropagator
6
6
7
- setup_opentelemetry (app = app )
7
+ # setup_opentelemetry(app=app)
8
8
tracer = setup_tracer (__name__ )
9
9
10
10
You can’t perform that action at this time.
0 commit comments