Skip to content

Commit 6585b79

Browse files
committed
Fix requirements.txt
1 parent 20d8fe3 commit 6585b79

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/fastapi_app/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import os
44

55
import azure.identity.aio
6+
import fastapi
7+
from azure.monitor.opentelemetry import configure_azure_monitor
68
from dotenv import load_dotenv
79
from environs import Env
8-
from fastapi import FastAPI
10+
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
911

1012
from .globals import global_storage
1113
from .openai_clients import create_openai_chat_client
@@ -15,7 +17,7 @@
1517

1618

1719
@contextlib.asynccontextmanager
18-
async def lifespan(app: FastAPI):
20+
async def lifespan(app: fastapi.FastAPI):
1921
load_dotenv(override=True)
2022

2123
azure_credential = None
@@ -40,6 +42,8 @@ async def lifespan(app: FastAPI):
4042
global_storage.openai_chat_client = openai_chat_client
4143
global_storage.openai_chat_model = openai_chat_model
4244

45+
if os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"):
46+
SQLAlchemyInstrumentor().instrument(engine=engine.sync_engine)
4347
yield
4448

4549
await engine.dispose()
@@ -54,7 +58,14 @@ def create_app():
5458
else:
5559
logging.basicConfig(level=logging.WARNING)
5660

57-
app = FastAPI(docs_url="/docs", lifespan=lifespan)
61+
# Turn off particularly noisy INFO level logs from Azure Core SDK:
62+
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.WARNING)
63+
64+
if os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"):
65+
logger.info("Configuring Azure Monitor")
66+
configure_azure_monitor(logger_name="ragapp")
67+
68+
app = fastapi.FastAPI(docs_url="/docs", lifespan=lifespan)
5869

5970
from . import api_routes # noqa
6071
from . import frontend_routes # noqa

src/requirements.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ async-timeout==4.0.3
77
asyncpg==0.29.0
88
attrs==23.2.0
99
azure-core==1.30.1
10+
azure-core-tracing-opentelemetry
1011
azure-identity==1.16.0
12+
azure-monitor-opentelemetry
1113
azure-monitor-opentelemetry-exporter==1.0.0b27
1214
build==1.2.1
1315
certifi==2024.2.2
@@ -24,7 +26,7 @@ email_validator==2.1.1
2426
environs==11.0.0
2527
fastapi==0.111.0
2628
fastapi-cli==0.0.4
27-
-e git+https://github.com/chatrtham/rag-postgres-openai-python.git@7f1578f2d48381331570f68cc13167c3290ee097#egg=fastapi_app&subdirectory=src
29+
-e git+https://github.com/chatrtham/rag-postgres-openai-python@20d8fe30d4373e9290dbd18c012f6610393fd5e7#egg=fastapi_app&subdirectory=src
2830
filelock==3.14.0
2931
fixedint==0.1.6
3032
frozenlist==1.4.1
@@ -63,10 +65,18 @@ opentelemetry-exporter-otlp-proto-grpc==1.25.0
6365
opentelemetry-exporter-otlp-proto-http==1.25.0
6466
opentelemetry-instrumentation==0.46b0
6567
opentelemetry-instrumentation-asgi==0.46b0
68+
opentelemetry-instrumentation-dbapi==0.46b0
69+
opentelemetry-instrumentation-django==0.46b0
6670
opentelemetry-instrumentation-fastapi==0.46b0
71+
opentelemetry-instrumentation-flask==0.46b0
72+
opentelemetry-instrumentation-psycopg2==0.46b0
6773
opentelemetry-instrumentation-requests==0.46b0
6874
opentelemetry-instrumentation-sqlalchemy==0.46b0
75+
opentelemetry-instrumentation-urllib==0.46b0
76+
opentelemetry-instrumentation-urllib3==0.46b0
77+
opentelemetry-instrumentation-wsgi==0.46b0
6978
opentelemetry-proto==1.25.0
79+
opentelemetry-resource-detector-azure==0.1.5
7080
opentelemetry-sdk==1.25.0
7181
opentelemetry-semantic-conventions==0.46b0
7282
opentelemetry-util-http==0.46b0

0 commit comments

Comments
 (0)