Skip to content

Commit 20d925f

Browse files
committed
Update startup activities
1 parent 672d2df commit 20d925f

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

code/function/fastapp/api/v1/endpoints/sample.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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(

code/function/fastapp/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1+
from contextlib import asynccontextmanager
2+
13
from fastapi import FastAPI
24
from fastapp.api.v1.api_v1 import api_v1_router
35
from fastapp.core.config import settings
46
from 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)

code/function/wrapper/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from opentelemetry.context import attach, detach
55
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
66

7-
setup_opentelemetry(app=app)
7+
# setup_opentelemetry(app=app)
88
tracer = setup_tracer(__name__)
99

1010

0 commit comments

Comments
 (0)