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(
2323 response = await client .get ("https://www.bing.com" )
2424 logger .info (f"Received response status code: { response .status_code } " )
2525
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")
2929
3030 # tracer_attributes = {"http.client_ip": x_forwarded_for}
3131 # with tracer.start_as_current_span(
Original file line number Diff line number Diff line change 1+ from contextlib import asynccontextmanager
2+
13from fastapi import FastAPI
24from fastapp .api .v1 .api_v1 import api_v1_router
35from fastapp .core .config import settings
46from fastapp .utils import setup_opentelemetry
57
68
7- def get_app () -> FastAPI :
9+ def get_app (lifespan ) -> FastAPI :
810 """Setup the Fast API server.
911
1012 RETURNS (FastAPI): The FastAPI object to start the server.
1113 """
1214 app = FastAPI (
1315 title = settings .PROJECT_NAME ,
16+ description = "" ,
1417 version = settings .APP_VERSION ,
1518 openapi_url = "/openapi.json" ,
1619 debug = settings .DEBUG ,
20+ lifespan = lifespan ,
1721 )
1822 app .include_router (api_v1_router , prefix = settings .API_V1_STR )
1923 return app
2024
2125
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 :
2728 """Gracefully start the application before the server reports readiness."""
2829 setup_opentelemetry (app = app )
30+ yield
31+ pass
2932
3033
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 44from opentelemetry .context import attach , detach
55from opentelemetry .trace .propagation .tracecontext import TraceContextTextMapPropagator
66
7- setup_opentelemetry (app = app )
7+ # setup_opentelemetry(app=app)
88tracer = setup_tracer (__name__ )
99
1010
You can’t perform that action at this time.
0 commit comments