Skip to content

Commit 042cc3d

Browse files
committed
add environment variables for Otel
1 parent 70f06f2 commit 042cc3d

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Azure Application Insights
2+
APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/;LiveEndpoint=https://xxx.livediagnostics.monitor.azure.com/;ApplicationId=xxx"
3+
OTEL_RESOURCE_ATTRIBUTES="service.namespace=local-template-fastapi-namespace,service.instance.id=local-template-fastapi-instance"
4+
OTEL_SERVICE_NAME="local-template-fastapi-service"
5+
OTEL_TRACES_SAMPLER_ARG="1"
6+
17
# Azure OpenAI Service
28
AZURE_OPENAI_ENDPOINT="https://<YOUR_AOAI_NAME>.openai.azure.com/"
39
AZURE_OPENAI_API_KEY="<YOUR_API_KEY>"

docs/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ make dev
3131

3232
The application will be available at http://localhost:8000 with interactive API documentation at http://localhost:8000/docs.
3333

34+
### Docker Setup
35+
36+
See [ks6088ts/template-fastapi](https://hub.docker.com/r/ks6088ts/template-fastapi) for Docker images.
37+
38+
```shell
39+
# Configure environment
40+
cp .env.template .env
41+
# Edit .env with your Azure service credentials
42+
43+
# Run Docker container
44+
docker run --rm -p 8000:8000 \
45+
--volume "$PWD/.env:/app/.env" \
46+
ks6088ts/template-fastapi:latest
47+
```
48+
3449
## Architecture Overview
3550

3651
For detailed architecture information, see:

template_fastapi/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def server_request_hook(span: Span, scope: dict):
3838

3939
configure_azure_monitor(
4040
connection_string=AZURE_CONNECTION_STRING,
41-
# enable_live_metrics=True,
41+
enable_live_metrics=True,
4242
server_request_hook=server_request_hook,
4343
)
4444
FastAPIInstrumentor.instrument_app(app)

template_fastapi/routers/demos.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import asyncio
12
import random
2-
import time
33

44
from fastapi import APIRouter, HTTPException
55

@@ -73,10 +73,9 @@ async def heavy_sync_with_sleep(sleep_ms: int):
7373

7474
with tracer.start_as_current_span("parent"):
7575
logger.debug(f"Starting sleep for {sleep_ms} milliseconds")
76-
time.sleep(sleep_ms / 1000.0)
76+
await asyncio.sleep(sleep_ms / 1000.0) # Convert milliseconds to seconds
7777
with tracer.start_as_current_span("child"):
7878
logger.debug("Child span execution")
79-
8079
logger.info(f"Completed sleep operation for {sleep_ms}ms")
8180
return {
8281
"message": f"Slept for {sleep_ms} milliseconds",

0 commit comments

Comments
 (0)