Skip to content

Commit 4e76272

Browse files
committed
otel
1 parent 4f85bc1 commit 4e76272

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/fastapi_app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dotenv import load_dotenv
77
from environs import Env
88
from fastapi import FastAPI
9+
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
910

1011
from .globals import global_storage
1112
from .openai_clients import create_openai_chat_client, create_openai_embed_client
@@ -63,6 +64,9 @@ def create_app():
6364

6465
app = FastAPI(docs_url="/docs", lifespan=lifespan)
6566

67+
if os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"):
68+
FastAPIInstrumentor.instrument_app(app)
69+
6670
from . import api_routes # noqa
6771
from . import frontend_routes # noqa
6872

src/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"openai>=1.34.0,<2.0.0",
1515
"tiktoken>=0.7.0,<0.8.0",
1616
"openai-messages-token-helper>=0.1.5,<0.2.0",
17+
"opentelemetry-instrumentation-fastapi>=0.46b0,<1.0.0",
1718
]
1819

1920
[build-system]

0 commit comments

Comments
 (0)