Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Azure Application Insights
APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/;LiveEndpoint=https://xxx.livediagnostics.monitor.azure.com/;ApplicationId=xxx"
OTEL_RESOURCE_ATTRIBUTES="service.namespace=local-template-fastapi-namespace,service.instance.id=local-template-fastapi-instance"
OTEL_SERVICE_NAME="local-template-fastapi-service"
OTEL_TRACES_SAMPLER_ARG="1"

# Azure OpenAI Service
AZURE_OPENAI_ENDPOINT="https://<YOUR_AOAI_NAME>.openai.azure.com/"
AZURE_OPENAI_API_KEY="<YOUR_API_KEY>"
Expand Down
15 changes: 15 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ make dev

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

### Docker Setup

See [ks6088ts/template-fastapi](https://hub.docker.com/r/ks6088ts/template-fastapi) for Docker images.

```shell
# Configure environment
cp .env.template .env
# Edit .env with your Azure service credentials

# Run Docker container
docker run --rm -p 8000:8000 \
--volume "$PWD/.env:/app/.env" \
ks6088ts/template-fastapi:latest
```

## Architecture Overview

For detailed architecture information, see:
Expand Down
2 changes: 1 addition & 1 deletion template_fastapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def server_request_hook(span: Span, scope: dict):

configure_azure_monitor(
connection_string=AZURE_CONNECTION_STRING,
# enable_live_metrics=True,
enable_live_metrics=True,
server_request_hook=server_request_hook,
)
FastAPIInstrumentor.instrument_app(app)
Expand Down
5 changes: 2 additions & 3 deletions template_fastapi/routers/demos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
import random
import time

from fastapi import APIRouter, HTTPException

Expand Down Expand Up @@ -73,10 +73,9 @@ async def heavy_sync_with_sleep(sleep_ms: int):

with tracer.start_as_current_span("parent"):
logger.debug(f"Starting sleep for {sleep_ms} milliseconds")
time.sleep(sleep_ms / 1000.0)
await asyncio.sleep(sleep_ms / 1000.0) # Convert milliseconds to seconds
with tracer.start_as_current_span("child"):
logger.debug("Child span execution")

logger.info(f"Completed sleep operation for {sleep_ms}ms")
return {
"message": f"Slept for {sleep_ms} milliseconds",
Expand Down
Loading